Просмотр исходного кода

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

张延森 5 лет назад
Родитель
Сommit
10487977b7
4 измененных файлов: 94 добавлений и 73 удалений
  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 Просмотреть файл

@@ -1,18 +1,16 @@
1 1
 import Taro, { Component } from '@tarojs/taro';
2 2
 import ListView from '@components/ListView'
3
-import NewsItem from './item'
4 3
 import './index.scss'
5
-import { savePoint, updatePoint } from '@services/common'
6 4
 import { queryNewsList } from '@services/news'
5
+import NewsItem from './item'
6
+import { savePoint, updatePoint } from '@services/common'
7 7
 import { connect } from '@tarojs/redux'
8 8
 
9
-let pageIndex = 1
10
-
11 9
 @connect(state => state.city)
12 10
 export default class Index extends Component {
13 11
 
14 12
   config = {
15
-    navigationBarTitleText: '资讯列表'
13
+    navigationBarTitleText: '热门活动'
16 14
   }
17 15
 
18 16
   state = {
@@ -20,9 +18,11 @@ export default class Index extends Component {
20 18
     hasMore: true,
21 19
     isEmpty: false,
22 20
     recordId: null,
23
-    pageIndex:1
21
+    pageIndex: 1
24 22
   }
25 23
 
24
+  refreshing = false
25
+
26 26
   componentWillMount() {
27 27
     // App.zhuge.track('查看资讯列表页面')
28 28
     savePoint({
@@ -36,91 +36,104 @@ export default class Index extends Component {
36 36
       })
37 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 47
   componentWillUnmount() {
43 48
     const { recordId } = this.state
44 49
     recordId && updatePoint(recordId)
45 50
   }
46
-  componentDidShow(){
47
-    this.onPullDownRefresh()
48
-  }
49 51
 
50 52
   loadList(pageNumber) {
51 53
     const { curCity: { id: cityId } } = this.props
52 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 57
     if (cityId) {
59 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 66
     if (buildingId) {
64 67
       payload.buildingId = buildingId
65 68
     }
66
-
69
+    // return queryActivityList(payload)
67 70
     return queryNewsList(payload)
68 71
   }
69 72
 
70 73
   handleItemClick = (item) => {
71
-    Taro.navigateTo({ 
74
+    Taro.navigateTo({
72 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 87
     rest && rest()
85
-    Taro.hideLoading()
88
+
89
+    this.refreshing = false
86 90
   }
87 91
 
88 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 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 113
   render() {
102 114
     const { isEmpty, hasMore, list } = this.state
103
-
104 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 Просмотреть файл

@@ -1,12 +1,11 @@
1 1
 @import "@styles/theme.scss";
2 2
 
3
-.page {
4
-  background: #fff;
3
+.wrap {
4
+  background: white;
5 5
   position: relative;
6
+  height:100vh;
6 7
 }
7 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 Просмотреть файл

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

@@ -230,6 +230,9 @@ export default class Index extends Component {
230 230
     if (curCity.id) {
231 231
       payload.cityId = curCity.id
232 232
     }
233
+    this.setState({
234
+      newsList: []
235
+    })
233 236
     queryNewsList(payload).then(res => {
234 237
       this.setState({
235 238
         newsList: res.records || []