<script>
export default {
data () {
return {
timer: '',
}
},
methods: {
payOrder (type) {
let price = this.price;
let ordernum = this.orderN;
if (type == 2) { //支付宝支付
order.Alipay({ price, ordernum }).then(res => {
if (res.status == 200) {
$('#Alipay').html(res.data) //注意支付宝返回的数据是一个页面
} else {
this.$message.error('支付失败')
}
})
} else(type == 3) { //微信支付
order.weChatPay({ price, ordernum }).then(res => {
let data = res.data;
if (data.code === Code.CODE_SUCCESS) {
this.centerDialogVisible = true;
this.codeImg = data.data.img_url;
//支付轮询
this.timer = setInterval(() => {
this.selectOrderStatus();
}, 3000)
} else {
this.$message.error(data.msg)
}
})
}
},
// 支付轮询函数
selectOrderStatus () {
let ordernum = this.orderN,timestamp = Date.parse(new Date()) / 1000,sign = this.$md5(makeSign.makeSign({ ordernum, timestamp }))
order.selectOrderStatus({ ordernum, timestamp, sign }).then(res => {
let data = res.data;
if (data.code === Code.CODE_SUCCESS) {
clearInterval(this.timer);
this.timer = null;
this.$message.success('支付成功,2秒后将自动跳转到订单管理页面')
setTimeout(() => {
this.$router.push({
path: '/orderItem'
})
}, 2000)
} else {
return false
}
})
},
// 关闭弹窗清除轮询
closeWXpay () {
clearInterval(this.timer)
this.timer = null
},
},
mounted () {
},
filters: {
},
watch: {
}
}
</script>
WeChat(微信)二维码支付轮询
最新推荐文章于 2023-06-29 19:08:36 发布