[水感应客户端最新]
This commit is contained in:
111
pages/pay/index.js
Normal file
111
pages/pay/index.js
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 手太欠
|
||||
* 愿这世界都如故事里一样 美好而动人~
|
||||
*/
|
||||
|
||||
Page({
|
||||
data: {
|
||||
payCode : '', // code获取openid
|
||||
openId : '', // openid
|
||||
orderNo : '', // 订单编号
|
||||
total : '', // 订单金额
|
||||
paySuccess : false, // 兑换成功显示
|
||||
disabled : true
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
this.setData({
|
||||
orderNo : options.order_no,
|
||||
total : options.total
|
||||
})
|
||||
},
|
||||
|
||||
onShow() {
|
||||
wx.login({
|
||||
success: res => {
|
||||
this.setData({
|
||||
payCode: res.code
|
||||
})
|
||||
|
||||
// 获取openid
|
||||
this.openInfo()
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* openid
|
||||
*/
|
||||
openInfo() {
|
||||
wx.$api.auth.codeOpenid({code: this.data.payCode}).then(res => {
|
||||
this.setData({
|
||||
openId: res.data
|
||||
})
|
||||
}).catch(err => {})
|
||||
},
|
||||
|
||||
/**
|
||||
* 确认支付
|
||||
*/
|
||||
payBtn() {
|
||||
wx.showLoading({
|
||||
title: '支付中...',
|
||||
mask : true
|
||||
})
|
||||
let that = this
|
||||
wx.$api.mall.mallPay(this.data.orderNo,{type: 'miniapp', openid: this.data.openId}).then(res=>{
|
||||
wx.hideLoading()
|
||||
this.setData({
|
||||
disabled: false
|
||||
})
|
||||
let payInfo = JSON.parse(res.data.wechat)
|
||||
wx.requestPayment({
|
||||
timeStamp: payInfo.timeStamp,
|
||||
nonceStr : payInfo.nonceStr,
|
||||
package : payInfo.package,
|
||||
paySign : payInfo.paySign,
|
||||
signType : payInfo.signType,
|
||||
success : res=>{
|
||||
if(res.errMsg == "requestPayment:ok"){
|
||||
wx.showToast({
|
||||
title: '支付成功',
|
||||
icon: 'none',
|
||||
duration: 2000,
|
||||
//显示透明蒙层,防止触摸穿透
|
||||
mask:true,
|
||||
success: function () {
|
||||
that.setData({
|
||||
paySuccess: true
|
||||
})
|
||||
setTimeout(()=>{
|
||||
wx.redirectTo({
|
||||
url: '/pages/order/index?state=paid'
|
||||
})
|
||||
},3000)
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
fail : err=>{
|
||||
wx.showToast({
|
||||
title: '支付失败',
|
||||
icon: 'none',
|
||||
duration: 500,
|
||||
//显示透明蒙层,防止触摸穿透
|
||||
mask:true,
|
||||
success: function () {
|
||||
that.setData({
|
||||
paySuccess: true
|
||||
})
|
||||
setTimeout(()=>{
|
||||
wx.redirectTo({
|
||||
url: '/pages/order/index?state=unpay'
|
||||
})
|
||||
},3000)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}).catch(err => {});
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user