const app = getApp(); Page({ cashdialog: null, isOpenView: false, pid: '', pg: 1, data: { isShowNull: false }, onReady: function(){ }, onLoad: function (options) { //产品详情路径附带参数,用于来源分享的参数scene=encodeURIComponent(uid, product_id) if (options != null && typeof options.scene != 'undefined') { let str = decodeURIComponent(options.scene); let arr = str.split(','); let uid = arr[0]; this.pid = arr[1]; app.saveInviteUid(uid); //跳转详情页 this.isOpenView = true; }else{ this.isOpenView = false; } 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); if (that.isOpenView){ app.location('view/index?id=' + that.pid); } } }) } } }) }, /** * 获取首页数据 */ 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(); }, complete: function(res){ app.hideLoading(); } }); }, /** * 查看商品详情 */ view: function (event) { let id = app.getData(event).id; app.location('view/index?id=' + id); }, /** * 礼品卡兑换 */ cash: function(){ var that = this; app.isAuth('scope.userInfo', function(res){ if(res){ that.cashdialog.setErrMsg(''); that.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); }, /** * 用户点击右上角分享 */ onShareAppMessage: function (options) { //打开好友列表 wx.showShareMenu({ withShareTicket: true, success: function (res) { console.log('wx.showShareMenu success', res.data); }, fail: function (res) { console.log('wx.showShareMenu fail', res.data); } }) return { title: '', desc: '', path: '/template/home/index' } } })