wangzhibo
2025-10-23 cad64c1de2c45856b0774933c5801b05b64984e8
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
<template>
    <view class="p-4 space-y-4">
        <view class="text-2xl font-bold text-center mb-4">场馆预约核销</view>
    </view>
</template>
 
<script>
    import {
        useUserStore
    } from '@/stores/user'
    const userStore = useUserStore()
    import {
        apiService
    } from '@/apiservice/apiService'
 
    export default {
        onLoad(options) {
            console.log('扫码进入参数', options);
 
            if (options.q) {
                //1.将二维码链接解码
                let codeStr = decodeURIComponent(options.q)
                // 2. 提取 sitename
                const match = codeStr.match(/sitename=([^&]+)/); // 匹配 sitename= 后到 & 或结束
                const sitename = match ? match[1] : null;
                if (sitename) {
                    // 2️⃣ 获取当前时间
                    const now = new Date();
                    const todayStr = now.toISOString().split('T')[0]; // yyyy-mm-dd
                    const currentHour = now.getHours();
 
                    const checkingPayload = {
                        uuid: userStore.uuid,
                        sitename: sitename,
                        visitdate: todayStr,
                        visittimefield: currentHour <= 12 ? 'visittimeam' : 'visittimepm'
                    };
                    console.log(checkingPayload)
                    const res = await apiService.bookingCheck(checkingPayload);
                    if (res.code === 1000) {
                        console.log(res.data)
                        // 没有查找到记录
                        if (res.data.exist === 0) {
                            uni.showModal({
                                title: '无法核销',
                                content: '请检查您预约的场馆、日期和时段。',
                                showCancel: false,
                                confirmText: '我知道了'
                            });
                            uni.navigateTo({
                                url: '/pages/ucenter/my-booking'
                            })
                        } else {
                            const now = new Date();
                            const pad = (n) => n.toString().padStart(2, '0');
                            const getNowString = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())} ` +
                                    `${pad(now.getHours())}:${pad(now.getMinutes())}:${pad(now.getSeconds())}`;
                                    
                            const verifyRes = await apiService.bookingUse({
                                id: res.data.id,
                                usedtime: getNowString,
                                status: '已使用'
                            })
 
                            if (verifyRes.code === 1000) {
                                uni.showModal({
                                    title: '核销成功',
                                    content: '预约已核销,请工作人员确认',
                                    showCancel: false,
                                    confirmText: '确定',
                                    success: async () => {
                                        uni.navigateTo({
                                            url: '/pages/index/index'
                                        })
                                    }
                                });
                            } else {
                                uni.showToast({
                                    title: verifyRes.message || '核销失败',
                                    icon: 'none'
                                });
                            }
 
 
                        }
 
 
 
                    }
                }
 
            }
        }
</script>
<style>
 
</style>