|
@@ -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
|
}
|