const app = getApp(); Page({ pid: '', onLoad: function (options) { this.pid = options.id; var that = this; app.showLoading(); app.request('product.api.view', {id: this.pid}, { success: function (data, res) { app.html('content', data.product.content, that); }, complete: function(res){ app.hideLoading(); } }) }, /** * 跳转海报分享页面,分享海报 */ toShare: function(){ if(app.isLogin()){ app.location('poster/index?id=' + this.pid); }else{ app.location('login/index'); } }, /** * 立即购买 */ doBuy: function(e){ var that = this; app.showLoading(); app.isAuth('scope.userInfo', function (res) { if (res) { app.request('product.api.addCarts', { product_id: that.pid, num: 1 }, { success: function (data, res) { app.location('carts/index?id=' + that.pid); }, complete: function (res) { app.hideLoading(); } }) } else { app.location('login/index'); } }); }, /** * 用户点击右上角分享 */ 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); } }); if (app.getUid() != '') {//拼接分享参数 var scene = app.getUid() + ',' + this.pid; return { title: '', desc: '', path: '/template/home/index?scene=' + encodeURIComponent(scene) }; } } })