修复:时间输入改为选择器
This commit is contained in:
@@ -111,7 +111,18 @@
|
||||
|
||||
<div class="modal-section">
|
||||
<div class="section-title">预约时间</div>
|
||||
<input v-model="draftAppointmentTime" class="time-input" type="datetime-local" :min="minAppointmentTime" step="1800" />
|
||||
<a-date-picker
|
||||
v-model:value="draftAppointmentTime"
|
||||
class="time-picker"
|
||||
style="width: 100%"
|
||||
format="YYYY-MM-DD HH:mm:ss"
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
input-read-only
|
||||
:disabled-date="disablePastAppointmentDate"
|
||||
:disabled-time="disablePastAppointmentTime"
|
||||
:show-time="{ minuteStep: 30, secondStep: 60, hideDisabledOptions: true }"
|
||||
placeholder="请选择预约时间"
|
||||
/>
|
||||
<div class="helper">{{ bookingHelperText }}</div>
|
||||
</div>
|
||||
</a-modal>
|
||||
@@ -187,25 +198,22 @@ const bookingHelperText = computed(() => {
|
||||
const texts: string[] = []
|
||||
if (currentShopHours.value) texts.push('门店营业时间:' + currentShopHours.value)
|
||||
if (currentItem.value?.approximateDuration) texts.push('预计时长:' + currentItem.value.approximateDuration)
|
||||
return texts.join(' · ') || '请选择晚于当前时间的预约时间'
|
||||
})
|
||||
const minAppointmentTime = computed(() => {
|
||||
const d = new Date()
|
||||
d.setSeconds(0, 0)
|
||||
d.setMinutes(d.getMinutes() + 5)
|
||||
return [
|
||||
d.getFullYear(),
|
||||
'-',
|
||||
String(d.getMonth() + 1).padStart(2, '0'),
|
||||
'-',
|
||||
String(d.getDate()).padStart(2, '0'),
|
||||
'T',
|
||||
String(d.getHours()).padStart(2, '0'),
|
||||
':',
|
||||
String(d.getMinutes()).padStart(2, '0')
|
||||
].join('')
|
||||
return texts.join(' · ') || '请选择至少晚于当前 5 分钟的预约时间'
|
||||
})
|
||||
|
||||
const getMinAppointmentDate = () => {
|
||||
const date = new Date()
|
||||
date.setSeconds(0, 0)
|
||||
date.setMinutes(date.getMinutes() + 5)
|
||||
return date
|
||||
}
|
||||
|
||||
const getDayBoundary = (date: Date) => {
|
||||
const boundary = new Date(date)
|
||||
boundary.setHours(0, 0, 0, 0)
|
||||
return boundary.getTime()
|
||||
}
|
||||
|
||||
const getCouponKey = (coupon: UserCoupon) => `${coupon.sourceType || 'USER_COUPON'}:${coupon.id}`
|
||||
|
||||
const calculateCouponDiscount = (coupon: UserCoupon | null, amount: number) => {
|
||||
@@ -356,7 +364,7 @@ const removeItem = async (item: CartItem) => {
|
||||
const openBookingModal = async (item: CartItem) => {
|
||||
currentItem.value = item
|
||||
draftArtistId.value = item.artistId
|
||||
draftAppointmentTime.value = item.appointmentTime ? item.appointmentTime.replace(' ', 'T').slice(0, 16) : ''
|
||||
draftAppointmentTime.value = item.appointmentTime || ''
|
||||
showBookingModal.value = true
|
||||
await Promise.all([loadArtists(item), loadShopHours(item.shopId)])
|
||||
}
|
||||
@@ -390,7 +398,36 @@ const loadShopHours = async (shopId?: number) => {
|
||||
}
|
||||
|
||||
const formatAppointmentDisplay = (value?: string) => value ? value.replace('T', ' ').slice(0, 16) : '未选择预约时间'
|
||||
const isPastAppointment = (value?: string) => !!value && new Date(value.replace(' ', 'T')).getTime() <= Date.now()
|
||||
const isPastAppointment = (value?: string) => !!value && new Date(value.replace(' ', 'T')).getTime() < getMinAppointmentDate().getTime()
|
||||
const disablePastAppointmentDate = (current: any) => {
|
||||
if (!current) {
|
||||
return false
|
||||
}
|
||||
return current.valueOf() < getDayBoundary(new Date())
|
||||
}
|
||||
const disablePastAppointmentTime = (current: any) => {
|
||||
if (!current || typeof current.format !== 'function') {
|
||||
return {}
|
||||
}
|
||||
const minDate = getMinAppointmentDate()
|
||||
const minDateText = [
|
||||
minDate.getFullYear(),
|
||||
String(minDate.getMonth() + 1).padStart(2, '0'),
|
||||
String(minDate.getDate()).padStart(2, '0')
|
||||
].join('-')
|
||||
if (current.format('YYYY-MM-DD') !== minDateText) {
|
||||
return {}
|
||||
}
|
||||
const minHour = minDate.getHours()
|
||||
const minMinute = minDate.getMinutes()
|
||||
return {
|
||||
disabledHours: () => Array.from({ length: minHour }, (_, index) => index),
|
||||
disabledMinutes: (selectedHour: number) => selectedHour === minHour
|
||||
? Array.from({ length: minMinute }, (_, index) => index)
|
||||
: [],
|
||||
disabledSeconds: () => []
|
||||
}
|
||||
}
|
||||
|
||||
const closeBookingModal = () => {
|
||||
showBookingModal.value = false
|
||||
@@ -405,11 +442,10 @@ const confirmBooking = () => {
|
||||
if (!currentItem.value) return closeBookingModal()
|
||||
if (!draftArtistId.value) return message.warning('请先选择美甲师')
|
||||
if (!draftAppointmentTime.value) return message.warning('请选择预约时间')
|
||||
const normalizedTime = draftAppointmentTime.value.replace('T', ' ') + ':00'
|
||||
if (isPastAppointment(normalizedTime)) return message.warning('预约时间必须晚于当前时间')
|
||||
if (isPastAppointment(draftAppointmentTime.value)) return message.warning('预约时间至少需要晚于当前 5 分钟')
|
||||
currentItem.value.artistId = draftArtistId.value
|
||||
currentItem.value.artist = availableArtists.value.find(artist => artist.id === draftArtistId.value)
|
||||
currentItem.value.appointmentTime = normalizedTime
|
||||
currentItem.value.appointmentTime = draftAppointmentTime.value
|
||||
closeBookingModal()
|
||||
}
|
||||
|
||||
@@ -502,5 +538,5 @@ onMounted(async () => {
|
||||
.artist-option { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid #d9d9d9; border-radius: 999px; background: #fff; cursor: pointer; }
|
||||
.artist-option.active { border-color: #1890ff; color: #1890ff; background: #f0f9ff; }
|
||||
.artist-option img { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; }
|
||||
.time-input { width: 100%; padding: 10px 12px; border: 1px solid #d9d9d9; border-radius: 8px; }
|
||||
.time-picker { border-radius: 8px; }
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user