修复Salon注册预约客户流程
This commit is contained in:
@@ -47,6 +47,22 @@ function resolveAppointmentTimeText(item) {
|
||||
return `${startText}-${endText}`
|
||||
}
|
||||
|
||||
function resolveBusinessHours(calendar = {}) {
|
||||
const parts = String(calendar.businessHours || '').split('-')
|
||||
const normalizeTime = value => {
|
||||
const match = /^(\d{1,2}):(\d{2})(?::\d{2})?$/.exec(String(value || '').trim())
|
||||
if (!match) return ''
|
||||
const hour = Number(match[1])
|
||||
const minute = Number(match[2])
|
||||
if (hour > 23 || minute > 59) return ''
|
||||
return `${String(hour).padStart(2, '0')}:${String(minute).padStart(2, '0')}`
|
||||
}
|
||||
const start = normalizeTime(calendar.businessStartTime || parts[0])
|
||||
const end = normalizeTime(calendar.businessEndTime || parts[1])
|
||||
if (!start || !end || dateUtil.minutesOfDay(end) <= dateUtil.minutesOfDay(start)) return null
|
||||
return { start, end }
|
||||
}
|
||||
|
||||
function layoutAppointmentBlocks(items, startMinute, minuteScale, laneHeaderHeight, defaultLaneWidth) {
|
||||
const entries = (items || [])
|
||||
.filter(item => item.startTime)
|
||||
@@ -124,13 +140,16 @@ Page({
|
||||
dateTitle: '',
|
||||
rangeText: '',
|
||||
weekRange: '',
|
||||
businessStartTime: '10:00',
|
||||
businessEndTime: '22:00',
|
||||
businessStartTime: '',
|
||||
businessEndTime: '',
|
||||
businessHoursConfigured: false,
|
||||
businessHoursText: '营业时间未设置',
|
||||
artists: [],
|
||||
monthDays: [],
|
||||
weekDays: [],
|
||||
dayLanes: [],
|
||||
hours: [],
|
||||
hasTimedAppointments: false,
|
||||
timelineHeight: 720,
|
||||
laneWidth: 720,
|
||||
laneItemWidth: 240,
|
||||
@@ -143,6 +162,7 @@ Page({
|
||||
rangeUnassignedCount: 0,
|
||||
nearestUnassignedDate: '',
|
||||
canCreateAppointment: true,
|
||||
canManageShopSettings: false,
|
||||
loading: false,
|
||||
calendarError: '',
|
||||
phoneBannerVisible: false,
|
||||
@@ -152,7 +172,11 @@ Page({
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.setData({ canCreateAppointment: canCreateAppointment() })
|
||||
const userInfo = getApp().globalData.userInfo || {}
|
||||
this.setData({
|
||||
canCreateAppointment: canCreateAppointment(),
|
||||
canManageShopSettings: Number(userInfo.type) === 2
|
||||
})
|
||||
this.loadCalendar()
|
||||
},
|
||||
|
||||
@@ -165,6 +189,10 @@ Page({
|
||||
wx.removeStorageSync('planningNeedRefresh')
|
||||
this.loadCalendar()
|
||||
}
|
||||
if (this._refreshCalendarOnShow) {
|
||||
this._refreshCalendarOnShow = false
|
||||
this.loadCalendar()
|
||||
}
|
||||
this.refreshAccountPrompts()
|
||||
},
|
||||
|
||||
@@ -302,6 +330,10 @@ Page({
|
||||
this.openBackfillOrder(appointmentDate)
|
||||
return
|
||||
}
|
||||
if (!this.data.businessHoursConfigured) {
|
||||
wx.showToast({ title: '请先在店铺设置中配置营业时间', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.openAppointmentForm(appointmentDate)
|
||||
},
|
||||
|
||||
@@ -376,13 +408,16 @@ Page({
|
||||
clearCalendarView() {
|
||||
this._calendarData = { artists: [], appointments: [], daySummaries: [] }
|
||||
this.setData({
|
||||
businessStartTime: '10:00',
|
||||
businessEndTime: '22:00',
|
||||
businessStartTime: '',
|
||||
businessEndTime: '',
|
||||
businessHoursConfigured: false,
|
||||
businessHoursText: '营业时间暂不可用',
|
||||
artists: [],
|
||||
monthDays: [],
|
||||
weekDays: [],
|
||||
dayLanes: [],
|
||||
hours: [],
|
||||
hasTimedAppointments: false,
|
||||
dayTotal: 0,
|
||||
freeArtistCount: 0,
|
||||
pendingCount: 0,
|
||||
@@ -410,9 +445,11 @@ Page({
|
||||
},
|
||||
|
||||
applyCalendar(calendar) {
|
||||
const businessHours = resolveBusinessHours(calendar)
|
||||
const snapshot = {
|
||||
businessStartTime: (calendar.businessStartTime || '10:00').slice(0, 5),
|
||||
businessEndTime: (calendar.businessEndTime || '22:00').slice(0, 5),
|
||||
businessStartTime: businessHours ? businessHours.start : '',
|
||||
businessEndTime: businessHours ? businessHours.end : '',
|
||||
businessHoursConfigured: Boolean(businessHours),
|
||||
artists: Array.isArray(calendar.artists) ? calendar.artists : [],
|
||||
appointments: Array.isArray(calendar.appointments) ? calendar.appointments : [],
|
||||
daySummaries: Array.isArray(calendar.daySummaries) ? calendar.daySummaries : []
|
||||
@@ -421,6 +458,10 @@ Page({
|
||||
this.setData({
|
||||
businessStartTime: snapshot.businessStartTime,
|
||||
businessEndTime: snapshot.businessEndTime,
|
||||
businessHoursConfigured: snapshot.businessHoursConfigured,
|
||||
businessHoursText: snapshot.businessHoursConfigured
|
||||
? `${snapshot.businessStartTime}-${snapshot.businessEndTime}`
|
||||
: '营业时间未设置',
|
||||
artists: snapshot.artists,
|
||||
calendarError: '',
|
||||
rangeUnassignedCount: snapshot.appointments.filter(item => !item.artistId).length,
|
||||
@@ -445,6 +486,7 @@ Page({
|
||||
dateTitle: title,
|
||||
rangeText: this.data.viewMode === 'month' ? '月视图' : this.data.viewMode === 'week' ? '周视图' : '日视图',
|
||||
weekRange: `${formatMonthDay(range.start)} - ${formatMonthDay(range.end)}`,
|
||||
businessHoursConfigured: Boolean(resolveBusinessHours(calendar)),
|
||||
monthDays: [],
|
||||
weekDays: [],
|
||||
dayLanes: [],
|
||||
@@ -521,8 +563,46 @@ Page({
|
||||
|
||||
buildDayView(calendar) {
|
||||
const minuteScale = 4
|
||||
const startMinute = dateUtil.minutesOfDay(calendar.businessStartTime || '10:00')
|
||||
const endMinute = dateUtil.minutesOfDay(calendar.businessEndTime || '22:00')
|
||||
const businessHours = resolveBusinessHours(calendar)
|
||||
const filteredArtists = this.data.selectedArtistId
|
||||
? (calendar.artists || []).filter(item => String(item.id) === String(this.data.selectedArtistId))
|
||||
: (calendar.artists || [])
|
||||
const dayAppointments = (calendar.appointments || []).filter(item => resolveAppointmentDate(item) === this.data.currentDateText)
|
||||
const historicalBackfillItems = dayAppointments.filter(item => item.historicalBackfill)
|
||||
const timedAppointments = dayAppointments
|
||||
.filter(item => item.startTime)
|
||||
.filter(item => !this.data.selectedArtistId || String(item.artistId) === String(this.data.selectedArtistId))
|
||||
const startMinutes = timedAppointments
|
||||
.map(resolveAppointmentStartMinute)
|
||||
.filter(value => Number.isFinite(value) && value >= 0 && value < 1440)
|
||||
if (!businessHours && !startMinutes.length) {
|
||||
const pendingCount = dayAppointments.filter(item => item.status === 0).length
|
||||
return {
|
||||
dayLanes: [],
|
||||
hours: [],
|
||||
hasTimedAppointments: false,
|
||||
timelineHeight: 0,
|
||||
laneHeaderHeight: 54,
|
||||
laneItemWidth: 248,
|
||||
laneWidth: 720,
|
||||
dayTotal: dayAppointments.length,
|
||||
freeArtistCount: 0,
|
||||
pendingCount,
|
||||
unassignedCount: dayAppointments.filter(item => !item.artistId).length,
|
||||
historicalBackfillItems
|
||||
}
|
||||
}
|
||||
const startMinute = businessHours
|
||||
? dateUtil.minutesOfDay(businessHours.start)
|
||||
: Math.floor(Math.min(...startMinutes) / 60) * 60
|
||||
const latestAppointmentEnd = timedAppointments.reduce((latest, item) => {
|
||||
const start = resolveAppointmentStartMinute(item)
|
||||
const duration = Number(item.durationMinutes || 60)
|
||||
return Math.max(latest, start + (Number.isFinite(duration) ? duration : 60))
|
||||
}, startMinute)
|
||||
const endMinute = businessHours
|
||||
? dateUtil.minutesOfDay(businessHours.end)
|
||||
: Math.min(1440, Math.max(startMinute + 60, Math.ceil(latestAppointmentEnd / 60) * 60))
|
||||
const timelineHeight = Math.max(560, (endMinute - startMinute) * minuteScale)
|
||||
const laneHeaderHeight = 54
|
||||
const hours = []
|
||||
@@ -533,11 +613,6 @@ Page({
|
||||
top: (cursor - startMinute) * minuteScale + laneHeaderHeight
|
||||
})
|
||||
}
|
||||
const filteredArtists = this.data.selectedArtistId
|
||||
? (calendar.artists || []).filter(item => String(item.id) === String(this.data.selectedArtistId))
|
||||
: (calendar.artists || [])
|
||||
const dayAppointments = (calendar.appointments || []).filter(item => resolveAppointmentDate(item) === this.data.currentDateText)
|
||||
const historicalBackfillItems = dayAppointments.filter(item => item.historicalBackfill)
|
||||
const employeeLanes = filteredArtists.map(artist => {
|
||||
const blocks = dayAppointments
|
||||
.filter(item => String(item.artistId) === String(artist.id))
|
||||
@@ -578,6 +653,7 @@ Page({
|
||||
return {
|
||||
dayLanes: lanes,
|
||||
hours,
|
||||
hasTimedAppointments: timedAppointments.length > 0,
|
||||
timelineHeight: timelineHeight + laneHeaderHeight,
|
||||
laneHeaderHeight,
|
||||
laneItemWidth: 248,
|
||||
@@ -683,6 +759,10 @@ Page({
|
||||
wx.showToast({ title: '当前账号仅支持查看预约', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!this.data.businessHoursConfigured) {
|
||||
wx.showToast({ title: '请先在店铺设置中配置营业时间', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.openAppointmentForm(this.data.currentDateText)
|
||||
},
|
||||
|
||||
@@ -706,6 +786,11 @@ Page({
|
||||
wx.navigateTo({ url: `/pages/appointment-form/index?${query.join('&')}` })
|
||||
},
|
||||
|
||||
openShopSettings() {
|
||||
this._refreshCalendarOnShow = true
|
||||
wx.navigateTo({ url: '/pages/shop-settings/index' })
|
||||
},
|
||||
|
||||
openAppointment(event) {
|
||||
wx.navigateTo({
|
||||
url: `/pages/appointment-detail/index?id=${event.currentTarget.dataset.id}`
|
||||
|
||||
Reference in New Issue
Block a user