Files
sgy-web/pages/pay/index.js

94 lines
3.0 KiB
JavaScript

/*
* 手太欠
* 愿这世界都如故事里一样 美好而动人~
*/
Page({
data: {
orderNo : '', // 订单编号
total : '', // 订单金额
paySuccess : false, // 兑换成功显示
disabled : true
},
onLoad(options) {
this.setData({
orderNo : options.order_no,
total : options.total
})
},
onShow() {},
/**
* 确认支付
*/
payBtn() {
this.setData({
disabled: false
})
wx.showLoading({
title: '支付中...',
mask : true
})
let that = this
wx.$api.mall.mallPay(this.data.orderNo,{type: 'miniapp', openid: wx.getStorageSync("openid")}).then(res=>{
wx.hideLoading()
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,
disabled: 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,
disabled: true
})
setTimeout(()=>{
wx.redirectTo({
url: '/pages/order/index?state=unpay'
})
},3000)
}
})
}
})
}).catch(err => {
that.setData({
disabled: true
})
});
}
})