Browse Source

Merge branch 'dev' of http://git.ycjcjy.com/zhiyuxing/miniapp-v3 into dev

张延森 5 years ago
parent
commit
10487977b7
4 changed files with 94 additions and 73 deletions
  1. 70
    57
      src/pages/news/index.js
  2. 5
    6
      src/pages/news/index.scss
  3. 16
    10
      src/pages/project/h5Page.js
  4. 3
    0
      src/pages/project/index.js

+ 70
- 57
src/pages/news/index.js View File

1
 import Taro, { Component } from '@tarojs/taro';
1
 import Taro, { Component } from '@tarojs/taro';
2
 import ListView from '@components/ListView'
2
 import ListView from '@components/ListView'
3
-import NewsItem from './item'
4
 import './index.scss'
3
 import './index.scss'
5
-import { savePoint, updatePoint } from '@services/common'
6
 import { queryNewsList } from '@services/news'
4
 import { queryNewsList } from '@services/news'
5
+import NewsItem from './item'
6
+import { savePoint, updatePoint } from '@services/common'
7
 import { connect } from '@tarojs/redux'
7
 import { connect } from '@tarojs/redux'
8
 
8
 
9
-let pageIndex = 1
10
-
11
 @connect(state => state.city)
9
 @connect(state => state.city)
12
 export default class Index extends Component {
10
 export default class Index extends Component {
13
 
11
 
14
   config = {
12
   config = {
15
-    navigationBarTitleText: '资讯列表'
13
+    navigationBarTitleText: '热门活动'
16
   }
14
   }
17
 
15
 
18
   state = {
16
   state = {
20
     hasMore: true,
18
     hasMore: true,
21
     isEmpty: false,
19
     isEmpty: false,
22
     recordId: null,
20
     recordId: null,
23
-    pageIndex:1
21
+    pageIndex: 1
24
   }
22
   }
25
 
23
 
24
+  refreshing = false
25
+
26
   componentWillMount() {
26
   componentWillMount() {
27
     // App.zhuge.track('查看资讯列表页面')
27
     // App.zhuge.track('查看资讯列表页面')
28
     savePoint({
28
     savePoint({
36
       })
36
       })
37
       console.log('资讯列表')
37
       console.log('资讯列表')
38
     })
38
     })
39
-    Taro.showLoading()
40
-  } 
39
+  }
40
+
41
+  componentDidShow() {
42
+    // // this.onPullDownRefresh()
43
+    // console.log('----', this)
44
+    this.loadData(1)
45
+  }
41
 
46
 
42
   componentWillUnmount() {
47
   componentWillUnmount() {
43
     const { recordId } = this.state
48
     const { recordId } = this.state
44
     recordId && updatePoint(recordId)
49
     recordId && updatePoint(recordId)
45
   }
50
   }
46
-  componentDidShow(){
47
-    this.onPullDownRefresh()
48
-  }
49
 
51
 
50
   loadList(pageNumber) {
52
   loadList(pageNumber) {
51
     const { curCity: { id: cityId } } = this.props
53
     const { curCity: { id: cityId } } = this.props
52
     const payload = { pageSize: 10, pageNumber }
54
     const payload = { pageSize: 10, pageNumber }
53
 
55
 
54
-    const { params: { buildingId } } = this.$router
55
-
56
-    console.log(payload)
57
-
56
+    const { params: { buildingId, from } } = this.$router
58
     if (cityId) {
57
     if (cityId) {
59
       payload.cityId = cityId
58
       payload.cityId = cityId
60
     }
59
     }
61
-
62
-    // 从项目详情过来
60
+    // 从个人中心过来
61
+    console.log(this.router, "from")
62
+    if (from === 'mine') {
63
+      payload.mine = true
64
+    }
65
+    // // 从项目详情过来
63
     if (buildingId) {
66
     if (buildingId) {
64
       payload.buildingId = buildingId
67
       payload.buildingId = buildingId
65
     }
68
     }
66
-
69
+    // return queryActivityList(payload)
67
     return queryNewsList(payload)
70
     return queryNewsList(payload)
68
   }
71
   }
69
 
72
 
70
   handleItemClick = (item) => {
73
   handleItemClick = (item) => {
71
-    Taro.navigateTo({ 
74
+    Taro.navigateTo({
72
       url: '/pages/news/detail/index?id=' + item.newsId
75
       url: '/pages/news/detail/index?id=' + item.newsId
73
     })
76
     })
74
   }
77
   }
75
 
78
 
