// packageA//pages/myGiftDetails/myGiftDetails.js const app = getApp(); let self = null; var os = app.globalData.setting; Page({ /** * 页面的初始数据 */ data: { qr_code_object: { val: "12121", content: "请将二维码展示给核销员,服务更快捷!" }, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { self = this; this.setData({ id: options.id, index: options.index, }) // console.log('options', options); app.isLogin().then(function(data) {//进入页面前已经授权登录成功 self.setData({ userInfo: data, }); }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { if(app.globalData.userInfo) { if(!this.data.isLogin) { this.setData({ userInfo: app.globalData.userInfo, imghost: app.globalData.setting.imghost, isLogin: true, }); let url = ''; // let data = { // store_id: app.globalData.setting.stoid, // user_id: app.globalData.user_id, // }; if(this.data.index == 0) { // data.lbid = this.data.id; // 请求数据 app.request.promiseGet('/api/weshop/libao/libaoForm/page', { data: { store_id: app.globalData.setting.stoid, id: this.data.id, }, isShowLoading: true, }).then(function(res) { self.setData({ details: res.data.data.pageData[0], }); }); app.request.promiseGet('/api/weshop/libao/libaoList/page', { data: { store_id: app.globalData.setting.stoid, lbid: this.data.id, }, isShowLoading: true, }).then(function(res) { self.setData({ list: res.data.data.pageData, }); }); } else if(this.data.index == 1) { app.request.promiseGet('/api/weshop/libao/libaoFormvip/page', { data: { store_id: app.globalData.setting.stoid, user_id: app.globalData.user_id, id: this.data.id, }, isShowLoading: true, }).then(function(res) { // console.log('res3-->', res); if(res.data.code==0 && res.data.data && res.data.data.pageData && res.data.data.pageData.length>0){ self.setData({ details: res.data.data.pageData[0], }); } }); app.request.promiseGet('/api/weshop/libao/libaoListvip/page', { data: { store_id: app.globalData.setting.stoid, lbvipid: this.data.id, }, isShowLoading: true, }).then(function(res) { // console.log('res4-->', res); if(res.data.code==0 && res.data.data && res.data.data.pageData && res.data.data.pageData.length>0) { var list_arr=res.data.data.pageData; for(var i in list_arr){ list_arr[i].alsonum= list_arr[i]['goods_num'] - list_arr[i]['usenum'];//剩余次数 } self.setData({ list: res.data.data.pageData, }); } }); }; }; }; }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, //-- 礼包购买 -- GetBuyPrice: function(e) { var th = this,that=th; var item=th.data.details; var id = item.id; //活动id var my_confirm = th.selectComponent("#my_confirm"); //组件的id var user=getApp().globalData.userInfo; my_confirm.open( "是否确定购买该礼包", "取消", "确定", function() { my_confirm.open_cancel(0); }, function() { my_confirm.open_cancel(0); var json = { "lbid": id, //活动Id "paytype": 2, //1=积分兑换 2=购买 "store_id": os.stoid, //商家Id "user_id": user.user_id, //用户ID }; var url = "/api/weshop/libao/libaoFormvip/libaoOrder"; getApp().request.post(url, { data:json, success:function(res) { if (res.data.code == 0 && res.data.data) { res = res.data.data; wx.requestPayment({ timeStamp: String(res.timeStamp), nonceStr: res.nonceStr, package: res.packageValue, signType: res.signType, paySign: res.paySign, success: function(res) { getApp().my_warnning("支付成功", 1, th); setTimeout(function (){ getApp().goto("/packageA/pages/libao_payment/payment?type=2"); },1000) }, fail: function(res) { getApp().my_warnning("取消支付", 0, th); } }); } else { getApp().my_warnning(res.data.msg, 0, th); } } }) }) }, //-- 积分兑换 -- GetBuyIntegral: function(e) { var th = this,that=th; var item=th.data.details; var id = item.id; //活动id var my_confirm = th.selectComponent("#my_confirm"); //组件的id var user=getApp().globalData.userInfo; my_confirm.open( "是否确定兑换该礼包", "取消", "确定", function() { my_confirm.open_cancel(0); }, function() { my_confirm.open_cancel(0); var json = { "lbid": id, //活动Id "paytype": 1, //1=积分兑换 2=购买 "store_id": os.stoid, //商家Id "user_id": user.user_id, //用户ID }; var url = "/api/weshop/libao/libaoFormvip/libaoOrder"; getApp().request.post(url,{ data:json, success:function(res) { if (res.data.code == 0) { getApp().my_warnning("兑换成功!", 1, th); setTimeout(function (){ getApp().goto("/packageA/pages/libao_payment/payment?type=1"); },1000) } else { getApp().my_warnning(res.data.msg, 0, th); } }, }) }) }, //显示二维码,进行核销 show_hxm:function (e){ var th=this; var type=e.currentTarget.dataset.type; var data={}; data.store_id=os.stoid; data.user_id=getApp().globalData.user_id; if(type && parseInt(type)==1){ data.id=this.data.id; data.type=1; }else{ var index=e.currentTarget.dataset.index; var item=this.data.list[index]; data.id=item.id; data.type=2; } //获取二维码 getApp().request.get("/api/weshop/libao/libaoListvip/getLibaoCode",{ data:data, success:function (res){ if(res.data.code==0){ th.data.qr_code_object.val=res.data.data; var qc_com = th.selectComponent("#qrcode"); //组件的id qc_com.open(th.data.qr_code_object) }else{ wx.showToast({ title: res.data.msg, icon: 'none', duration: 2000 }) } } }) } })