diff --git a/pages/order/create.vue b/pages/order/create.vue index 7e67868..8ec6fde 100644 --- a/pages/order/create.vue +++ b/pages/order/create.vue @@ -153,8 +153,19 @@ const now = new Date(); const pad = (n) => (n < 10 ? '0' + n : '' + n); const today = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`; - const date = ref(today); - const time = ref('14:00'); + // 默认预约时间取当前时间之后的可用时段,避免默认值落在过去导致下单失败 + function defaultAppointment() { + const h = now.getHours(); + if (h >= 18) { + const t = new Date(now.getTime() + 86400000); + return { date: `${t.getFullYear()}-${pad(t.getMonth() + 1)}-${pad(t.getDate())}`, time: '09:00' }; + } + if (h >= 14) return { date: today, time: pad(h + 1) + ':00' }; + return { date: today, time: '14:00' }; + } + const defAppointment = defaultAppointment(); + const date = ref(defAppointment.date); + const time = ref(defAppointment.time); const form = reactive({ contact: '', mobile: '', address: '', floor: 1, has_elevator: 1, diff --git a/pages/order/quick.vue b/pages/order/quick.vue index d43bb33..2ceb19e 100644 --- a/pages/order/quick.vue +++ b/pages/order/quick.vue @@ -216,8 +216,19 @@ const now = new Date(); const pad = (n) => (n < 10 ? '0' + n : '' + n); const today = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`; - const date = ref(today); - const time = ref('14:00'); + // 默认预约时间取当前时间之后的可用时段,避免默认值落在过去导致下单失败 + function defaultAppointment() { + const h = now.getHours(); + if (h >= 18) { + const t = new Date(now.getTime() + 86400000); + return { date: `${t.getFullYear()}-${pad(t.getMonth() + 1)}-${pad(t.getDate())}`, time: '09:00' }; + } + if (h >= 14) return { date: today, time: pad(h + 1) + ':00' }; + return { date: today, time: '14:00' }; + } + const defAppointment = defaultAppointment(); + const date = ref(defAppointment.date); + const time = ref(defAppointment.time); const form = reactive({ goods_model: '', goods_num: 1, remark: '' }); let calcTimer = null;