76
-  onPullDownRefresh = async (rest) => {
77
-    const { records: list, total } = await this.loadList(1);
78
-    this.setState({
79
-      list,
80
-      isEmpty: total == 0,
81
-      hasMore: list.length >= total ? false : true,
82
-      pageIndex:1
83
-    })
79
+  onPullDownRefresh = (rest) => {
80
+    // debugger
81
+    if (this.refreshing) return
82
+    this.refreshing = true
83
+
84
+    this.loadData(1)
85
+
86
+    // debugger
84
     rest && rest()
87
     rest && rest()
85
-    Taro.hideLoading()
88
+
89
+    this.refreshing = false
86
   }
90
   }
87
 
91
 
88
   onScrollToLower = async (fn) => {
92
   onScrollToLower = async (fn) => {
89
-    const { list } = this.state;
90
-    pageIndex++
91
-    const { records, total } = await this.loadList(this.state.pageIndex+1);
92
-    const newList = list.concat(records)
93
-    this.setState({
94
-      list: newList,
95
-      hasMore: newList.length >= total ? false : true,
96
-      pageIndex:this.state.pageIndex+1
97
-    });
93
+    const { pageIndex } = this.state;
94
+    this.loadData(pageIndex + 1)
98
     fn && fn();
95
     fn && fn();
99
   }
96
   }
100
 
97
 
98
+  loadData = (page) => {
99
+    this.loadList(page).then(res => {
100
+      const { records, list, total, current, pages } = res || {}
101
+      const _list = records || list || []
102
+      const newList = current <= 1 ? _list : this.state.list.concat(_list)
103
+      console.log(res, '---res-------')
104
+      this.setState({
105
+        list: newList,
106
+        isEmpty: total == 0,
107
+        hasMore: current < pages,
108
+        pageIndex: current >= pages ? pages : current
109
+      })
110
+    })
111
+  }
112
+
101
   render() {
113
   render() {
102
     const { isEmpty, hasMore, list } = this.state
114
     const { isEmpty, hasMore, list } = this.state
103
-
104
     return (
115
     return (
105
-      <View className="page">
106
-        <ListView
107
-          needInit
108
-          isEmpty={isEmpty}
109
-          emptyText="暂无资讯~"
110
-          hasMore={hasMore}
111
-          className="list"
112
-          onPullDownRefresh={fn => this.onPullDownRefresh(fn)}
113
-          onScrollToLower={fn => this.onScrollToLower(fn)}
114
-        >
115
-          {list.map(item => (
116
-            <NewsItem
117
-              key={item.newsId}
118
-              data={item}
119
-              onClick={this.handleItemClick}
120
-            ></NewsItem>
121
-          ))}
122
-        </ListView>
123
-      </View>
116
+      <ListView
117
+        className="wrap"
118
+        needInit
119
+        isEmpty={isEmpty}
120
+        emptyText="暂无资讯~"
121
+        hasMore={hasMore}
122
+        onPullDownRefresh={fn => this.onPullDownRefresh(fn)}
123
+        onScrollToLower={fn => this.onScrollToLower(fn)}
124
+      >
125
+        <View className="list">
126
+          {
127
+            list.map(item => (
128
+              <NewsItem
129
+                key={item.newsId}
130
+                data={item}
131
+                onClick={this.handleItemClick}
132
+              ></NewsItem>
133
+            ))
134
+          }
135
+        </View>
136
+      </ListView>
124
     );
137
     );
125
   }
138
   }
126
 }
139
 }

+ 5
- 6
src/pages/news/index.scss View File

1
 @import "@styles/theme.scss";
1
 @import "@styles/theme.scss";
2
 
2
 
3
-.page {
4
-  background: #fff;
3
+.wrap {
4
+  background: white;
5
   position: relative;
5
   position: relative;
6
+  height:100vh;
6
 }
7
 }
7
 .list{
8
 .list{
8
-  padding:0 40px;
9
-  height:100vh;
10
-  background:white;
11
-  margin-top:30px;
9
+  padding:30px;
12
 }
10
 }
11
+

+ 16
- 10
src/pages/project/h5Page.js View File

15
 
15
 
16
   state = {
16
   state = {
17
     recordId: undefined, // 埋点ID
17
     recordId: undefined, // 埋点ID
18
-    avatarVisible: true,
18
+    avatarVisible: false,
19
     phoneVisible: false,
19
     phoneVisible: false,
20
     webViewVisible: false,
20
     webViewVisible: false,
21
     pageInfo: {},
21
     pageInfo: {},
98
   }
98
   }
