@@ -13,14 +13,15 @@ App({ | |||
success: res => { | |||
// 发送 res.code 到后台换取 openId, sessionKey, unionId | |||
// console.log(res) | |||
if (res.code){ | |||
if (res.code) { | |||
console.log(res.code) | |||
wx.request({ | |||
url: this.globalData.httpUrl+'openid', | |||
header: { | |||
code: res.code | |||
}, | |||
success: e => { | |||
// console.log(e) | |||
console.log(e) | |||
if (e.data.code == 200) { | |||
this.globalData.openId = e.data.data.openid; | |||
this.globalData.session_key = e.data.data.session_key; | |||
@@ -28,7 +29,9 @@ App({ | |||
wx.setStorageSync('openid', e.data.data.openid) | |||
wx.setStorageSync('session_key', e.data.data.session_key) | |||
wx.setStorageSync('token', e.data.data.token) | |||
// if (this.globalData.openidSuccessFuc) { | |||
// this.globalData.openidSuccessFuc(); | |||
// } | |||
} | |||
} | |||
}) | |||
@@ -81,14 +84,21 @@ App({ | |||
wx.reLaunch({ | |||
url: '/pages/register/register' | |||
}) | |||
} else if (e.code == 202){//已注册跳到首页购券大厅 | |||
wx.switchTab({ | |||
url: '/pages/index/index' | |||
}) | |||
} else if (e.code == 202){//已注册 | |||
if (this.globalData.present_id){ | |||
wx.reLaunch({ | |||
url: '/pages/receiveTicket/receiveTicket?shareId=' + this.globalData.present_id + "&number=" + this.globalData.number | |||
}) | |||
} else { | |||
wx.switchTab({ | |||
url: '/pages/index/index' | |||
}) | |||
} | |||
} | |||
},this) | |||
}, | |||
globalData: { | |||
openidSuccessFuc: null,//方法回调 | |||
userInfo: null, | |||
present_id:"",//判断用户是通过领取优惠券进来的还是直接进的 | |||
number:"",//赠送优惠券的数量 |
@@ -9,6 +9,8 @@ Page({ | |||
data: { | |||
ticketUser: [],//优惠券信息 | |||
ticketStateArr:[],//优惠券使用状态 | |||
codePicUrl:"",//二维码图片地址 | |||
yesCode: false,//二维码图片隐藏 | |||
}, | |||
/** | |||
@@ -16,7 +18,8 @@ Page({ | |||
*/ | |||
onLoad: function (options) { | |||
console.log(options.id) | |||
this.getTicketUser(options.id,1) | |||
this.getTicketUser(options.id, 1) | |||
this.getCodeFn(options.id) | |||
}, | |||
getTicketUser: function (id,from) {//获取优惠券信息 | |||
app.wxRequest(app.globalData.httpUrl + 'couponsell/detail', { coupon_sell_id: id, from: from}, e => { | |||
@@ -28,6 +31,21 @@ Page({ | |||
} | |||
}, this) | |||
}, | |||
getCodeFn:function(id){//获取二维码 | |||
app.wxRequest(app.globalData.httpUrl + 'couponbuy/getqrcode', { coupon_sell_id: id}, e => { | |||
console.log(e) | |||
if (e.code == 200) { | |||
this.setData({ | |||
codePicUrl: e.data.coupon_url, | |||
}) | |||
} | |||
}, this) | |||
}, | |||
showCode:function(){//查看二维码 | |||
this.setData({ | |||
yesCode: true, | |||
}) | |||
}, | |||
/** | |||
* 生命周期函数--监听页面初次渲染完成 | |||
*/ |
@@ -41,7 +41,8 @@ | |||
</view> | |||
<view class="lookView"> | |||
<button plain="true" size="mini" class="lookCode">点击查看二维码</button> | |||
<button wx:if="{{!yesCode}}" plain="true" size="mini" class="lookCode" bindtap="showCode">点击查看二维码</button> | |||
<image wx:else class="codeImg" src="{{codePicUrl}}"></image> | |||
</view> | |||
<!-- <scroll-view class="scrollY" scroll-y="true"> | |||
<view class="history" wx:for="{{ticketStateArr}}"> |
@@ -92,6 +92,11 @@ | |||
text-align: center; | |||
margin-top: 100rpx; | |||
} | |||
.codeImg{ | |||
width: 200rpx; | |||
height: 200rpx; | |||
} | |||
/* .scrollY{ | |||
height: 200rpx; | |||
margin-top: 107rpx; |
@@ -30,7 +30,7 @@ Page({ | |||
// }) | |||
}, | |||
getTicketUser: function (id,number) {//获取优惠券信息 | |||
getTicketUser: function (id,number) {//获取赠送优惠券信息 | |||
app.wxRequest(app.globalData.httpUrl + 'couponbuy/presentvisit', { present_id: id, present_num: number }, e => { | |||
console.log(e) | |||
if (e.code == 201) { |
@@ -134,7 +134,7 @@ Page({ | |||
}) | |||
setTimeout(function () { | |||
if (app.globalData.present_id){ | |||
wx.switchTab({ | |||
wx.reLaunch({ | |||
url: '/pages/receiveTicket/receiveTicket?shareId=' + app.globalData.present_id + "&number=" + app.globalData.number | |||
}) | |||
} else { | |||
@@ -143,6 +143,11 @@ Page({ | |||
}) | |||
} | |||
}, 1000) | |||
}else{ | |||
wx.showToast({ | |||
title: e.message, | |||
duration:500 | |||
}) | |||
} | |||
}, this,"POST") | |||
}, |