157 lines
4.3 KiB
JavaScript
157 lines
4.3 KiB
JavaScript
/*
|
|
* 手太欠
|
|
* 愿这世界都如故事里一样 美好而动人~
|
|
*/
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
orderId : '',
|
|
identityid : '',
|
|
items : [{
|
|
value : 'wechat',
|
|
name : '微信支付',
|
|
cover : '/static/icons/payIcon_00.png',
|
|
checked: 'true'
|
|
},
|
|
{
|
|
value : 'code',
|
|
name : '激活码支付',
|
|
cover : '/static/icons/payIcon_01.png'
|
|
}
|
|
],
|
|
current : 0,
|
|
payState : false, //支付选择弹出
|
|
writeState : false, //激活码弹出
|
|
disabled : false, //按钮状态
|
|
payType : 'wechat' //支付类型 wechat微信 code激活码
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
this.setData({
|
|
identityid: options.identityid
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
// 获取身份信息
|
|
this.identityInfo();
|
|
},
|
|
|
|
/**
|
|
* 身份信息
|
|
*/
|
|
identityInfo() {
|
|
wx.$api.member.identityOpen(this.data.identityid).then(res => {
|
|
this.setData({
|
|
// orderId: res.data.order
|
|
orderId: res.data.order_id
|
|
})
|
|
}).catch(err => {})
|
|
},
|
|
|
|
/**
|
|
* 选择支付
|
|
*/
|
|
payChange(e) {
|
|
this.setData({
|
|
payType: e.detail.value
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 显示支付选择弹出
|
|
*/
|
|
payShow() {
|
|
this.setData({
|
|
payState: !this.data.payState
|
|
})
|
|
},
|
|
|
|
// 微信支付
|
|
payment() {
|
|
// 隐藏支付选择弹出
|
|
this.setData({
|
|
payState: false
|
|
})
|
|
if(this.data.payType == 'code') {
|
|
// 弹出激活码填写表单
|
|
this.setData({
|
|
writeState: !this.data.writeState
|
|
})
|
|
return
|
|
}
|
|
// 微信支付
|
|
wx.login({
|
|
success: res => {
|
|
wx.$api.member.openid(res).then(openidRes => {
|
|
wx.$api.member.identityPay(this.data.orderId, {
|
|
channel: 'miniapp',
|
|
openid : openidRes.data
|
|
}).then(PayRes => {
|
|
let payInfo = JSON.parse(PayRes.data.wechat)
|
|
wx.requestPayment({
|
|
timeStamp: payInfo.timeStamp,
|
|
nonceStr : payInfo.nonceStr,
|
|
package : payInfo.package,
|
|
paySign : payInfo.paySign,
|
|
signType : payInfo.signType,
|
|
success : payInfoRes=>{
|
|
if(payInfoRes.errMsg == "requestPayment:ok"){
|
|
wx.showToast({
|
|
title: '支付成功',
|
|
icon : 'success'
|
|
})
|
|
setTimeout(()=>{
|
|
wx.navigateTo({
|
|
url: './tips/index'
|
|
})
|
|
},3000)
|
|
}
|
|
},
|
|
fail : res=>{
|
|
wx.showToast({
|
|
title: '取消支付',
|
|
icon: 'none'
|
|
})
|
|
}
|
|
})
|
|
}).catch(err => {})
|
|
}).catch(err => {})
|
|
}
|
|
})
|
|
},
|
|
|
|
// 激活码支付
|
|
writePayment(e) {
|
|
let newCode = e.detail.value.code
|
|
wx.$api.member.codePay(this.data.orderId, {
|
|
code: newCode
|
|
}).then(res => {
|
|
this.setData({
|
|
disabled: true
|
|
})
|
|
|
|
// 返回上一页
|
|
wx.navigateBack();
|
|
}).catch(err => {})
|
|
},
|
|
|
|
/**
|
|
* 关闭激活码填写
|
|
*/
|
|
writeHide(){
|
|
this.setData({
|
|
writeState: false
|
|
})
|
|
},
|
|
}) |