// user/parIncome/parIncome.js const app = getApp(); const regeneratorRuntime = app.loadAsync() const model = app.loadModel("index") const http = app.loadHttp() Page({ /** * 页面的初始数据 */ data: { system: app.globalData.system, //设备相关信息 pageTitle: "我的返利", //头部标题 isBack: true,//显示返回 isLoading: true,//加载显示关闭 current: '0',//当前所在的标签的 key 值 tabs: ["我推荐的人", "积分记录", "佣金记录"], page: 1,//当前页码 isPage: true,//当前接口无数据, recommendList: [],//推荐人列表 score: [],//积分记录 commission: [],//佣金记录 userInfo: {},//用户信息 }, // 获取用户个人信息 userInfo() { this.setData({ userInfo: app.globalData.userInfo }) }, // tab选中事件 // 切换tab时把该清空的清空 handleChange(e) { let index = e.currentTarget.dataset.index this.setData({ current: index, page: 1, isPage: true, recommendList: [], score: [], commission: [] }); this.isSwitch(index) }, isSwitch(index) { switch (index) { case 0: this.allRecord(http.api.recommend, 0) break; case 1: this.allRecord(http.api.score, 1) break; case 2: this.allRecord(http.api.withDrawRecord, 2) break; default: break; } }, //回到顶部 goTop: function (e) { // 一键回到顶部 if (wx.pageScrollTo) { wx.pageScrollTo({ scrollTop: 0 }) } else { wx.showModal({ title: '提示', content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。' }) } }, // 所有记录 0 推荐人列表 1 积分记录 2 佣金记录 async allRecord(url, index) { if (!this.data.isPage) { return } let data = { page: this.data.page, limit: 10 } let res = await http.http.request2({ url: url, method: "POST", data: data }) if (res.data.data.list.length < 10) { this.setData({ isPage: false }) } let rel = res.data.data.list switch (index) { case 0: let recommendList = this.data.recommendList this.setData({ recommendList: [...recommendList, ...rel], isLoading: false }) break; case 1: let score = this.data.score this.setData({ score: [...score, ...rel], isLoading: false }) break; case 2: let commission = this.data.commission this.setData({ commission: [...commission, ...rel], isLoading: false }) break; default: this.setData({ isLoading: false }) break; } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ current: options.index || 0 }) if (options['index']) { this.isSwitch(parseInt(options['index'])) } else { this.isSwitch(0) } this.userInfo() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.userInfo() }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { if (this.data.isPage) { this.setData({ page: ++this.data.page }) this.isSwitch(this.data.current) } }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })