// pointExchange/index.js const app = getApp(); import util from '../utils/util.js' Page({ /** * 页面的初始数据 */ data: { appAssetsUrl:app.appAssetsUrl, tools:[{ text:'积分任务' },{ text:'积分中心' },{ text:'我的兑换' }], typeList: [], typeListIndex: 0, nameListEle: [], totalScore: '--',//总积分 itemData:{ id:'', needScore: '--' }, nodata: util.nodata(), params: { pageNum: 1, pageSize: 10, type: '' }, total:{ currPage: 0, totalPage: 0 }, noMore:false, listData:[], navScrollWidth: 0, statusBarHeight: 0, statusBarMH: 0 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.height(); this.loadData(); this.getTypeList(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function() { //获得popup组件 this.popup = this.selectComponent("#popup"); this.popup2 = this.selectComponent("#popup2"); this.popup3 = this.selectComponent("#popup3"); }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.loadData(); }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, // 自定义高度处理 height() { const { platform, statusBarHeight } = wx.getSystemInfoSync() let height = statusBarHeight + 4 //ios 24px let mH = statusBarHeight + 4 if (platform.toLowerCase() == "android") { height += 4 //android 28px mH += 4 } height = height + 38 // 胶囊高度 32px 下边框6px height 状态栏高度 this.setData({ statusBarHeight: height + 'px', statusBarMH: mH + 'px' }) }, switchType(e) { let index = e.currentTarget.dataset.index; this.setData({ typeListIndex: index }) this.scroll(index); this.loadList(true); }, back(){ wx.navigateBack(); }, toDatail(e){ wx.navigateTo({ url: `/pointExchange/pages/detail/detail?id=${e.currentTarget.dataset.id}&totalScore=${this.data.totalScore}` }) }, goTool(e){ let index = e.currentTarget.dataset.index; if(index == 0){ wx.navigateTo({ url:'/pointExchange/pages/task/task' }) }else if(index == 1){ wx.navigateTo({ url:`/pointExchange/pages/center/center?totalScore=${this.data.totalScore}` }) }else if(index == 2){ wx.navigateTo({ url:'/pointExchange/pages/my/my' }) } }, getTypeList(){ let that = this; app._post_form('productType/list', '', null, function(res) { if (res.code == 0) { that.setData({ typeList: res.data }) wx.nextTick(() => { let query = wx.createSelectorQuery(); query.selectAll('.nameitem').boundingClientRect().exec(function (res) { let nameListEle = []; for(let i in res[0]){ nameListEle.push(res[0][i].width*1); } that.setData({ nameListEle }) }) }) that.loadList(true); } }) }, scroll(index){ let that = this; let leftNum = 0; if(index>0){ for(let i in that.data.nameListEle){ if(i0 && that.data.listData.length>0 && res.page.list[0].id == that.data.listData[0].id){ return ; } let listData = that.data.listData; listData.push(...res.page.list); that.setData({ listData, currPage: res.page.currPage, totalPage: res.page.totalPage, noMore: res.page.totalPage == res.page.currPage }) } }) }, //弹窗 showPopup(e) { this[e.currentTarget.dataset.name].showPopup(); this.setData({ itemData:{ ...this.data.itemData, id: e.currentTarget.dataset.id, needScore: e.currentTarget.dataset.needscore } }) }, //取消事件 _error(e) { this[e.currentTarget.dataset.name].hidePopup(); }, useCoupon(e) { this.popup.hidePopup(); let that = this; wx.showLoading({ title: '提交中...', }) app._post_form('product/exchange', "", { pId: this.data.itemData.id, stuId: util.getUserId() }, function(res) { if (res.code === 0) { that.loadData(); that.popup2.showPopup(); } }) }, toPointExchangeByMe(){ this.popup2.hidePopup(); wx.navigateTo({ url:'/pointExchange/pages/my/my' }) } })