H5-ThreeDoorder/pages/pay/index.vue

104 lines
2.1 KiB
Vue

<template>
<view>
</view>
</template>
<script>
let self;
import {
getOrderStatusAPI
} from '@/request/recharge/index.js';
import mixin from '@/static/js/mixin/mixin.js';
import {
mapGetters
} from 'vuex';
export default {
mixins:[mixin],
data() {
return {
index: 0,
redirect_url:'',
order_sn:'',
type:''
};
},
onLoad(p) {
console.log('onLoad');
self = this;
this['index'] = 0;
uni.showLoading({
title: '获取订单状态'
});
console.log(p,'ppp');
new Promise(resolve=>{
if(p?.order_sn){
this['redirect_url'] = p['redirect_url'];
this['order_sn'] = p['order_sn'];
this['type'] = p['type'];
resolve();
};
}).then(res=>{
this.OrderState(this['order_sn'],this['type']);
})
},
onShow() {
console.log('onShow');
if(this['index'] > 0){
this['index'] = 5;
}
},
computed: {
...mapGetters(['GetOperation'])
},
methods: {
OrderState(order_sn,type) {
console.log(order_sn,'进入轮询方法');
setTimeout(() => {
self['index'] += 1;
let parameters = {
order_sn,
type
};
getOrderStatusAPI(parameters).then(res => {
/**
* @调用5次之后如果还是未支付状态则直接判定为未支付订单列表
* */
if (self['index'] >= 5 && res['data']['pay_status'] == 0) {
console.log(order_sn,'次数限制');
uni.hideLoading();
self.pay_statepage({
order_sn,
type,
state:2
},this['redirect_url']);
return;
};
/**
* @未支付则一直调用
* */
if (res['data']['pay_status'] == 0) {
self.OrderState(order_sn,type);
return;
};
/**
* @调用支付状态成功则直接跳转
* */
uni.hideLoading();
self.pay_statepage({
order_sn:res['data']['order_sn'],
type,
state:1
},this['redirect_url']);
});
}, 500);
}
}
}
</script>
<style lang="scss">
</style>