修复Salon注册预约客户流程

This commit is contained in:
2026-10-30 15:13:38 +08:00
parent 53b6fcaa11
commit 7b9a5e4d1c
20 changed files with 748 additions and 67 deletions
+136 -16
View File
@@ -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' })
@@ -138,7 +138,7 @@
<view class="modal-head"><view><text class="modal-title">选择预约时间</text><text class="modal-subtitle">{{form.appointmentDate}} · {{selectedArtist.name || '待分配'}} · {{form.durationMinutes}}分钟</text></view><view class="modal-close" bindtap="closeTimeSheet" aria-label="关闭时间选择"></view></view>
<view class="time-mode-switch"><button class="{{timePickerMode === 'wheel' ? 'active' : ''}}" data-mode="wheel" bindtap="onTimePickerModeChange">滚轮选择</button><button class="{{timePickerMode === 'grid' ? 'active' : ''}}" data-mode="grid" bindtap="onTimePickerModeChange">15分钟时段</button></view>
<view wx:if="{{timeLoading}}" class="time-empty">正在计算可约时间...</view>
<view wx:elif="{{timeError}}" class="time-empty">{{timeError}}</view>
<view wx:elif="{{timeError}}" class="time-empty"><text>{{businessHoursMissing && !canManageShopSettings ? '门店营业时间尚未设置,请联系店长完成设置' : timeError}}</text><button wx:if="{{businessHoursMissing && canManageShopSettings}}" class="time-empty-action" bindtap="openShopSettings">前往店铺设置</button></view>
<block wx:elif="{{timePickerMode === 'wheel'}}">
<picker-view class="time-wheel" indicator-style="height: 76rpx;" value="{{timePickerValue}}" bindchange="onTimePickerChange"><picker-view-column><view wx:for="{{timePickerHours}}" wx:key="value" class="wheel-item {{item.disabled ? 'disabled' : ''}}">{{item.label}}</view></picker-view-column><picker-view-column><view wx:for="{{timePickerMinutes}}" wx:key="value" class="wheel-item {{item.disabled ? 'disabled' : ''}}">{{item.label}}</view></picker-view-column></picker-view>
<view class="time-wheel-caption">{{selectedTimeCandidate || '请选择时间'}}<text wx:if="{{timePickerCandidateStatus === 'occupied'}}"> · 已被占用</text><text wx:elif="{{timePickerCandidateStatus === 'past'}}"> · 已过时</text><text wx:elif="{{timePickerCandidateStatus === 'off-shift'}}"> · 当前无排班</text></view>
@@ -418,6 +418,7 @@
.time-empty {
min-height: 220rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 40rpx 20rpx;
@@ -428,6 +429,19 @@
text-align: center;
}
.time-empty-action {
flex: 0 0 auto;
height: 62rpx;
margin: 14rpx 0 0;
padding: 0 24rpx;
border-radius: 999rpx;
background: #247b63;
color: #fff;
font-size: 22rpx;
font-weight: 700;
line-height: 62rpx;
}
.action-row {
display: flex;
gap: 16rpx;
@@ -13,6 +13,7 @@ global.wx = {
setStorageSync: () => {},
showToast: () => {},
showModal: options => { lastModal = options; if (options.success) options.success({ confirm: true }) },
navigateTo: () => {},
redirectTo: ({ url }) => { redirectedTo = url }
}
global.getApp = () => ({ globalData: appGlobalData })
@@ -79,6 +80,38 @@ async function run() {
assert.strictEqual(availability.ok, true)
assert.strictEqual(page.data.conflictTip.includes('待分配'), true)
appGlobalData.userInfo = { type: 2 }
const managerRolePage = createPage()
managerRolePage.loadOptions = () => {}
managerRolePage.onLoad({ date: futureDate })
assert.strictEqual(managerRolePage.data.canManageShopSettings, true)
appGlobalData.userInfo = { type: 3 }
const staffRolePage = createPage()
staffRolePage.loadOptions = () => {}
staffRolePage.onLoad({ date: futureDate })
assert.strictEqual(staffRolePage.data.canManageShopSettings, false)
appGlobalData = {}
planningApi.calendar = async () => ({ artists: [], schedules: [], appointments: [] })
const missingHoursPage = createPage()
Object.assign(missingHoursPage.data.form, {
appointmentDate: futureDate,
durationMinutes: '60',
artistId: ''
})
await missingHoursPage.refreshAvailableTimes()
assert.strictEqual(missingHoursPage.data.timePickerSlots.length, 0)
assert.strictEqual(missingHoursPage.data.timeError, '门店营业时间尚未设置,请先完成设置')
assert.strictEqual(missingHoursPage.data.businessHoursMissing, true)
missingHoursPage.data.canManageShopSettings = true
missingHoursPage.openShopSettings()
assert.strictEqual(missingHoursPage._refreshTimesAfterSettings, true)
const staffMissingHoursPage = createPage()
staffMissingHoursPage.data.businessHoursMissing = true
staffMissingHoursPage.openShopSettings()
assert.strictEqual(staffMissingHoursPage._refreshTimesAfterSettings, undefined)
assert.match(appointmentWxml, /businessHoursMissing && canManageShopSettings\}\}.*前往店铺设置/)
const unassignedPage = createPage()
Object.assign(unassignedPage.data.form, { appointmentTime: '14:00' })
unassignedPage.data.artists = [{ id: 2, name: '小李' }]
@@ -124,6 +157,8 @@ async function run() {
assert.strictEqual(redirectedTo, '/pages/appointment-detail/index?id=61')
const walkInPage = createPage()
walkInPage.data.businessStartTime = '09:30'
walkInPage.data.businessEndTime = '18:00'
Object.assign(walkInPage.data.form, {
productId: '41',
appointmentDate: futureDate,