完善规划页特殊日期弹窗

This commit is contained in:
2026-07-22 20:01:38 +08:00
parent e7877be77d
commit df4344dd46
3 changed files with 258 additions and 33 deletions
+82 -15
View File
@@ -52,6 +52,23 @@ function buildAppointmentFormUrl(date, artistId) {
return `/pages/appointment-form/index?date=${date}&artistId=${artistId || ''}`
}
const SPECIAL_DATE_TYPES = [
{ value: 'REST', label: '休息日', desc: '当天不开放预约', icon: '休', tone: 'rest', requiresTime: false },
{ value: 'EXTRA_WORK', label: '临时营业', desc: '原休息日也可开放预约', icon: '营', tone: 'work', requiresTime: true },
{ value: 'CHANGE_SHIFT', label: '临时改班', desc: '当天改成指定营业时段', icon: '改', tone: 'shift', requiresTime: true }
]
function resolveSpecialDateType(value) {
return SPECIAL_DATE_TYPES.find(item => item.value === value) || SPECIAL_DATE_TYPES[0]
}
function buildSpecialDateTypes(activeValue) {
return SPECIAL_DATE_TYPES.map(item => ({
...item,
active: item.value === activeValue
}))
}
function resolveAppointmentDate(item) {
if (item.date) return item.date
return String(item.startTime || '').slice(0, 10)
@@ -200,7 +217,13 @@ Page({
pendingEmptyDate: '',
pendingEmptyDateTitle: '',
pendingEmptyDateLabel: '',
savingRestDate: false
specialDateTypes: buildSpecialDateTypes('REST'),
pendingSpecialDateType: 'REST',
pendingSpecialDateTypeLabel: '休息日',
pendingSpecialDateRequiresTime: false,
pendingSpecialDateStartTime: '10:00',
pendingSpecialDateEndTime: '22:00',
savingSpecialDate: false
},
onLoad() {
@@ -247,7 +270,7 @@ Page({
const currentDate = dateUtil.formatDate(event.currentTarget.dataset.date)
if (this.data.viewMode === 'month') {
const monthDay = this.data.monthDays.find(item => item.date === currentDate)
if (monthDay && monthDay.isCurrentMonth && Number(monthDay.totalCount || 0) === 0 && !monthDay.shopRest) {
if (monthDay && monthDay.isCurrentMonth && !monthDay.isPast && Number(monthDay.totalCount || 0) === 0) {
this.openEmptyDateAction(currentDate)
return
}
@@ -259,36 +282,73 @@ Page({
emptyDateActionVisible: false,
pendingEmptyDate: '',
pendingEmptyDateTitle: '',
pendingEmptyDateLabel: ''
pendingEmptyDateLabel: '',
savingSpecialDate: false
})
this.prepareView()
},
openEmptyDateAction(date) {
const currentDate = dateUtil.formatDate(date)
const monthDay = this.data.monthDays.find(item => item.date === currentDate)
const typeValue = monthDay && monthDay.shopRest ? 'EXTRA_WORK' : 'REST'
const option = resolveSpecialDateType(typeValue)
this.setData({
currentDate,
currentDateText: currentDate,
emptyDateActionVisible: true,
pendingEmptyDate: currentDate,
pendingEmptyDateTitle: formatActionDate(currentDate),
pendingEmptyDateLabel: formatShortDate(currentDate)
pendingEmptyDateLabel: formatShortDate(currentDate),
specialDateTypes: buildSpecialDateTypes(option.value),
pendingSpecialDateType: option.value,
pendingSpecialDateTypeLabel: option.label,
pendingSpecialDateRequiresTime: option.requiresTime,
pendingSpecialDateStartTime: this.data.businessStartTime,
pendingSpecialDateEndTime: this.data.businessEndTime,
savingSpecialDate: false
})
this.prepareView()
},
closeEmptyDateAction() {
const option = resolveSpecialDateType('REST')
this.setData({
emptyDateActionVisible: false,
pendingEmptyDate: '',
pendingEmptyDateTitle: '',
pendingEmptyDateLabel: '',
savingRestDate: false
specialDateTypes: buildSpecialDateTypes(option.value),
pendingSpecialDateType: option.value,
pendingSpecialDateTypeLabel: option.label,
pendingSpecialDateRequiresTime: option.requiresTime,
pendingSpecialDateStartTime: this.data.businessStartTime,
pendingSpecialDateEndTime: this.data.businessEndTime,
savingSpecialDate: false
})
},
stopTap() {},
selectEmptyDateSpecialType(event) {
const value = String(event.currentTarget.dataset.value || 'REST')
const option = resolveSpecialDateType(value)
this.setData({
specialDateTypes: buildSpecialDateTypes(option.value),
pendingSpecialDateType: option.value,
pendingSpecialDateTypeLabel: option.label,
pendingSpecialDateRequiresTime: option.requiresTime
})
},
onEmptyDateStartTimeChange(event) {
this.setData({ pendingSpecialDateStartTime: event.detail.value })
},
onEmptyDateEndTimeChange(event) {
this.setData({ pendingSpecialDateEndTime: event.detail.value })
},
prevRange() {
this.shiftRange(-1)
},
@@ -655,31 +715,38 @@ Page({
})
},
async setEmptyDateAsRest() {
async saveEmptyDateSpecialDate() {
if (!this.data.pendingEmptyDate) {
wx.showToast({ title: '请选择休息日期', icon: 'none' })
wx.showToast({ title: '请选择特殊日期', icon: 'none' })
return
}
if (this.data.savingRestDate) {
if (this.data.savingSpecialDate) {
return
}
this.setData({ savingRestDate: true })
const option = resolveSpecialDateType(this.data.pendingSpecialDateType)
const startTime = this.data.pendingSpecialDateStartTime
const endTime = this.data.pendingSpecialDateEndTime
if (option.requiresTime && (!startTime || !endTime || startTime >= endTime)) {
wx.showToast({ title: '请设置正确营业时间', icon: 'none' })
return
}
this.setData({ savingSpecialDate: true })
try {
await shopApi.saveScheduleException({
workDate: this.data.pendingEmptyDate,
exceptionType: 'REST',
startTime: null,
endTime: null,
exceptionType: option.value,
startTime: option.requiresTime ? startTime : null,
endTime: option.requiresTime ? endTime : null,
remark: '规划页快速设置'
})
markPlanningRefresh()
wx.showToast({ title: '已设为休息日', icon: 'success' })
wx.showToast({ title: '特殊日期已保存', icon: 'success' })
this.closeEmptyDateAction()
await this.loadCalendar()
} catch (error) {
wx.showToast({ title: error.message || '休息日设置失败', icon: 'none' })
wx.showToast({ title: error.message || '特殊日期保存失败', icon: 'none' })
} finally {
this.setData({ savingRestDate: false })
this.setData({ savingSpecialDate: false })
}
},