修复Salon注册预约客户流程
This commit is contained in:
@@ -26,6 +26,11 @@ function canCreateAppointment() {
|
||||
return Number(userInfo.type) !== 3
|
||||
}
|
||||
|
||||
function isShopManager() {
|
||||
const userInfo = getApp().globalData.userInfo || {}
|
||||
return Number(userInfo.type) === 2
|
||||
}
|
||||
|
||||
function isShopBusinessExpired() {
|
||||
const userInfo = getApp().globalData.userInfo || {}
|
||||
return Number(userInfo.type) === 2 && userInfo.shopBusinessExpired === true
|
||||
@@ -205,6 +210,22 @@ function hasBusyConflict(startMinute, endMinute, ranges) {
|
||||
return ranges.some(range => startMinute < range.endMinute && endMinute > range.startMinute)
|
||||
}
|
||||
|
||||
function resolveBusinessHours(calendar) {
|
||||
const source = calendar || {}
|
||||
const parts = String(source.businessHours || '').split('-')
|
||||
const start = String(source.businessStartTime || parts[0] || '').trim()
|
||||
const end = String(source.businessEndTime || parts[1] || '').trim()
|
||||
const valid = value => {
|
||||
if (!/^\d{1,2}:[0-5]\d$/.test(value)) return false
|
||||
const hour = Number(value.split(':')[0])
|
||||
return hour >= 0 && hour <= 23
|
||||
}
|
||||
if (!valid(start) || !valid(end) || dateUtil.minutesOfDay(end) <= dateUtil.minutesOfDay(start)) {
|
||||
return { start: '', end: '' }
|
||||
}
|
||||
return { start, end }
|
||||
}
|
||||
|
||||
function buildAvailableTimeGroups(calendar, form, durationMinutes) {
|
||||
const schedules = (calendar.schedules || [])
|
||||
.filter(item => String(item.artistId) === String(form.artistId))
|
||||
@@ -214,8 +235,10 @@ function buildAvailableTimeGroups(calendar, form, durationMinutes) {
|
||||
const today = dateUtil.formatDate(new Date())
|
||||
const now = new Date()
|
||||
const currentMinute = now.getHours() * 60 + now.getMinutes()
|
||||
const businessStart = dateUtil.minutesOfDay(calendar.businessStartTime || '10:00')
|
||||
const businessEnd = dateUtil.minutesOfDay(calendar.businessEndTime || '22:00')
|
||||
const businessHours = resolveBusinessHours(calendar)
|
||||
if (!businessHours.start) return []
|
||||
const businessStart = dateUtil.minutesOfDay(businessHours.start)
|
||||
const businessEnd = dateUtil.minutesOfDay(businessHours.end)
|
||||
const groupMap = {
|
||||
morning: { key: 'morning', title: '上午', times: [] },
|
||||
afternoon: { key: 'afternoon', title: '下午', times: [] },
|
||||
@@ -245,14 +268,16 @@ function buildAvailableTimeGroups(calendar, form, durationMinutes) {
|
||||
.filter(group => group.times.length > 0)
|
||||
}
|
||||
|
||||
function buildUnassignedTimeGroups(durationMinutes, businessStart = '10:00', businessEnd = '22:00', appointmentDate) {
|
||||
function buildUnassignedTimeGroups(durationMinutes, businessStart, businessEnd, appointmentDate) {
|
||||
const groupMap = {
|
||||
morning: { key: 'morning', title: '上午', times: [] },
|
||||
afternoon: { key: 'afternoon', title: '下午', times: [] },
|
||||
evening: { key: 'evening', title: '晚上', times: [] }
|
||||
}
|
||||
if (!businessStart || !businessEnd) return []
|
||||
const start = dateUtil.minutesOfDay(businessStart)
|
||||
const end = dateUtil.minutesOfDay(businessEnd)
|
||||
if (end <= start) return []
|
||||
const now = new Date()
|
||||
const today = dateUtil.formatDate(now)
|
||||
const currentMinute = now.getHours() * 60 + now.getMinutes()
|
||||
@@ -273,10 +298,12 @@ function flattenTimeGroups(groups) {
|
||||
return (groups || []).reduce((list, group) => list.concat(group.times || []), [])
|
||||
}
|
||||
|
||||
function buildTimeValues(durationMinutes, businessStart = '10:00', businessEnd = '22:00', appointmentDate) {
|
||||
function buildTimeValues(durationMinutes, businessStart, businessEnd, appointmentDate) {
|
||||
const values = []
|
||||
if (!businessStart || !businessEnd) return values
|
||||
const open = dateUtil.minutesOfDay(businessStart)
|
||||
const close = dateUtil.minutesOfDay(businessEnd)
|
||||
if (close <= open) return values
|
||||
const now = new Date()
|
||||
const today = dateUtil.formatDate(now)
|
||||
const currentMinute = now.getHours() * 60 + now.getMinutes()
|
||||
@@ -290,9 +317,10 @@ function buildTimeValues(durationMinutes, businessStart = '10:00', businessEnd =
|
||||
function buildTimePickerSlots(calendar, form, durationMinutes) {
|
||||
const schedules = calendar.schedules || []
|
||||
const busyRanges = form.artistId ? buildBusyRanges(calendar.appointments || [], form) : []
|
||||
const businessHours = String(calendar.businessHours || '10:00-22:00').split('-')
|
||||
const businessStart = calendar.businessStartTime || businessHours[0] || '10:00'
|
||||
const businessEnd = calendar.businessEndTime || businessHours[1] || '22:00'
|
||||
const businessHours = resolveBusinessHours(calendar)
|
||||
if (!businessHours.start) return []
|
||||
const businessStart = businessHours.start
|
||||
const businessEnd = businessHours.end
|
||||
return buildTimeValues(durationMinutes, businessStart, businessEnd, form.appointmentDate).map(time => {
|
||||
const value = time.value
|
||||
const startMinute = dateUtil.minutesOfDay(value)
|
||||
@@ -513,8 +541,8 @@ Page({
|
||||
unifiedStyleDescription: '',
|
||||
customerOptions: [],
|
||||
customerDirectory: [],
|
||||
businessStartTime: '10:00',
|
||||
businessEndTime: '22:00',
|
||||
businessStartTime: '',
|
||||
businessEndTime: '',
|
||||
defaultAppointmentDurationMinutes: 60,
|
||||
durationManuallyChanged: false,
|
||||
customerSheetVisible: false,
|
||||
@@ -544,6 +572,7 @@ Page({
|
||||
conflictTip: '',
|
||||
conflictLevel: 'free',
|
||||
canCreateAppointment: true,
|
||||
canManageShopSettings: false,
|
||||
draftSavedAtText: '',
|
||||
manualImageUploading: false,
|
||||
timeSheetVisible: false,
|
||||
@@ -557,6 +586,7 @@ Page({
|
||||
selectedTimeCandidate: '',
|
||||
timeLoading: false,
|
||||
timeError: '',
|
||||
businessHoursMissing: false,
|
||||
timeSelectTip: '请先选择美甲师并填写时长',
|
||||
appointmentDayLabel: '',
|
||||
appointmentDateBadge: '',
|
||||
@@ -580,6 +610,7 @@ Page({
|
||||
const dateLabels = buildAppointmentDateLabels(appointmentDate)
|
||||
this.setData({
|
||||
canCreateAppointment: creatable,
|
||||
canManageShopSettings: isShopManager(),
|
||||
form: {
|
||||
...this.data.form,
|
||||
...baseForm,
|
||||
@@ -606,6 +637,21 @@ Page({
|
||||
this.loadOptions()
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (!this._refreshTimesAfterSettings) return
|
||||
this._refreshTimesAfterSettings = false
|
||||
this.refreshAvailableTimes()
|
||||
},
|
||||
|
||||
openShopSettings() {
|
||||
if (!this.data.canManageShopSettings) {
|
||||
wx.showToast({ title: '请联系店长设置门店营业时间', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this._refreshTimesAfterSettings = true
|
||||
wx.navigateTo({ url: '/pages/shop-settings/index' })
|
||||
},
|
||||
|
||||
async loadOptions() {
|
||||
this.setData({ loadingProducts: true })
|
||||
try {
|
||||
@@ -650,7 +696,7 @@ Page({
|
||||
endDate: this.data.form.appointmentDate
|
||||
})
|
||||
let artists = getCalendarArtists(calendar)
|
||||
const hours = String(calendar.businessHours || '10:00-22:00').split('-')
|
||||
const businessHours = resolveBusinessHours(calendar)
|
||||
const defaultDuration = Number(calendar.defaultAppointmentDurationMinutes) || 60
|
||||
const requestedId = preferredArtistId || this.data.form.artistId
|
||||
if (fallbackEmployee && requestedId && !findArtist(artists, requestedId).id) {
|
||||
@@ -664,8 +710,8 @@ Page({
|
||||
? findArtist(artists, requestedId)
|
||||
: unassignedSelection
|
||||
this.setData({
|
||||
businessStartTime: calendar.businessStartTime || hours[0] || '10:00',
|
||||
businessEndTime: calendar.businessEndTime || hours[1] || '22:00',
|
||||
businessStartTime: businessHours.start,
|
||||
businessEndTime: businessHours.end,
|
||||
defaultAppointmentDurationMinutes: defaultDuration,
|
||||
...(!this.data.durationManuallyChanged && !this.data.form.productId && !this.data.form.appointmentTime
|
||||
? { 'form.durationMinutes': String(defaultDuration) }
|
||||
@@ -681,6 +727,8 @@ Page({
|
||||
this.setData({
|
||||
artists: [],
|
||||
artistSelectorItems: this.filterArtistItems([], this.data.artistKeyword),
|
||||
businessStartTime: '',
|
||||
businessEndTime: '',
|
||||
selectedArtist: unassignedSelection,
|
||||
'form.artistId': '',
|
||||
artistError: error.message || '美甲师列表加载失败',
|
||||
@@ -1253,6 +1301,7 @@ Page({
|
||||
selectedTimeCandidate: '',
|
||||
timePickerCandidateStatus: 'off-shift',
|
||||
timeError: '',
|
||||
businessHoursMissing: false,
|
||||
timeSelectTip: '请先填写预约日期和时长'
|
||||
}
|
||||
if (form.appointmentTime) {
|
||||
@@ -1266,9 +1315,27 @@ Page({
|
||||
try {
|
||||
const calendar = await planningApi.calendar({ startDate: form.appointmentDate, endDate: form.appointmentDate })
|
||||
if (requestSeq !== this._availableTimeRequestSeq) return
|
||||
const hours = String(calendar.businessHours || `${this.data.businessStartTime}-${this.data.businessEndTime}`).split('-')
|
||||
const businessStartTime = calendar.businessStartTime || hours[0] || '10:00'
|
||||
const businessEndTime = calendar.businessEndTime || hours[1] || '22:00'
|
||||
const businessHours = resolveBusinessHours(calendar)
|
||||
const businessStartTime = businessHours.start
|
||||
const businessEndTime = businessHours.end
|
||||
if (!businessStartTime) {
|
||||
this.setData({
|
||||
businessStartTime: '',
|
||||
businessEndTime: '',
|
||||
availableTimeGroups: [],
|
||||
timePickerSlots: [],
|
||||
timePickerGroups: [],
|
||||
timePickerHours: [],
|
||||
timePickerMinutes: [],
|
||||
selectedTimeCandidate: '',
|
||||
'form.appointmentTime': '',
|
||||
timeError: '门店营业时间尚未设置,请先完成设置',
|
||||
businessHoursMissing: true,
|
||||
timeLoading: false,
|
||||
timeSelectTip: '请先设置门店营业时间'
|
||||
})
|
||||
return
|
||||
}
|
||||
this.setData({ businessStartTime, businessEndTime })
|
||||
const availableTimeGroups = buildUnassignedTimeGroups(durationMinutes, businessStartTime, businessEndTime, form.appointmentDate)
|
||||
const timePickerSlots = buildTimePickerSlots(calendar, form, durationMinutes)
|
||||
@@ -1278,12 +1345,27 @@ Page({
|
||||
timePickerGroups: buildTimePickerGroups(timePickerSlots),
|
||||
...buildTimeWheelState(timePickerSlots, form.appointmentTime),
|
||||
timeError: '',
|
||||
businessHoursMissing: false,
|
||||
timeLoading: false,
|
||||
timeSelectTip: availableTimeGroups.length ? '请选择预约时间,美甲师可稍后分配' : '当前日期没有可选时段'
|
||||
})
|
||||
} catch (error) {
|
||||
if (requestSeq === this._availableTimeRequestSeq) {
|
||||
this.setData({ availableTimeGroups: [], timePickerSlots: [], timePickerGroups: [], timeError: error.message || '营业时间加载失败', timeLoading: false, timeSelectTip: '营业时间加载失败' })
|
||||
this.setData({
|
||||
businessStartTime: '',
|
||||
businessEndTime: '',
|
||||
availableTimeGroups: [],
|
||||
timePickerSlots: [],
|
||||
timePickerGroups: [],
|
||||
timePickerHours: [],
|
||||
timePickerMinutes: [],
|
||||
selectedTimeCandidate: '',
|
||||
'form.appointmentTime': '',
|
||||
timeError: error.message || '营业时间加载失败',
|
||||
businessHoursMissing: false,
|
||||
timeLoading: false,
|
||||
timeSelectTip: '营业时间加载失败'
|
||||
})
|
||||
}
|
||||
}
|
||||
return
|
||||
@@ -1291,6 +1373,7 @@ Page({
|
||||
this.setData({
|
||||
timeLoading: true,
|
||||
timeError: '',
|
||||
businessHoursMissing: false,
|
||||
timeSelectTip: '正在计算可约时间...'
|
||||
})
|
||||
try {
|
||||
@@ -1302,6 +1385,25 @@ Page({
|
||||
if (requestSeq !== this._availableTimeRequestSeq) {
|
||||
return
|
||||
}
|
||||
const businessHours = resolveBusinessHours(calendar)
|
||||
if (!businessHours.start) {
|
||||
this.setData({
|
||||
businessStartTime: '',
|
||||
businessEndTime: '',
|
||||
availableTimeGroups: [],
|
||||
timePickerSlots: [],
|
||||
timePickerGroups: [],
|
||||
timePickerHours: [],
|
||||
timePickerMinutes: [],
|
||||
selectedTimeCandidate: '',
|
||||
'form.appointmentTime': '',
|
||||
timeError: '门店营业时间尚未设置,请先完成设置',
|
||||
businessHoursMissing: true,
|
||||
timeLoading: false,
|
||||
timeSelectTip: '请先设置门店营业时间'
|
||||
})
|
||||
return
|
||||
}
|
||||
const availableTimeGroups = buildAvailableTimeGroups(calendar, form, durationMinutes)
|
||||
const availableTimes = flattenTimeGroups(availableTimeGroups).map(item => item.value)
|
||||
const timePickerSlots = buildTimePickerSlots(calendar, form, durationMinutes)
|
||||
@@ -1310,6 +1412,8 @@ Page({
|
||||
timePickerSlots,
|
||||
timePickerGroups: buildTimePickerGroups(timePickerSlots),
|
||||
...buildTimeWheelState(timePickerSlots, form.appointmentTime),
|
||||
timeError: '',
|
||||
businessHoursMissing: false,
|
||||
timeSelectTip: availableTimes.length > 0 ? '请选择预约时间' : '当前美甲师当天暂无可约时间'
|
||||
}
|
||||
if (form.appointmentTime && !availableTimes.includes(form.appointmentTime)) {
|
||||
@@ -1321,8 +1425,17 @@ Page({
|
||||
return
|
||||
}
|
||||
this.setData({
|
||||
businessStartTime: '',
|
||||
businessEndTime: '',
|
||||
availableTimeGroups: [],
|
||||
timePickerSlots: [],
|
||||
timePickerGroups: [],
|
||||
timePickerHours: [],
|
||||
timePickerMinutes: [],
|
||||
selectedTimeCandidate: '',
|
||||
'form.appointmentTime': '',
|
||||
timeError: error.message || '可约时间加载失败',
|
||||
businessHoursMissing: false,
|
||||
timeSelectTip: '可约时间加载失败'
|
||||
})
|
||||
} finally {
|
||||
@@ -1436,6 +1549,13 @@ Page({
|
||||
}
|
||||
const startMinute = dateUtil.minutesOfDay(appointmentTime)
|
||||
const endMinute = startMinute + durationMinutes
|
||||
if (!this.data.businessStartTime || !this.data.businessEndTime) {
|
||||
const tip = this.data.businessHoursMissing
|
||||
? '门店营业时间尚未设置,请先完成设置'
|
||||
: '营业时间暂不可用,请稍后重试'
|
||||
this.setData({ conflictTip: tip, conflictLevel: 'danger' })
|
||||
return { ok: false, tip }
|
||||
}
|
||||
if (startMinute < dateUtil.minutesOfDay(this.data.businessStartTime) || endMinute > dateUtil.minutesOfDay(this.data.businessEndTime)) {
|
||||
const tip = `该时间超出营业时间 ${this.data.businessStartTime}-${this.data.businessEndTime}`
|
||||
this.setData({ conflictTip: tip, conflictLevel: 'danger' })
|
||||
|
||||
Reference in New Issue
Block a user