<template>
|
<view class="page-wrapper">
|
<div class="bg-top"></div>
|
|
<div class="content-wrapper">
|
|
<view class="text-2xl font-bold text-center mb-4">场馆预约参观</view>
|
|
<!-- 预约场馆 -->
|
<view class="flex items-center h-11 mb-4">
|
<label class="w-24 text-sm font-medium">预约场馆:</label>
|
<picker mode="selector" :range="booking_sites" :value="form.selectedSiteIndex" @change="onVenueChange">
|
<view
|
class="flex flex-1 items-center justify-between h-35px px-3 rounded border border-gray-300 bg-gray-50 active-bg-gray-100 transition-all duration-150">
|
<text class="truncate text-gray-800 text-sm">
|
{{ booking_sites[form.selectedSiteIndex] || '请选择场馆' }}
|
</text>
|
<text class="text-gray-400 text-xs">▼</text>
|
</view>
|
</picker>
|
</view>
|
|
<!-- 预约日期 -->
|
<view class="flex items-center h-11 mb-4">
|
<label class="w-24 text-sm font-medium">预约日期:</label>
|
<picker mode="date" :value="form.visitdate" @change="onDateChange" :start="today">
|
<view
|
class="flex flex-1 items-center justify-between h-35px px-3 rounded border border-gray-300 bg-gray-50 active-bg-gray-100 transition-all duration-150">
|
<text class="truncate text-gray-800 text-sm">
|
{{ form.visitdate || '请选择日期' }}
|
</text>
|
<text class="text-gray-400 text-xs">▼</text>
|
</view>
|
</picker>
|
</view>
|
|
<!-- 预约时段 -->
|
<view class="flex items-center space-x-2 h-15 mb-4">
|
<label class="w-24 text-sm font-medium">预约时段:</label>
|
<picker mode="selector" :range="timeSlots" :value="form.selectedTimeSlotIndex"
|
@change="onTimeSlotChange">
|
<view
|
class="flex flex-1 items-center justify-between h-35px px-3 rounded border border-gray-300 bg-gray-50 active-bg-gray-100 transition-all duration-150">
|
<text class="truncate text-gray-800 text-sm">
|
{{ form.selectedTimeSlotIndex !== null ? timeSlots[form.selectedTimeSlotIndex] : '请选择时段' }}
|
</text>
|
<text class="text-gray-400 text-xs">▼</text>
|
</view>
|
</picker>
|
</view>
|
|
<!-- 预约人 -->
|
<view class="flex items-center space-x-2 h-11 mb-4">
|
<label class="w-24 text-sm font-medium">预约人员:</label>
|
<input v-model="form.contactperson" type="text" placeholder="请输入姓名(最多10个字)"
|
class="flex-1 border border-gray-300 rounded p-2 h-12" />
|
</view>
|
<view class="h-5"></view>
|
|
<!-- 预约电话 -->
|
<view class="flex items-center space-x-2 h-11 mb-4 mt-2">
|
<label class="w-24 text-sm font-medium">预约电话:</label>
|
<input v-model="form.contactphone" type="text" placeholder="请输入联系电话"
|
class="flex-1 border border-gray-300 rounded p-2 h-12" />
|
</view>
|
<view class="h-5"></view>
|
|
<!-- 同行人数 -->
|
<view class="flex items-center space-x-2 h-11 mb-4">
|
<label class="w-24 text-sm font-medium">同行人数:</label>
|
<view class="flex items-center space-x-2 h-11">
|
<view
|
class="w-8 h-8 border border-dashed border-gray-300 bg-blue-500 rounded text-white flex justify-center items-center cursor-pointer"
|
@click="decrementCompanions">
|
-
|
</view>
|
<view class="mx-8 text-center w-8">{{ form.personcount }}</view>
|
<!--<button @click="incrementCompanions" class="w-8 h-8 bg-gray-300 rounded">+</button> -->
|
<view
|
class="w-8 h-8 border border-dashed border-gray-300 bg-blue-500 rounded text-white flex justify-center items-center cursor-pointer"
|
@click="incrementCompanions">
|
+
|
</view>
|
<view class="text-xs text-gray-500 ml-5">(1-5人)</view>
|
</view>
|
</view>
|
|
<!-- 提交按钮 -->
|
<button @click="submitForm" class="w-full bg-blue-500 text-white py-3 rounded-lg mt-4">提交预约</button>
|
|
</div>
|
<div class="bg-bottom"></div>
|
|
</view>
|
</template>
|
|
<script>
|
import {
|
useUserStore
|
} from '@/stores/user'
|
const userStore = useUserStore()
|
import {
|
ASSETS
|
} from './assets'
|
import {
|
apiService
|
} from '../../apiservice/apiService'
|
|
function getTodayISO() {
|
const now = new Date();
|
const tzOffset = now.getTimezoneOffset() * 60000;
|
return new Date(now - tzOffset).toISOString().split('T')[0];
|
}
|
|
export default {
|
data() {
|
return {
|
today: getTodayISO(),
|
//today: new Date().toLocaleDateString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '-'),
|
booking_sites: ASSETS.booking_sites,
|
timeSlots: [],
|
form: {
|
selectedSiteIndex: 0,
|
visitdate: '',
|
selectedTimeSlotIndex: null,
|
contactperson: userStore.username,
|
contactphone: userStore.phone,
|
personcount: 1
|
}
|
}
|
},
|
onShareAppMessage() {
|
return {
|
title: '欢迎来荆门市园博园游玩!',
|
path: '/pages/index/index'
|
}
|
},
|
onShareTimeline() {
|
return {
|
title: '欢迎来荆门市园博园游玩!'
|
}
|
},
|
watch: {
|
'form.selectedSiteIndex': 'fetchTimeSlots',
|
'form.visitdate': 'fetchTimeSlots'
|
},
|
methods: {
|
onVenueChange(e) {
|
this.form.selectedSiteIndex = e.detail.value;
|
this.form.visitdate = '';
|
},
|
onDateChange(e) {
|
this.form.visitdate = e.detail.value;
|
},
|
onTimeSlotChange(e) {
|
this.form.selectedTimeSlotIndex = e.detail.value;
|
},
|
async fetchTimeSlots() {
|
if (!this.form.visitdate) return;
|
const sitename = this.booking_sites[this.form.selectedSiteIndex];
|
const visitdate = this.form.visitdate;
|
|
apiService.bookingAvailableCount()
|
try {
|
uni.showLoading({
|
title: '查询中...'
|
});
|
const payload = {
|
sitename: sitename,
|
visitdate: visitdate
|
}
|
apiService.bookingAvailableCount(payload).then((res) => {
|
if (res.code === 1000) {
|
this.timeSlots = [
|
`上午(09:00-12:00 余${res.data.am.remain}/共${res.data.am.total}人)`,
|
`下午(13:00-17:00 余${res.data.pm.remain}/共${res.data.pm.total}人)`
|
];
|
this.selectedTimeSlotIndex = 0;
|
|
} else {
|
console.warn('查询失败:', res.message)
|
}
|
}).catch((err) => {
|
uni.showToast({
|
title: '发生错误,请联系管理员',
|
icon: 'none'
|
})
|
})
|
} catch (err) {
|
console.error("查询错误:", err);
|
uni.showToast({
|
title: "网络错误",
|
icon: "none"
|
});
|
} finally {
|
uni.hideLoading();
|
}
|
|
this.form.selectedTimeSlotIndex = null;
|
},
|
incrementCompanions() {
|
if (this.form.personcount < 5) this.form.personcount++;
|
},
|
decrementCompanions() {
|
if (this.form.personcount > 1) this.form.personcount--;
|
},
|
async submitForm() {
|
if (!this.form.contactperson || this.form.contactperson.length > 10) {
|
uni.showToast({
|
title: '姓名不能为空,且最多10个字',
|
icon: 'none'
|
});
|
return;
|
}
|
const phonePattern = /^(\d{11}|(\d{3,4}-?\d{7,8}))$/;
|
if (!phonePattern.test(this.form.contactphone)) {
|
uni.showToast({
|
title: '联系电话格式不正确',
|
icon: 'none'
|
});
|
return;
|
}
|
if (!this.form.visitdate) {
|
uni.showToast({
|
title: '请选择预约日期',
|
icon: 'none'
|
});
|
return;
|
}
|
if (this.form.selectedTimeSlotIndex === null) {
|
uni.showToast({
|
title: '请选择预约时段',
|
icon: 'none'
|
});
|
return;
|
} else {
|
const now = new Date();
|
const currentHour = now.getHours();
|
|
if (this.form.visitdate == this.today && currentHour > 17) {
|
uni.showToast({
|
title: '预约时段已过,请重新选择',
|
icon: 'none',
|
duration: 2000
|
});
|
return;
|
} else if (this.form.visitdate == this.today && currentHour > 12 && this.form
|
.selectedTimeSlotIndex == 0) {
|
uni.showToast({
|
title: '预约时段已过,请重新选择',
|
icon: 'none',
|
duration: 2000
|
});
|
return;
|
}
|
}
|
/* 开始保存*/
|
try {
|
uni.showLoading({
|
title: '保存中...'
|
});
|
|
const checkingPayload = {
|
uuid: userStore.uuid,
|
sitename: this.booking_sites[this.form.selectedSiteIndex],
|
visitdate: this.form.visitdate,
|
visittimefield: Number(this.form.selectedTimeSlotIndex) === 0 ? 'visittimeam' :
|
'visittimepm'
|
};
|
console.log(checkingPayload)
|
const res = await apiService.bookingCheck(checkingPayload);
|
if (res.code === 1000) {
|
console.log(res.data)
|
// real save booking
|
if (res.data.exist === 0) {
|
console.log("start saving")
|
|
const payload = {
|
uuid: userStore.uuid,
|
sitename: this.booking_sites[this.form.selectedSiteIndex],
|
visitdate: this.form.visitdate,
|
visittimeam: Number(this.form.selectedTimeSlotIndex) === 0 ? '09:00-12:00' : '',
|
visittimepm: Number(this.form.selectedTimeSlotIndex) === 1 ? '13:00-17:00' : '',
|
contactperson: this.form.contactperson,
|
contactphone: this.form.contactphone,
|
personcount: this.form.personcount,
|
};
|
console.log(payload)
|
const saveres = await apiService.bookingAdd(payload);
|
|
console.log(saveres.code)
|
|
if (saveres.code === 1000) {
|
|
uni.showModal({
|
title: '预约成功',
|
content: '请按时前往场馆,并扫码核销以便入场。',
|
showCancel: false,
|
confirmText: '我知道了'
|
})
|
this.form.visitdate = '';
|
this.form.selectedTimeSlotIndex = null;
|
uni.navigateTo({
|
url: '/pages/ucenter/my-booking'
|
})
|
|
} else {
|
console.warn('预约失败:', saveres.message)
|
}
|
|
} else {
|
uni.showToast({
|
title: '您已有预约相同日期和时段的该场馆信息,请更改信息。',
|
icon: 'none',
|
duration: 3000 // 显示 3 秒
|
})
|
}
|
|
|
} else {
|
console.warn('查询失败:', res.message)
|
}
|
|
|
} catch (err) {
|
console.error("查询错误:", err);
|
uni.showToast({
|
title: "网络错误",
|
icon: "none"
|
});
|
} finally {
|
uni.hideLoading();
|
}
|
|
|
|
|
}
|
}
|
}
|
</script>
|
<style>
|
/* 主容器样式 */
|
.flex {
|
display: flex;
|
}
|
|
.flex-1 {
|
flex: 1 1 0%;
|
}
|
|
.items-center {
|
align-items: center;
|
}
|
|
.cursor-pointer {
|
cursor: pointer;
|
}
|
|
.justify-center {
|
justify-content: center;
|
}
|
|
.justify-between {
|
justify-content: space-between;
|
}
|
|
.h-35px {
|
height: 35px;
|
line-height: 35px;
|
}
|
|
.px-3 {
|
padding-left: 0.75rem;
|
padding-right: 0.75rem;
|
}
|
|
.rounded {
|
border-radius: 0.25rem;
|
}
|
|
.border {
|
border-width: 1px;
|
}
|
|
.border-gray-300 {
|
border-color: rgb(209 213 219);
|
}
|
|
.bg-gray-50 {
|
background-color: rgb(249 250 251);
|
}
|
|
.active-bg-gray-100:active {
|
background-color: rgb(243 244 246);
|
}
|
|
.transition-all {
|
transition-property: all;
|
}
|
|
.duration-150 {
|
transition-duration: 150ms;
|
}
|
|
.truncate {
|
overflow: hidden;
|
text-overflow: ellipsis;
|
white-space: nowrap;
|
}
|
|
.text-gray-800 {
|
color: rgb(31 41 55);
|
}
|
|
.text-sm {
|
font-size: 0.875rem;
|
line-height: 1.25rem;
|
}
|
|
.text-gray-400 {
|
color: rgb(156 163 175);
|
}
|
|
.text-xs {
|
font-size: 0.75rem;
|
line-height: 1rem;
|
}
|
|
/* ------- 布局与容器 ------- */
|
.p-4 {
|
padding: 1rem;
|
}
|
|
.space-y-4 {
|
margin-top: 1rem;
|
}
|
|
.mb-4 {
|
margin-bottom: 1rem;
|
}
|
|
.mt-4 {
|
margin-top: 1rem;
|
}
|
|
/* ------- 字体与文字 ------- */
|
.text-2xl {
|
font-size: 1.5rem;
|
line-height: 2rem;
|
}
|
|
.text-sm {
|
font-size: 0.875rem;
|
line-height: 1.25rem;
|
}
|
|
.text-xs {
|
font-size: 0.75rem;
|
line-height: 1rem;
|
}
|
|
.text-center {
|
text-align: center;
|
}
|
|
.text-gray-500 {
|
color: #6b7280;
|
}
|
|
.font-bold {
|
font-weight: 700;
|
}
|
|
.font-medium {
|
font-weight: 500;
|
}
|
|
/* ------- 尺寸与布局 ------- */
|
.w-full {
|
width: 100%;
|
}
|
|
.flex {
|
display: flex;
|
}
|
|
.flex-1 {
|
flex: 1 1 0%;
|
}
|
|
.items-center {
|
align-items: center;
|
}
|
|
.h-full {
|
height: 100%;
|
}
|
|
.h-5 {
|
height: 1rem;
|
}
|
|
.h-11 {
|
height: 2rem;
|
}
|
|
.h-15 {
|
height: 3rem;
|
}
|
|
.h-12 {
|
height: 2rem;
|
}
|
|
.w-8 {
|
width: 2rem;
|
}
|
|
.ml-5 {
|
margin-left: 20rpx;
|
}
|
|
.h-8 {
|
height: 2rem;
|
}
|
|
.w-24 {
|
width: 5rem;
|
}
|
|
.w-28 {
|
width: 7rem;
|
}
|
|
/* ------- 边距与填充 ------- */
|
.p-2 {
|
padding: 0.5rem;
|
}
|
|
.px-3 {
|
padding-left: 0.75rem;
|
padding-right: 0.75rem;
|
}
|
|
.py-3 {
|
padding-top: 0.75rem;
|
padding-bottom: 0.75rem;
|
}
|
|
/* ------- 边框与圆角 ------- */
|
.border {
|
border-width: 1px;
|
border-style: solid;
|
border-color: #d1d5db;
|
}
|
|
.border-gray-300 {
|
border-color: #d1d5db;
|
}
|
|
.rounded {
|
border-radius: 0.25rem;
|
}
|
|
.rounded-lg {
|
border-radius: 0.5rem;
|
}
|
|
/* ------- 背景色与颜色 ------- */
|
.bg-blue-500 {
|
background-color: #3b82f6;
|
}
|
|
.bg-gray-300 {
|
background-color: #d1d5db;
|
}
|
|
.text-white {
|
color: #fff;
|
}
|
|
.mx-8 {
|
margin-left: 1rem;
|
margin-right: 1rem;
|
}
|
|
.text-center {
|
text-align: center;
|
}
|
|
.w-8 {
|
width: 2rem;
|
/* Tailwind w-8 默认 2rem */
|
}
|
|
/* ------- 按钮样式 ------- */
|
button {
|
border: none;
|
cursor: pointer;
|
}
|
|
/* 轻微交互效果 */
|
button:hover {
|
opacity: 0.9;
|
}
|
|
.page-wrapper {
|
position: relative;
|
min-height: 100vh;
|
/* 确保小内容时填满视口 */
|
overflow: hidden;
|
}
|
|
/* 顶部背景 */
|
.bg-top {
|
position: absolute;
|
top: 0;
|
left: 0;
|
width: 100%;
|
height: 500rpx;
|
/* 可用固定像素或图片高度 */
|
background: url('https://farm.evcc.top/Uploads/yuanboyuan/background/bg_top.jpg') no-repeat top center;
|
background-size: cover;
|
z-index: 0;
|
}
|
|
/* 底部背景 */
|
.bg-bottom {
|
position: absolute;
|
bottom: 0;
|
left: 0;
|
width: 100%;
|
height: 500rpx;
|
/* 可用固定像素或图片高度 */
|
background: url('https://farm.evcc.top/Uploads/yuanboyuan/background/bg_bottom.jpg') no-repeat bottom center;
|
background-size: cover;
|
z-index: 0;
|
}
|
|
/* 内容层 */
|
.content-wrapper {
|
position: relative;
|
z-index: 1;
|
padding: 2rem 1rem;
|
}
|
</style>
|