From 036b4512a52d51fd14c280da01ec25b089d2e455 Mon Sep 17 00:00:00 2001 From: zpc Date: Mon, 15 Sep 2025 00:18:48 +0800 Subject: [PATCH] 312 --- pages/appointment/appointment-page.vue | 62 +++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/pages/appointment/appointment-page.vue b/pages/appointment/appointment-page.vue index b5120cc..f2f81d3 100644 --- a/pages/appointment/appointment-page.vue +++ b/pages/appointment/appointment-page.vue @@ -56,7 +56,6 @@ - @@ -65,6 +64,13 @@ + + + {{ getAgeRangeText() }} + + + 大于等于 @@ -105,6 +111,9 @@ + @@ -136,6 +145,10 @@ import { getReservationRoomList } from '@/common/server/interface/sq' const _containerBase = ref(null) +// 年龄选择器状态 +const agePickerVisible = ref(false) +const agePickerColumns = ref([[], []]) +const agePickerDefaultIndex = ref([0, 0]) const startTimeStr = ref(0) const endTimeStr = ref(0) @@ -402,6 +415,53 @@ onLoad(async () => { gameTypeRange.value = [...config.config.playingMethodOptions]; } }) +// 年龄列构建与显示/文案 +const buildAgeColumns = () => { + const minList = [{ value: 0, text: '不限' }] + for (let i = 18; i <= 80; i++) minList.push({ value: i, text: String(i) }) + const maxList = [{ value: 0, text: '不限' }] + for (let i = 18; i <= 80; i++) maxList.push({ value: i, text: String(i) }) + agePickerColumns.value = [minList, maxList] +} +const getAgeRangeText = () => { + const { min_age, max_age } = reservationInfo.value + if (min_age == 0 && max_age == 0) { + return '不限' + } + const minText = min_age === 0 ? '不限' : min_age + '岁' + const maxText = max_age === 0 ? '不限' : max_age + '岁' + return minText + ' - ' + maxText +} +const openAgePicker = () => { + buildAgeColumns() + // 计算默认索引 + const { min_age, max_age } = reservationInfo.value + const [mins, maxs] = agePickerColumns.value + const findIndexByValue = (arr, val) => { + const idx = arr.findIndex(it => Number(it.value) === Number(val)) + return idx >= 0 ? idx : 0 + } + agePickerDefaultIndex.value = [ + findIndexByValue(mins, min_age ?? 0), + findIndexByValue(maxs, max_age ?? 0), + ] + agePickerVisible.value = true +} +const onAgePickerConfirm = (e) => { + // uview-plus up-picker confirm 回调 e.value 为两列所选对象数组 + const selected = e && e.value ? e.value : [] + const min = selected[0] ? Number(selected[0].value) : 0 + const max = selected[1] ? Number(selected[1].value) : 0 + // 若最小值大于最大值,自动交换或归零“不限”优先 + let minAge = min + let maxAge = max + if (minAge !== 0 && maxAge !== 0 && minAge > maxAge) { + [minAge, maxAge] = [maxAge, minAge] + } + reservationInfo.value.min_age = minAge + reservationInfo.value.max_age = maxAge + agePickerVisible.value = false +}