feat(success): 支付成功页面添加轮询逻辑
This commit is contained in:
parent
492dd04657
commit
a11f104adc
|
@ -41,7 +41,7 @@ import { mapGetters } from 'vuex'
|
||||||
import { payStatus, registerInfo } from '@/config/pay.js'
|
import { payStatus, registerInfo } from '@/config/pay.js'
|
||||||
import successDialog from '@/components/successDialog.vue'
|
import successDialog from '@/components/successDialog.vue'
|
||||||
|
|
||||||
let interval = null
|
let setTimeoutFlag = null
|
||||||
export default {
|
export default {
|
||||||
name: 'PaySuccess',
|
name: 'PaySuccess',
|
||||||
components: {
|
components: {
|
||||||
|
@ -50,7 +50,6 @@ export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
orderCode: '',
|
orderCode: '',
|
||||||
sucPay: 0,
|
|
||||||
specialArea: null,
|
specialArea: null,
|
||||||
isRecharge: undefined,
|
isRecharge: undefined,
|
||||||
}
|
}
|
||||||
|
@ -72,45 +71,39 @@ export default {
|
||||||
const extParam = JSON.parse(atob(options.extParam || '{}'))
|
const extParam = JSON.parse(atob(options.extParam || '{}'))
|
||||||
this.specialArea = extParam.specialArea
|
this.specialArea = extParam.specialArea
|
||||||
this.isRecharge = extParam.source
|
this.isRecharge = extParam.source
|
||||||
const source = options.source || ''
|
this.orderCode = extParam.orderCode || ''
|
||||||
if (source) {
|
this.orderCode && this.pollingPayStatus(this.orderCode)
|
||||||
this.orderCode = options.orderCode || ''
|
|
||||||
this.orderCode && this.checkPayStatus()
|
|
||||||
// this.goToOrderList()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置导航栏
|
// 设置导航栏
|
||||||
uni.setNavigationBarTitle({
|
uni.setNavigationBarTitle({
|
||||||
title: '支付成功',
|
title: '支付成功',
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
onUnload() {
|
onUnload() {
|
||||||
clearInterval(interval)
|
clearTimeout(setTimeoutFlag)
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 查询订单状态
|
pollingPayStatus(orderCode) {
|
||||||
checkPayStatus(orderCode) {
|
payStatus({ businessCode: orderCode }).then(res => {
|
||||||
// 定时器
|
if (res.data == 1) {
|
||||||
interval = setInterval(() => {
|
|
||||||
if (this.sucPay == 1) {
|
|
||||||
// 清除定时器
|
// 清除定时器
|
||||||
clearInterval(interval)
|
clearTimeout(setTimeoutFlag)
|
||||||
if (
|
if ([1, 7, 24].includes(Number(this.specialArea))) {
|
||||||
this.specialArea == 1 ||
|
|
||||||
this.specialArea == 7 ||
|
|
||||||
this.specialArea == 24
|
|
||||||
) {
|
|
||||||
registerInfo(orderCode).then(res => {
|
registerInfo(orderCode).then(res => {
|
||||||
this.$refs.successDialog.showSuccess(res.data)
|
this.$refs.successDialog.showSuccess(res.data)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
payStatus({ businessCode: orderCode }).then(res => {
|
payStatus({ businessCode: orderCode }).then(res => {
|
||||||
this.sucPay = res.data
|
if (res.data == 0) {
|
||||||
|
setTimeoutFlag = setTimeout(() => {
|
||||||
|
this.pollingPayStatus(orderCode)
|
||||||
|
}, 1000)
|
||||||
|
} else {
|
||||||
|
clearTimeout(setTimeoutFlag)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}, 2000)
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
// 跳转到订单列表
|
// 跳转到订单列表
|
||||||
|
|
Loading…
Reference in New Issue