<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>
|