Commit c288988edff277f0f65553b4c22900241f67995f
1 parent
be4dd06f
修改 上拉加载更多
Showing
1 changed file
with
75 additions
and
36 deletions
packageA/pages/liveStream/liveStream.js
| @@ -17,7 +17,7 @@ Page({ | @@ -17,7 +17,7 @@ Page({ | ||
| 17 | */ | 17 | */ |
| 18 | data: { | 18 | data: { |
| 19 | curPage: 1, | 19 | curPage: 1, |
| 20 | - pageNum: 0, | 20 | + pageNum: 1, |
| 21 | liveing: [], | 21 | liveing: [], |
| 22 | livetoBegin: [], | 22 | livetoBegin: [], |
| 23 | liveOver: [] | 23 | liveOver: [] |
| @@ -67,7 +67,7 @@ Page({ | @@ -67,7 +67,7 @@ Page({ | ||
| 67 | }); | 67 | }); |
| 68 | }, | 68 | }, |
| 69 | 69 | ||
| 70 | - loadLiveList: function (curPage) { | 70 | + loadLiveList: function (curPage) { |
| 71 | // console.log('---->curPage', curPage); | 71 | // console.log('---->curPage', curPage); |
| 72 | // var live = {}; | 72 | // var live = {}; |
| 73 | // live.toBegin = []; // 即将开始 | 73 | // live.toBegin = []; // 即将开始 |
| @@ -79,61 +79,76 @@ Page({ | @@ -79,61 +79,76 @@ Page({ | ||
| 79 | // 请求数据 | 79 | // 请求数据 |
| 80 | getApp().request.promiseGet("/api/weshop/wx/livelist/page", { | 80 | getApp().request.promiseGet("/api/weshop/wx/livelist/page", { |
| 81 | data: { | 81 | data: { |
| 82 | - storedId: storeId, | 82 | + storedId: o.stoid, |
| 83 | page: curPage, | 83 | page: curPage, |
| 84 | live_status: 103 | 84 | live_status: 103 |
| 85 | } | 85 | } |
| 86 | }).then(res => { | 86 | }).then(res => { |
| 87 | if (res.data.code == 0) { | 87 | if (res.data.code == 0) { |
| 88 | + console.log('res------------>', res); | ||
| 88 | // 计算总页数 | 89 | // 计算总页数 |
| 89 | - var total = res.data.data.total; | ||
| 90 | - var pageSize = res.data.data.pageSize; | ||
| 91 | - var pageNum = total % pageSize; | ||
| 92 | - | ||
| 93 | - that.setData({ | ||
| 94 | - pageNum: pageNum | ||
| 95 | - }); | 90 | + // var total = res.data.data.total; |
| 91 | + // console.log("total", total); | ||
| 92 | + // var pageSize = res.data.data.pageSize; | ||
| 93 | + // console.log("pageSize", pageSize); | ||
| 94 | + // var pageNum = that.pageTotal(total, pageSize); | ||
| 95 | + // that.setData({ | ||
| 96 | + // pageNum: that.pageTotal(total, pageSize) | ||
| 97 | + // }); | ||
| 96 | 98 | ||
| 97 | // 如果当前请求的是第一页数据,则执行赋值,否则执行合并再赋值 | 99 | // 如果当前请求的是第一页数据,则执行赋值,否则执行合并再赋值 |
| 98 | - if(curPage == 1) { | 100 | + if (curPage == 1) { |
| 99 | that.setData({ | 101 | that.setData({ |
| 100 | - liveOver: res.data.data.pageData | ||
| 101 | - // 测试 | ||
| 102 | - // liveOver: that.data.liveOver.concat(res.data.data.pageData) | ||
| 103 | - }); | 102 | + liveOver: that.data.liveOver.concat(res.data.data.pageData) |
| 103 | + }) | ||
| 104 | } else { | 104 | } else { |
| 105 | that.setData({ | 105 | that.setData({ |
| 106 | liveOver: that.data.liveOver.concat(res.data.data.pageData) | 106 | liveOver: that.data.liveOver.concat(res.data.data.pageData) |
| 107 | - }); | 107 | + }) |
| 108 | }; | 108 | }; |
| 109 | - | 109 | + |
| 110 | // var list = that.data.list; | 110 | // var list = that.data.list; |
| 111 | // for(var i in list) { | 111 | // for(var i in list) { |
| 112 | - // var liveStatus = list[i].live_status; | ||
| 113 | - // if (liveStatus == '101') { | ||
| 114 | - // live.ing.push(list[i]); | ||
| 115 | - // } else if (liveStatus == '102') { | ||
| 116 | - // live.toBegin.push(list[i]); | ||
| 117 | - // } else if (liveStatus == '103') { | ||
| 118 | - // live.over.push(list[i]); | ||
| 119 | - // } | 112 | + // var liveStatus = list[i].live_status; |
| 113 | + // if (liveStatus == '101') { | ||
| 114 | + // live.ing.push(list[i]); | ||
| 115 | + // } else if (liveStatus == '102') { | ||
| 116 | + // live.toBegin.push(list[i]); | ||
| 117 | + // } else if (liveStatus == '103') { | ||
| 118 | + // live.over.push(list[i]); | ||
| 119 | + // } | ||
| 120 | // } | 120 | // } |
| 121 | 121 | ||
| 122 | // that.setData({ | 122 | // that.setData({ |
| 123 | // liveOver: list | 123 | // liveOver: list |
| 124 | // }); | 124 | // }); |
| 125 | 125 | ||
| 126 | - curPage ++; | 126 | + curPage++; |
| 127 | that.setData({ | 127 | that.setData({ |
| 128 | curPage | 128 | curPage |
| 129 | }); | 129 | }); |
| 130 | 130 | ||
| 131 | + console.log('上拉已经触发,当前page------------------------->',that.data.curPage); | ||
| 132 | + | ||
| 131 | } else { | 133 | } else { |
| 132 | console.error('请求失败!!!!!'); | 134 | console.error('请求失败!!!!!'); |
| 133 | } | 135 | } |
| 134 | }) | 136 | }) |
| 135 | }, | 137 | }, |
| 136 | 138 | ||
| 139 | + pageTotal: function (rowCount, pageSize) { | ||
| 140 | + if (rowCount == null || rowCount == "") { | ||
| 141 | + return 0; | ||
| 142 | + } else { | ||
| 143 | + if (pageSize != 0 && rowCount % pageSize == 0) { | ||
| 144 | + return parseInt(rowCount / pageSize) | ||
| 145 | + }; | ||
| 146 | + if (pageSize != 0 && rowCount % pageSize != 0) { | ||
| 147 | + return parseInt(rowCount / pageSize) + 1; | ||
| 148 | + }; | ||
| 149 | + } | ||
| 150 | + }, | ||
| 151 | + | ||
| 137 | getData: function (liveStatus) { | 152 | getData: function (liveStatus) { |
| 138 | var that = this; | 153 | var that = this; |
| 139 | var curPage = this.data.curPage | 154 | var curPage = this.data.curPage |
| @@ -145,21 +160,37 @@ Page({ | @@ -145,21 +160,37 @@ Page({ | ||
| 145 | } | 160 | } |
| 146 | }).then(res => { | 161 | }).then(res => { |
| 147 | if (res.data.code == 0) { | 162 | if (res.data.code == 0) { |
| 148 | - if(liveStatus == 101) { | 163 | + if (liveStatus == 101) { |
| 149 | that.setData({ | 164 | that.setData({ |
| 150 | liveing: res.data.data.pageData | 165 | liveing: res.data.data.pageData |
| 151 | }); | 166 | }); |
| 152 | - } else if(liveStatus == 102) { | 167 | + } else if (liveStatus == 102) { |
| 153 | that.setData({ | 168 | that.setData({ |
| 154 | livetoBegin: res.data.data.pageData | 169 | livetoBegin: res.data.data.pageData |
| 155 | }); | 170 | }); |
| 156 | - } else if(liveStatus == 103) { | 171 | + } else if (liveStatus == 103) { |
| 157 | that.setData({ | 172 | that.setData({ |
| 158 | liveOver: res.data.data.pageData | 173 | liveOver: res.data.data.pageData |
| 159 | }); | 174 | }); |
| 175 | + | ||
| 176 | + var total = res.data.data.total; | ||
| 177 | + console.log("total", total); | ||
| 178 | + var pageSize = res.data.data.pageSize; | ||
| 179 | + console.log("pageSize", pageSize); | ||
| 180 | + var pageNum = that.pageTotal(total, pageSize); | ||
| 181 | + console.log("pageNum", pageNum); | ||
| 182 | + that.setData({ | ||
| 183 | + pageNum | ||
| 184 | + }); | ||
| 185 | + | ||
| 160 | } | 186 | } |
| 161 | - | ||
| 162 | } | 187 | } |
| 188 | + | ||
| 189 | + curPage++; | ||
| 190 | + that.setData({ | ||
| 191 | + curPage | ||
| 192 | + }); | ||
| 193 | + | ||
| 163 | }); | 194 | }); |
| 164 | }, | 195 | }, |
| 165 | 196 | ||
| @@ -167,7 +198,13 @@ Page({ | @@ -167,7 +198,13 @@ Page({ | ||
| 167 | * 生命周期函数--监听页面加载 | 198 | * 生命周期函数--监听页面加载 |
| 168 | */ | 199 | */ |
| 169 | onLoad: function (options) { | 200 | onLoad: function (options) { |
| 170 | - | 201 | + console.log('ppppp',this.pageTotal(4, 10)); |
| 202 | + // var self = this; | ||
| 203 | + // this.updateLiveList().then(() => { | ||
| 204 | + // self.getData(101); | ||
| 205 | + // self.getData(102); | ||
| 206 | + // self.getData(103); | ||
| 207 | + // }); | ||
| 171 | }, | 208 | }, |
| 172 | 209 | ||
| 173 | /** | 210 | /** |
| @@ -178,6 +215,7 @@ Page({ | @@ -178,6 +215,7 @@ Page({ | ||
| 178 | // this.updateLiveList().then(() => { | 215 | // this.updateLiveList().then(() => { |
| 179 | // self.loadLiveList(1); | 216 | // self.loadLiveList(1); |
| 180 | // }); | 217 | // }); |
| 218 | + | ||
| 181 | var self = this; | 219 | var self = this; |
| 182 | this.updateLiveList().then(() => { | 220 | this.updateLiveList().then(() => { |
| 183 | self.getData(101); | 221 | self.getData(101); |
| @@ -219,30 +257,31 @@ Page({ | @@ -219,30 +257,31 @@ Page({ | ||
| 219 | // wx.stopPullDownRefresh(); //停止下拉刷新 | 257 | // wx.stopPullDownRefresh(); //停止下拉刷新 |
| 220 | // }, 500); | 258 | // }, 500); |
| 221 | }, | 259 | }, |
| 260 | + | ||
| 222 | /** | 261 | /** |
| 223 | * 页面上拉触底事件的处理函数 | 262 | * 页面上拉触底事件的处理函数 |
| 224 | */ | 263 | */ |
| 225 | onReachBottom: function () { | 264 | onReachBottom: function () { |
| 226 | var self = this; | 265 | var self = this; |
| 227 | var curPage = this.data.curPage; | 266 | var curPage = this.data.curPage; |
| 267 | + console.log('now curPage',curPage); | ||
| 228 | var pageNum = this.data.pageNum; | 268 | var pageNum = this.data.pageNum; |
| 269 | + console.log('now pageNum',pageNum); | ||
| 229 | 270 | ||
| 230 | - if(curPage <= pageNum) { | 271 | + if (curPage <= pageNum) { |
| 231 | wx.showLoading({ | 272 | wx.showLoading({ |
| 232 | title: '加载中...', | 273 | title: '加载中...', |
| 233 | }) | 274 | }) |
| 234 | - setTimeout(function() { | ||
| 235 | - self.loadLiveList(1); | 275 | + setTimeout(function () { |
| 276 | + self.loadLiveList(curPage); | ||
| 236 | wx.hideLoading(); | 277 | wx.hideLoading(); |
| 237 | }, 500); | 278 | }, 500); |
| 238 | - | ||
| 239 | } else { | 279 | } else { |
| 240 | wx.showToast({ | 280 | wx.showToast({ |
| 241 | title: '已经到底啦~', | 281 | title: '已经到底啦~', |
| 242 | duration: 1000 | 282 | duration: 1000 |
| 243 | }) | 283 | }) |
| 244 | } | 284 | } |
| 245 | - console.log('当前curpage',curPage, pageNum); | ||
| 246 | }, | 285 | }, |
| 247 | 286 | ||
| 248 | /** | 287 | /** |