diff --git a/pages/pay/success.vue b/pages/pay/success.vue index 535a6cc..5d612a3 100644 --- a/pages/pay/success.vue +++ b/pages/pay/success.vue @@ -41,7 +41,7 @@ import { mapGetters } from 'vuex' import { payStatus, registerInfo } from '@/config/pay.js' import successDialog from '@/components/successDialog.vue' -let interval = null +let setTimeoutFlag = null export default { name: 'PaySuccess', components: { @@ -50,7 +50,6 @@ export default { data() { return { orderCode: '', - sucPay: 0, specialArea: null, isRecharge: undefined, } @@ -72,45 +71,39 @@ export default { const extParam = JSON.parse(atob(options.extParam || '{}')) this.specialArea = extParam.specialArea this.isRecharge = extParam.source - const source = options.source || '' - if (source) { - this.orderCode = options.orderCode || '' - this.orderCode && this.checkPayStatus() - // this.goToOrderList() - return - } - + this.orderCode = extParam.orderCode || '' + this.orderCode && this.pollingPayStatus(this.orderCode) // 设置导航栏 uni.setNavigationBarTitle({ title: '支付成功', }) }, onUnload() { - clearInterval(interval) + clearTimeout(setTimeoutFlag) }, methods: { - // 查询订单状态 - checkPayStatus(orderCode) { - // 定时器 - interval = setInterval(() => { - if (this.sucPay == 1) { + pollingPayStatus(orderCode) { + payStatus({ businessCode: orderCode }).then(res => { + if (res.data == 1) { // 清除定时器 - clearInterval(interval) - if ( - this.specialArea == 1 || - this.specialArea == 7 || - this.specialArea == 24 - ) { + clearTimeout(setTimeoutFlag) + if ([1, 7, 24].includes(Number(this.specialArea))) { registerInfo(orderCode).then(res => { this.$refs.successDialog.showSuccess(res.data) }) } } else { payStatus({ businessCode: orderCode }).then(res => { - this.sucPay = res.data + if (res.data == 0) { + setTimeoutFlag = setTimeout(() => { + this.pollingPayStatus(orderCode) + }, 1000) + } else { + clearTimeout(setTimeoutFlag) + } }) } - }, 2000) + }) }, // 跳转到订单列表