// pointExchange/pages/my/my.js const app = getApp(); import util from '../../../utils/util.js' Page({ /** * 页面的初始数据 */ data: { appAssetsUrl:app.appAssetsUrl, typeList:[{ name:'全部', value:'' },{ name:'未使用', value:1 },{ name:'已使用', value:2 },{ name:'已过期', value:3 }], typeListIndex:0, nodata: util.nodata(), params: { sutId: util.getUserId(), pageNum: 1, pageSize: 10, status: '' }, total:{ currPage: 0, totalPage: 0 }, noMore:false, listData:[], itemData:{ cdkey:'', needScore: '--' } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if(options.index){ this.setData({ typeListIndex:options.index }) } this.loadList(true); }, switchType(e) { let index = e.currentTarget.dataset.index; this.setData({ typeListIndex: index }) this.loadList(true); }, loadList(isRefresh) { let that = this; if (!isRefresh && this.data.noMore) { wx.showToast({ title: '没有更多了~', icon: 'none' }) return false; } this.setData({ listData: isRefresh ? [] : this.data.listData, noMore: isRefresh ? false : this.data.noMore, params: { ...this.data.params, pageNum: isRefresh?1:this.data.params.pageNum+1, status: this.data.typeList[this.data.typeListIndex].value } }) wx.showLoading({ title: '努力加载中...', }) app._post_form('productStu/page', '', this.data.params, function(res) { if (res.code == 0) { if(res.data.list.length>0 && that.data.listData.length>0 && res.data.list[0].id == that.data.listData[0].id){ return ; } let listData = that.data.listData; listData.push(...res.data.list); that.setData({ listData, currPage: res.data.currPage, totalPage: res.data.totalPage, noMore: res.data.totalPage == res.data.currPage }) } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { this.popup3 = this.selectComponent("#popup3"); }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { this.loadList(); }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, toDatail(e){ wx.navigateTo({ url: `/pointExchange/pages/detail/detail?id=${e.currentTarget.dataset.id}&isApply=true` }) }, //弹窗 showPopup(e) { this[e.currentTarget.dataset.name].showPopup(); this.setData({ itemData:{ ...this.data.itemData, needScore: e.currentTarget.dataset.needscore, cdkey: e.currentTarget.dataset.cdkey, } }) }, //取消事件 _error(e) { this[e.currentTarget.dataset.name].hidePopup(); }, //使用卡券 applyCoupon(e){ this.popup3.hidePopup(); let that = this; wx.showLoading({ title: '提交中...', }) app._post_form('productStu/use', "", { cdkey: this.data.itemData.cdkey, stuId: util.getUserId() }, function(res) { if (res.code === 0) { wx.showToast({ title:'使用成功', icon:'none' }) that.loadList(true); } }) } })