99
   componentWillMount() {
99
   componentWillMount() {
100
     ready.queue(() => {
100
     ready.queue(() => {
101
-
101
+      Taro.showLoading()
102
       if (this.$router.params.scene) {
102
       if (this.$router.params.scene) {
103
 
103
 
104
         getQrCodeParams(this.$router.params.scene).then((_, codeParams) => {
104
         getQrCodeParams(this.$router.params.scene).then((_, codeParams) => {
116
       console.log(hFiveId, "hFiveId")
116
       console.log(hFiveId, "hFiveId")
117
       // h5id 、第一个分享人ID、置业顾问ID、分享人ID 
117
       // h5id 、第一个分享人ID、置业顾问ID、分享人ID 
118
       getHFiveDetail(hFiveId).then(res => {
118
       getHFiveDetail(hFiveId).then(res => {
119
-        if(res.status==1){
119
+        Taro.hideLoading()
120
+        if (res.status == 1) {
120
           this.setState({
121
           this.setState({
121
             pageInfo: res
122
             pageInfo: res
122
           })
123
           })
123
-        }else{
124
+        } else {
124
           Taro.showModal({
125
           Taro.showModal({
125
             title: '提示',
126
             title: '提示',
126
             content: '活动已下架',
127
             content: '活动已下架',
127
-            showCancel:false,
128
-          }).then(()=>{
128
+            showCancel: false,
129
+          }).then(() => {
129
             Taro.switchTab({
130
             Taro.switchTab({
130
               url: '/pages/project/index'
131
               url: '/pages/project/index'
131
             })
132
             })
134
       })
135
       })
135
       const { userInfo: { person: { avatarurl, phone } } } = this.props
136
       const { userInfo: { person: { avatarurl, phone } } } = this.props
136
       console.log(this.props, "this.propsthis.propsthis.props")
137
       console.log(this.props, "this.propsthis.propsthis.props")
138
+
137
       if (avatarurl && avatarurl.indexOf('wx.qlogo.cn') != -1) {
139
       if (avatarurl && avatarurl.indexOf('wx.qlogo.cn') != -1) {
138
         console.log(avatarurl, "有头像哦~")
140
         console.log(avatarurl, "有头像哦~")
139
         this.setState({
141
         this.setState({
140
           avatarVisible: false,
142
           avatarVisible: false,
141
         })
143
         })
144
+        Taro.hideLoading()
142
         console.log(phone, "phone#########")
145
         console.log(phone, "phone#########")
143
         // 头像手机号都有
146
         // 头像手机号都有
144
         if (phone) {
147
         if (phone) {
155
           })
158
           })
156
         }
159
         }
157
       } else {
160
       } else {
161
+        Taro.hideLoading()
158
         if (phone) {
162
         if (phone) {
159
           this.setState({
163
           this.setState({
160
             phoneVisible: false,
164
             phoneVisible: false,
165
+            avatarVisible: true,
161
           })
166
           })
162
         }
167
         }
163
       }
168
       }
193
       lang: 'zh_CN',
198
       lang: 'zh_CN',
194
       success: res => {
199
       success: res => {
195
         const payload = Object.assign(res, { sessionKey })
200
         const payload = Object.assign(res, { sessionKey })
196
-        console.log(res,"获取用户信息返回值")
201
+        console.log(res, "获取用户信息返回值")
197
         // 用户信息保存至服务器
202
         // 用户信息保存至服务器
198
         dispatchUpdateUserInfo(payload).then(res => {
203
         dispatchUpdateUserInfo(payload).then(res => {
199
           this.onAvatarSuccess();
204
           this.onAvatarSuccess();
249
       }
254
       }
250
       reportClient(payload).then(res => {
255
       reportClient(payload).then(res => {
251
         console.log('恭喜您绑定成功')
256
         console.log('恭喜您绑定成功')
252
-      }).catch(err => {
253
-        console.error(err)
254
-        this.setState({ bound: true })
255
       })
257
       })
258
+      // .catch(err => {
259
+      //   console.error(err)
260
+
261
+      // })
256
     }
262
     }
257
   }
263
   }
258
 
264
 

+ 3
- 0
src/pages/project/index.js View File

230
     if (curCity.id) {
230
     if (curCity.id) {
231
       payload.cityId = curCity.id
231
       payload.cityId = curCity.id
232
     }
232
     }
233
+    this.setState({
234
+      newsList: []
235
+    })
233
     queryNewsList(payload).then(res => {
236
     queryNewsList(payload).then(res => {
234
       this.setState({
237
       this.setState({
235
         newsList: res.records || []
238
         newsList: res.records || []