getOrder () {
const data = {
class_id: this.id, //需要支付的物品id
class_name: this.info.title, //需要支付的物品名称
student_list: this.student_list //人员
} //传过去的数据是根据后端需要的数据
this.$toast.loading({
duration: 0,
forbidClick: true,
mask: true,
message: '加载中...'
})
order(data)
.then((res) => {
this.order_id = res.data.order_id //后端返回来的你需要的数据订单id
this.getWxPlay(res.data.order_id) //将后端传回来的id传入调用支付函数里
})
.finally(() => {
this.$toast.clear()
})
},
getWxPlay (id) {
const arr = { order_id: id }
wxPlay(arr).then((res) => {
this.getWeixinJSBridge(res.data)
this.second = 60
clearInterval(this.timer)
this.getTime()
})
},
getWeixinJSBridge (data) {
console.log(data, '++++++')
// eslint-disable-next-line no-undef
WeixinJSBridge.invoke(
'getBrandWCPayRequest',
{
appId: data.appId + '',
timeStamp: data.timeStamp + '',
nonceStr: data.nonceStr + '',
signType: data.signType + '',
paySign: data.paySign + '',
package: data.package
},
function (res) {
// if (res.err_msg === 'get_brand_wcpay_request:ok') {
// this.$toast('支付成功')
// this.$router.push({ path: '/orderList' })
// } else if (res.err_msg === 'get_brand_wcpay_request:cancel') {
// this.$toast('取消支付')
// } else if (res.err_msg === 'get_brand_wcpay_request:fail') {
// this.$toast('支付失败')
// }
}
)
},
/* 定时刷新 */
getTime () {
this.timer = setInterval(() => {
if (this.second > 0) {
this.second--
this.getOrderStatus()
} else {
this.timer = ''
clearInterval(this.timer)
}
}, 1000)
},
// 支付状态
getOrderStatus () {
const data = {
order_id: this.order_id
}
orderStatus(data).then((res) => {
const isPay = res.data.is_pay
if (Number(isPay) === 1) {
clearInterval(this.timer)
this.$router.push({ path: '/orderList' }) //支付成功跳转
}
})
},
最后提醒,要部署上去才能测试