waiting.vue
3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<!--
* @Date: 2024-01-19 21:57:50
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-01-30 15:22:54
* @FilePath: /xysBooking/src/views/waiting.vue
* @Description: 文件描述
-->
<template>
<div class="waiting-page">
<div class="waiting-content">
<div>
<van-icon name="clock-o" size="2.5rem" color="#A67939" />
</div>
<div style="margin: 1rem 0;">支付中</div>
<div>{{ current.seconds }} s</div>
<div style="margin: 1.5rem 0; font-size: 0.85rem; color: #A67939; text-align: center; line-height: 2;">
温馨提示:{{ pay_msg }}<br />
</div>
</div>
<div class="go-back-wrapper">
<div @click="goBackBtn" class="button" style="background-color: #A67939;">返回首页</div>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useCountDown } from '@vant/use';
import { Cookies, axios, storeToRefs, mainStore, Toast, useTitle } from '@/utils/generatePackage.js'
//import { } from '@/utils/generateModules.js'
//import { } from '@/utils/generateIcons.js'
//import { } from '@/composables'
import { showSuccessToast, showFailToast, showToast } from 'vant';
import { useGo } from '@/hooks/useGo'
import { billPayStatusAPI } from '@/api/index'
const $route = useRoute();
const $router = useRouter();
useTitle($route.meta.title);
const go = useGo();
const countDown = useCountDown({
time: 10 * 1000,
});
// 开始倒计时
countDown.start();
const current = countDown.current;
const pay_id = $route.query.pay_id;
const pay_msg = ref('支付可能需要10s左右,请耐心等待');
/**
* 3=支付成功,1=待支付,2=支付中,7=支付失败
*/
const PAY_STATUS = {
PAY: '1',
PAYING: '2',
FAIL: '7',
SUCCESS: '3'
}
onMounted(() => {
// 重置历史记录
window.history.pushState(null, '', location.origin + location.pathname); // 将授权页面替换为根路径或其他合适的路径
//
const timer = setInterval(async () => {
if (!current.value.seconds) {
clearInterval(timer);
}
const { code, data } = await billPayStatusAPI({ pay_id });
// TAG:轮询支付回调
switch (data.status) {
case PAY_STATUS.PAY:
pay_msg.value = '订单待支付';
break;
case PAY_STATUS.PAYING:
pay_msg.value = '订单支付中';
break;
case PAY_STATUS.SUCCESS:
// 预约成功页面
go('/success', { pay_id });
break;
case PAY_STATUS.FAIL:
pay_msg.value = '订单支付失败';
break;
}
}, 1000);
onUnmounted(() => {
clearInterval(timer);
})
});
const goBackBtn = () => {
go('/');
}
</script>
<style lang="less" scoped>
.waiting-page {
.waiting-content {
display: flex;
// justify-content: center;
align-items: center;
flex-direction: column;
margin-top: 10vh;
background-color: #FFF;
margin: 1rem;
border-radius: 8px;
padding: 3rem 0;
height: 40vh;
}
.go-back-wrapper {
position: fixed;
bottom: 0;
height: 5rem;
width: 100vw;
display: flex;
left: 0;
background-color: #FFF;
align-items: center;
justify-content: center;
box-shadow: 0rem -0.33rem 0.25rem 0rem rgba(0,0,0,0.12);
.button {
color: #FFF;
padding: 0.85rem 0;
border-radius: 8px;
font-size: 1.1rem;
text-align: center;
flex-grow: 1;
margin: 1rem;
}
}
}
</style>