success: res => { | success: res => { | ||||
// 发送 res.code 到后台换取 openId, sessionKey, unionId | // 发送 res.code 到后台换取 openId, sessionKey, unionId | ||||
// console.log(res) | // console.log(res) | ||||
if (res.code){ | |||||
if (res.code) { | |||||
console.log(res.code) | |||||
wx.request({ | wx.request({ | ||||
url: this.globalData.httpUrl+'openid', | url: this.globalData.httpUrl+'openid', | ||||
header: { | header: { | ||||
code: res.code | code: res.code | ||||
}, | }, | ||||
success: e => { | success: e => { | ||||
// console.log(e) | |||||
console.log(e) | |||||
if (e.data.code == 200) { | if (e.data.code == 200) { | ||||
this.globalData.openId = e.data.data.openid; | this.globalData.openId = e.data.data.openid; | ||||
this.globalData.session_key = e.data.data.session_key; | this.globalData.session_key = e.data.data.session_key; | ||||
wx.setStorageSync('openid', e.data.data.openid) | wx.setStorageSync('openid', e.data.data.openid) | ||||
wx.setStorageSync('session_key', e.data.data.session_key) | wx.setStorageSync('session_key', e.data.data.session_key) | ||||
wx.setStorageSync('token', e.data.data.token) | wx.setStorageSync('token', e.data.data.token) | ||||
// if (this.globalData.openidSuccessFuc) { | |||||
// this.globalData.openidSuccessFuc(); | |||||
// } | |||||
} | } | ||||
} | } | ||||
}) | }) | ||||
wx.reLaunch({ | wx.reLaunch({ | ||||
url: '/pages/register/register' | 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) | },this) | ||||
}, | }, | ||||
globalData: { | globalData: { | ||||
openidSuccessFuc: null,//方法回调 | |||||
userInfo: null, | userInfo: null, | ||||
present_id:"",//判断用户是通过领取优惠券进来的还是直接进的 | present_id:"",//判断用户是通过领取优惠券进来的还是直接进的 | ||||
number:"",//赠送优惠券的数量 | number:"",//赠送优惠券的数量 |
data: { | data: { | ||||
ticketUser: [],//优惠券信息 | ticketUser: [],//优惠券信息 | ||||
ticketStateArr:[],//优惠券使用状态 | ticketStateArr:[],//优惠券使用状态 | ||||
codePicUrl:"",//二维码图片地址 | |||||
yesCode: false,//二维码图片隐藏 | |||||
}, | }, | ||||
/** | /** | ||||
*/ | */ | ||||
onLoad: function (options) { | onLoad: function (options) { | ||||
console.log(options.id) | console.log(options.id) | ||||
this.getTicketUser(options.id,1) | |||||
this.getTicketUser(options.id, 1) | |||||
this.getCodeFn(options.id) | |||||
}, | }, | ||||
getTicketUser: function (id,from) {//获取优惠券信息 | getTicketUser: function (id,from) {//获取优惠券信息 | ||||
app.wxRequest(app.globalData.httpUrl + 'couponsell/detail', { coupon_sell_id: id, from: from}, e => { | app.wxRequest(app.globalData.httpUrl + 'couponsell/detail', { coupon_sell_id: id, from: from}, e => { | ||||
} | } | ||||
}, this) | }, 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, | |||||
}) | |||||
}, | |||||
/** | /** | ||||
* 生命周期函数--监听页面初次渲染完成 | * 生命周期函数--监听页面初次渲染完成 | ||||
*/ | */ |
</view> | </view> | ||||
<view class="lookView"> | <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> | </view> | ||||
<!-- <scroll-view class="scrollY" scroll-y="true"> | <!-- <scroll-view class="scrollY" scroll-y="true"> | ||||
<view class="history" wx:for="{{ticketStateArr}}"> | <view class="history" wx:for="{{ticketStateArr}}"> |
text-align: center; | text-align: center; | ||||
margin-top: 100rpx; | margin-top: 100rpx; | ||||
} | } | ||||
.codeImg{ | |||||
width: 200rpx; | |||||
height: 200rpx; | |||||
} | |||||
/* .scrollY{ | /* .scrollY{ | ||||
height: 200rpx; | height: 200rpx; | ||||
margin-top: 107rpx; | margin-top: 107rpx; |
// }) | // }) | ||||
}, | }, | ||||
getTicketUser: function (id,number) {//获取优惠券信息 | |||||
getTicketUser: function (id,number) {//获取赠送优惠券信息 | |||||
app.wxRequest(app.globalData.httpUrl + 'couponbuy/presentvisit', { present_id: id, present_num: number }, e => { | app.wxRequest(app.globalData.httpUrl + 'couponbuy/presentvisit', { present_id: id, present_num: number }, e => { | ||||
console.log(e) | console.log(e) | ||||
if (e.code == 201) { | if (e.code == 201) { |
}) | }) | ||||
setTimeout(function () { | setTimeout(function () { | ||||
if (app.globalData.present_id){ | if (app.globalData.present_id){ | ||||
wx.switchTab({ | |||||
wx.reLaunch({ | |||||
url: '/pages/receiveTicket/receiveTicket?shareId=' + app.globalData.present_id + "&number=" + app.globalData.number | url: '/pages/receiveTicket/receiveTicket?shareId=' + app.globalData.present_id + "&number=" + app.globalData.number | ||||
}) | }) | ||||
} else { | } else { | ||||
}) | }) | ||||
} | } | ||||
}, 1000) | }, 1000) | ||||
}else{ | |||||
wx.showToast({ | |||||
title: e.message, | |||||
duration:500 | |||||
}) | |||||
} | } | ||||
}, this,"POST") | }, this,"POST") | ||||
}, | }, |