// pages/member/member.js const util = require('../../utils/util.js') const api = require('../../utils/api.js') const app = getApp() Page({ /** * 页面的初始数据 */ data: { tabIndex: 0, IncomeList: [], IncomeCount: 99, IncomeListParams: { page: 1, offset: 10 }, IncomeRank: [], IncomeRankCount: 99, IncomeRankParams: { page: 1, offset: 10 }, mpType: app.globalData.mpType }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.getIncomeList() this.getIncomeRank() }, getIncomeList: function () { api.getIncomeList(this.data.IncomeListParams).then(res => { // res.data.list.forEach((item, ids) => { if (this.data.mpType === 'rp') { item.amount = (item.amount).toFixed(2) } item.create_time = util.formatTime(item.create_time, 'yyyy/MM/dd') }) this.setData({ IncomeList: this.data.IncomeList.concat(res.data.list), IncomeCount: res.data.count, IncomeListParams: { page: ++this.data.IncomeListParams.page, offset: 10 } }) }) }, getIncomeRank: function () { api.memIncomeRank(this.data.IncomeRankParams).then(res => { if (this.data.mpType === 'rp') { res.data.list.forEach((item, ids) => { item.amount = (item.amount || 0).toFixed(2) }) } this.setData({ IncomeRank: this.data.IncomeRank.concat(res.data.list), IncomeRankCount: res.data.count, IncomeRankParams: { page: ++this.data.IncomeRankParams.page, offset: 10 } }) console.log(this.data.IncomeRank) }) }, tabChange: function (e) { this.setData({ tabIndex: e.target.dataset.index }) }, routeIncome: function (e) { util.routeTo(`/pages/Incomelog/Incomelog?memid=${e.currentTarget.dataset.memid}`) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { let { tabIndex, IncomeCount, IncomeListParams, IncomeRankCount, IncomeRankParams } = this.data if (tabIndex) { if (IncomeRankParams.page * IncomeRankParams.offset < IncomeRankCount + 10) { this.getIncomeRank() } } else { if (IncomeListParams.page * IncomeListParams.offset < IncomeCount + 10) { this.getIncomeList() } } } })