优化规划月视图空日期操作

This commit is contained in:
2026-07-22 19:15:02 +08:00
parent 6dcb426b93
commit a3240d2323
3 changed files with 307 additions and 6 deletions
+105 -5
View File
@@ -1,6 +1,7 @@
const planningApi = require('../../api/planning')
const shopApi = require('../../api/shop')
const dateUtil = require('../../utils/date')
const { markPlanningRefresh } = require('../../utils/planning-refresh')
const CALENDAR_ERROR_FALLBACK_MESSAGE = '规划数据暂时不可用,请稍后重试'
const TECHNICAL_ERROR_PATTERNS = [
@@ -36,6 +37,21 @@ function formatMonthDay(value) {
return `${target.getMonth() + 1}月${target.getDate()}日`
}
function formatActionDate(value) {
const target = toLocalDate(value)
const weekLabels = ['日', '一', '二', '三', '四', '五', '六']
return `${target.getMonth() + 1}月${target.getDate()}日 周${weekLabels[target.getDay()]}`
}
function formatShortDate(value) {
const target = toLocalDate(value)
return `${target.getMonth() + 1}月${target.getDate()}日`
}
function buildAppointmentFormUrl(date, artistId) {
return `/pages/appointment-form/index?date=${date}&artistId=${artistId || ''}`
}
function resolveAppointmentDate(item) {
if (item.date) return item.date
return String(item.startTime || '').slice(0, 10)
@@ -141,9 +157,9 @@ Page({
data: {
viewMode: 'month',
viewModes: [
{ value: 'day', label: '日' },
{ value: 'month', label: '月' },
{ value: 'week', label: '周' },
{ value: 'month', label: '月' }
{ value: 'day', label: '日' }
],
monthDisplayMode: 'count',
monthDisplayModes: [
@@ -179,7 +195,12 @@ Page({
pendingCount: 0,
canCreateAppointment: true,
loading: false,
calendarError: ''
calendarError: '',
emptyDateActionVisible: false,
pendingEmptyDate: '',
pendingEmptyDateTitle: '',
pendingEmptyDateLabel: '',
savingRestDate: false
},
onLoad() {
@@ -224,14 +245,50 @@ Page({
selectDate(event) {
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) {
this.openEmptyDateAction(currentDate)
return
}
}
this.setData({
currentDate,
currentDateText: currentDate,
viewMode: this.data.viewMode === 'month' ? 'day' : this.data.viewMode
viewMode: this.data.viewMode === 'month' ? 'day' : this.data.viewMode,
emptyDateActionVisible: false,
pendingEmptyDate: '',
pendingEmptyDateTitle: '',
pendingEmptyDateLabel: ''
})
this.prepareView()
},
openEmptyDateAction(date) {
const currentDate = dateUtil.formatDate(date)
this.setData({
currentDate,
currentDateText: currentDate,
emptyDateActionVisible: true,
pendingEmptyDate: currentDate,
pendingEmptyDateTitle: formatActionDate(currentDate),
pendingEmptyDateLabel: formatShortDate(currentDate)
})
this.prepareView()
},
closeEmptyDateAction() {
this.setData({
emptyDateActionVisible: false,
pendingEmptyDate: '',
pendingEmptyDateTitle: '',
pendingEmptyDateLabel: '',
savingRestDate: false
})
},
stopTap() {},
prevRange() {
this.shiftRange(-1)
},
@@ -579,10 +636,53 @@ Page({
return
}
wx.navigateTo({
url: `/pages/appointment-form/index?date=${this.data.currentDateText}&artistId=${this.data.selectedArtistId || ''}`
url: buildAppointmentFormUrl(this.data.currentDateText, this.data.selectedArtistId)
})
},
createAppointmentFromEmptyDate() {
if (!this.data.pendingEmptyDate) {
wx.showToast({ title: '请选择预约日期', icon: 'none' })
return
}
if (!this.data.canCreateAppointment) {
wx.showToast({ title: '美甲师账号只能查看预约', icon: 'none' })
return
}
this.setData({ emptyDateActionVisible: false })
wx.navigateTo({
url: buildAppointmentFormUrl(this.data.pendingEmptyDate, this.data.selectedArtistId)
})
},
async setEmptyDateAsRest() {
if (!this.data.pendingEmptyDate) {
wx.showToast({ title: '请选择休息日期', icon: 'none' })
return
}
if (this.data.savingRestDate) {
return
}
this.setData({ savingRestDate: true })
try {
await shopApi.saveScheduleException({
workDate: this.data.pendingEmptyDate,
exceptionType: 'REST',
startTime: null,
endTime: null,
remark: '规划页快速设置'
})
markPlanningRefresh()
wx.showToast({ title: '已设为休息日', icon: 'success' })
this.closeEmptyDateAction()
await this.loadCalendar()
} catch (error) {
wx.showToast({ title: error.message || '休息日设置失败', icon: 'none' })
} finally {
this.setData({ savingRestDate: false })
}
},
openAppointment(event) {
wx.navigateTo({
url: `/pages/appointment-detail/index?id=${event.currentTarget.dataset.id}`