// subpages/integralCentre/pages/index/index.js import { pointsRecordlist } from '../../../../utils/api' import { getTimestamp } from '../../../../utils/common' Page({ /** * 页面的初始数据 */ data: { pageIndex: 1, pageSize: 10, pointsRecordlist:[],//积分记录列表 selectTab: 'tab1', typeList: [{ //排名方式:0-周,1-月 type: '0', name: '本周排名', select: true }, { type: '1', name: '本月排名', select: false } ], timestamp: getTimestamp(), loadMoreType: 'none', loadMoreVisible: false, }, // tab 切换 onTabChange(e) { this.setData({ loadMoreType: 'none', loadMoreVisible: false, pointsRecordlist:[], selectTab: e.currentTarget.dataset.tab, }) if (this.data.selectTab == 'tab1'){ this.pointsRecordlist();//初始化加载积分记录列表 }else{ console.log('积分排行') } }, onButtonChange: function (e) { const list = this.data.typeList let that = this; list.forEach(item => { if (item.type === e.currentTarget.dataset.type) { item.select = true } else { item.select = false } }) that.setData({ typeList: list, }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { this.pointsRecordlist();//初始化加载积分记录列表 }, // 获取事件详情 pointsRecordlist() { let that = this const para = { pageIndex: this.data.pageIndex, pageSize: this.data.pageSize, timestamp: this.data.timestamp } pointsRecordlist(para).then(res => { console.log('积分记录列表', res) that.setData({ pointsRecordlist: that.data.pointsRecordlist.concat(res.data), loadMoreType: res.data.length === that.data.pageSize ? 'loading' : 'none', }) }).catch(err => { that.setData({ loadMoreType: 'none', pointsRecordlist: [] }) console.log(err) }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function() { }, /** * 生命周期函数--监听页面显示 */ onShow: function() { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function() { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function() { this.setData({ loadMoreVisible: true }) if (this.data.loadMoreType === 'loading') { console.log('加载翻页') this.setData({ pageNo: this.data.pageNo + 1, pageSize: this.data.pageSize, pageIndex: getTimestamp() }) this.pointsRecordlist() } }, /** * 用户点击右上角分享 */ onShareAppMessage: function() { } })