张延森 5 年前
父节点
当前提交
84c9addd00
共有 1 个文件被更改,包括 24 次插入21 次删除
  1. 24
    21
      src/pages/activity/index.js

+ 24
- 21
src/pages/activity/index.js 查看文件

39
   }
39
   }
40
  
40
  
41
   componentDidShow () {
41
   componentDidShow () {
42
-    this.onPullDownRefresh()
42
+    // // this.onPullDownRefresh()
43
+    // console.log('----', this)
44
+    this.loadData(1)
43
   }
45
   }
44
   
46
   
45
   componentWillUnmount() {
47
   componentWillUnmount() {
88
     }
90
     }
89
   }
91
   }
90
 
92
 
91
-  onListPullDownRefresh = async (rest) => {
93
+  onPullDownRefresh = (rest) => {
92
     // debugger
94
     // debugger
93
     if (this.refreshing) return
95
     if (this.refreshing) return
94
     this.refreshing = true
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
     // debugger
100
     // debugger
105
     rest && rest()
101
     rest && rest()
106
     
102
     
108
   }
104
   }
109
 
105
 
110
   onScrollToLower = async (fn) => {
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
     fn && fn();
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
   render() {
127
   render() {
125
     const { isEmpty, hasMore, list } = this.state
128
     const { isEmpty, hasMore, list } = this.state
126
     return (
129
     return (
130
         isEmpty={isEmpty}
133
         isEmpty={isEmpty}
131
         emptyText="暂无活动~"
134
         emptyText="暂无活动~"
132
         hasMore={hasMore}
135
         hasMore={hasMore}
133
-        onPullDownRefresh={fn => this.onListPullDownRefresh(fn)}
136
+        onPullDownRefresh={fn => this.onPullDownRefresh(fn)}
134
         onScrollToLower={fn => this.onScrollToLower(fn)}
137
         onScrollToLower={fn => this.onScrollToLower(fn)}
135
       >
138
       >
136
         <View className="list">
139
         <View className="list">