const { apiRequest } = require('../../../utils/API.js') let end_currentPage = 1 let not_currentPage = 1 Page({ data: { current: 1, isShowLoadTip: false, pageLength: 15, end_data: [], not_end_data: [], dataList: {} }, changeTab: function ({ detail }) { let that = this this.setData({ current: detail.key, isShowLoadTip: false, end_data: [], not_end_data: [] }) end_currentPage = 1 not_currentPage = 1 wx.showLoading({ title: '加载中', mask: true }) setTimeout(function () { let pageLen = that.data.pageLength let dataAll = that.data.dataList let endData = dataAll.end.length > pageLen ? dataAll.end.slice(0, pageLen) : dataAll.end let notEndData = dataAll.not_end.length > pageLen ? dataAll.not_end.slice(0, pageLen) : dataAll.not_end that.setData({ end_data: endData, not_end_data: notEndData }) wx.hideLoading() }, 500) }, onLoad: function (options) { this.getList() }, getList: function (callback) { let that = this wx.showLoading({ title: '加载中', mask: true }) apiRequest('/user/lotteries').then(data => { let endData = data.data.end.length > that.data.pageLength ? data.data.end.slice(0, that.data.pageLength) : data.data.end let notEndData = data.data.not_end.length > that.data.pageLength ? data.data.not_end.slice(0, that.data.pageLength) : data.data.not_end that.setData({ dataList: data.data, end_data: endData, not_end_data: notEndData }) wx.hideLoading() callback && callback() }) }, toDetail: function (e) { wx.navigateTo({ url: '/pages/award-detail/award-detail?id=' + e.currentTarget.id }) }, onPullDownRefresh: function () { let that = this wx.showNavigationBarLoading() this.getList(function() { wx.hideNavigationBarLoading() wx.stopPullDownRefresh() wx.showToast({ title: '刷新成功', icon: 'none' }) that.setData({ isShowLoadTip: false }) end_currentPage = 1 not_currentPage = 1 }) }, onReachBottom: function() { let that = this let pageSize = this.data.pageLength wx.showLoading({ title: '加载中', mask: true }) setTimeout(function () { wx.hideLoading() if (that.data.current == 1) { let not_end = that.data.dataList.not_end if (that.data.not_end_data.length != not_end.length) { not_currentPage++ } let data = not_end.length > not_currentPage * pageSize ? not_end.slice(0, not_currentPage * pageSize) : not_end that.setData({ not_end_data: data }) if (that.data.not_end_data.length == not_end.length) { that.setData({ isShowLoadTip: true }) } } else if (that.data.current == 2) { let end = that.data.dataList.end if (that.data.end_data.length != end.length) { end_currentPage++ } let data = end.length > end_currentPage * pageSize ? end.slice(0, end_currentPage * pageSize) : end that.setData({ end_data: data }) if (that.data.end_data.length == end.length) { that.setData({ isShowLoadTip: true }) } } }, 500) } })