const app = getApp(); Page({ cashdialog: null, pg: 1, data: { isShowNull: false }, onLoad: function (options) { if (app.isLogin){ this.getHomeData(this); }else{ var that = this; wx.login({ success: function (res) { if (res.code) { app.request("passport.applet.bind", { code: res.code }, { success: function (data, res) { that.getHomeData(that); } }) } } }) } }, /** * 获取首页数据 */ getHomeData: function(that){ if (that.pg == 1) { app.showLoading(); } that.cashdialog = that.selectComponent("#cashdialog"); app.set(that, 'loadMoreText', '正在加载'); app.request('product.api.home', { pg: that.pg }, { success: function (data, res) { if (data.product.length > 0) { if (that.pg > 1) { app.setList(that, data.product, true); } else { app.setList(that, data.product); } that.pg++; app.set(that, 'isShowNull', false); } else { app.set(that, 'isShowNull', true); } app.hideLoading(); } }); }, /** * 查看商品详情 */ view: function (event) { let id = app.getData(event).id; app.location('view/index?id=' + id); }, /** * 礼品卡兑换 */ cash: function(e){ if(app.isLogin()){ this.cashdialog.setErrMsg(''); this.cashdialog.showDialog(); }else{ app.location('login/index'); } }, /** * 跳转兑换页面 */ toCash: function(){ var that = this; var cashCode = this.cashdialog.getCashCode(); if (cashCode.length <= 0) { that.cashdialog.setErrMsg('请输入兑换码!'); return ; } app.request('product.api.checkCode', { code: cashCode }, { success: function (data, res) { that.cashdialog.hideDialog(); app.location('cash/index?code=' + cashCode); }, fail: function (res) { that.cashdialog.setErrMsg(res.data.msg); } }); }, /** * 页面下拉事件的处理函数 */ onPullDownRefresh: function () { this.pg = 1; app.startPullDown(this); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { app.startPullDown(this); }, })