|
@@ -39,7 +39,9 @@ export default class Index extends Component {
|
39
|
39
|
}
|
40
|
40
|
|
41
|
41
|
componentDidShow () {
|
42
|
|
- this.onPullDownRefresh()
|
|
42
|
+ // // this.onPullDownRefresh()
|
|
43
|
+ // console.log('----', this)
|
|
44
|
+ this.loadData(1)
|
43
|
45
|
}
|
44
|
46
|
|
45
|
47
|
componentWillUnmount() {
|
|
@@ -88,19 +90,13 @@ export default class Index extends Component {
|
88
|
90
|
}
|
89
|
91
|
}
|
90
|
92
|
|
91
|
|
- onListPullDownRefresh = async (rest) => {
|
|
93
|
+ onPullDownRefresh = (rest) => {
|
92
|
94
|
// debugger
|
93
|
95
|
if (this.refreshing) return
|
94
|
96
|
this.refreshing = true
|
95
|
97
|
|
96
|
|
- const { records, list, total } = await this.loadList(1);
|
97
|
|
- const _list = records || list || []
|
98
|
|
- this.setState({
|
99
|
|
- list: _list,
|
100
|
|
- isEmpty: total == 0,
|
101
|
|
- hasMore: _list.length >= total ? false : true,
|
102
|
|
- pageIndex: 1
|
103
|
|
- })
|
|
98
|
+ this.loadData(1)
|
|
99
|
+
|
104
|
100
|
// debugger
|
105
|
101
|
rest && rest()
|
106
|
102
|
|
|
@@ -108,19 +104,26 @@ export default class Index extends Component {
|
108
|
104
|
}
|
109
|
105
|
|
110
|
106
|
onScrollToLower = async (fn) => {
|
111
|
|
- const { list } = this.state;
|
112
|
|
-
|
113
|
|
- const { records, list: list1, total, current } = await this.loadList(this.state.pageIndex + 1);
|
114
|
|
- const _list = records || list1 || []
|
115
|
|
- const newList = list.concat(_list)
|
116
|
|
- this.setState({
|
117
|
|
- list: newList,
|
118
|
|
- hasMore: newList.length >= total ? false : true,
|
119
|
|
- pageIndex: current,
|
120
|
|
- });
|
|
107
|
+ const { pageIndex } = this.state;
|
|
108
|
+ this.loadData(pageIndex + 1)
|
121
|
109
|
fn && fn();
|
122
|
110
|
}
|
123
|
111
|
|
|
112
|
+ loadData = (page) => {
|
|
113
|
+ this.loadList(page).then(res => {
|
|
114
|
+ const {records, list, total, current, pages} = res || {}
|
|
115
|
+ const _list = records || list || []
|
|
116
|
+ const newList = current <= 1 ? _list: this.state.list.concat(_list)
|
|
117
|
+
|
|
118
|
+ this.setState({
|
|
119
|
+ list: newList,
|
|
120
|
+ isEmpty: total == 0,
|
|
121
|
+ hasMore: current < pages,
|
|
122
|
+ pageIndex: current >= pages ? pages : current
|
|
123
|
+ })
|
|
124
|
+ })
|
|
125
|
+ }
|
|
126
|
+
|
124
|
127
|
render() {
|
125
|
128
|
const { isEmpty, hasMore, list } = this.state
|
126
|
129
|
return (
|
|
@@ -130,7 +133,7 @@ export default class Index extends Component {
|
130
|
133
|
isEmpty={isEmpty}
|
131
|
134
|
emptyText="暂无活动~"
|
132
|
135
|
hasMore={hasMore}
|
133
|
|
- onPullDownRefresh={fn => this.onListPullDownRefresh(fn)}
|
|
136
|
+ onPullDownRefresh={fn => this.onPullDownRefresh(fn)}
|
134
|
137
|
onScrollToLower={fn => this.onScrollToLower(fn)}
|
135
|
138
|
>
|
136
|
139
|
<View className="list">
|