1.展示
2.
<view class="btnWarp">
<view class="mask_item mask_bottom">
<view class="loginBtn btn" @click="submit">立即支付</view>
</view>
</view>
3.方法
data() {
return {
optionObj: {},
}
},
methods: {
//立即支付
submit() {
this.$utils.stopClick(null, 2000).then(res => {
uni.showLoading({
mask: true,
title: '加载中...'
})
//支付成功跳转至订单详情
uni.hideLoading();
let that = this;
uni.requestPayment({
provider: 'wxpay',
timeStamp: this.optionObj.data.result.jsConfig.timeStamp,//时间戳从1970年1月1日至今的秒数,即当前的时间。
nonceStr: this.optionObj.data.result.jsConfig.nonceStr,//随机字符串,长度为32个字符以下。//统一下单接口返回的 prepay_id 参数值,提交格式如:prepay_id=xx
package: this.optionObj.data.result.jsConfig.package,
signType: this.optionObj.data.result.jsConfig.signType,//签名算法,应与后台下单时的值一致
paySign: this.optionObj.data.result.jsConfig.paySign,//签名
success: function(res) {
// console.log('success:', that.optionObj);
//跳转页面
uni.showToast({
title: '支付成功',
icon: 'none'
})
uni.removeStorageSync('optionObj');
//返回订单详情
uni.setStorageSync('optionObj',that.optionObj.data.result)
uni.redirectTo({
url: `/pagesA/myOrder/orderDetails?type=1`
})
},
fail: function(err) {
console.log("支付失败的原因", err);
uni.showToast({
title: '取消支付',
icon: 'none'
})
var pages = getCurrentPages();
var currPage = pages[pages.length - 1]; //当前页面
var prevPage = pages[pages.length - 2]; //上一个页面
prevPage.$vm.showCar = false;
setTimeout(() => {
uni.navigateBack({
delta: -1
})
}, 800)
}
});
})
},
}