修复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
+99 -14
View File
@@ -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}`
+31 -3
View File
@@ -109,6 +109,24 @@ async function run() {
const shortAppointmentLane = shortAppointmentState.dayLanes.find(lane => lane.artistId === 1)
assert.strictEqual(shortAppointmentLane.blocks[0].height, 60)
assert.strictEqual(shortAppointmentLane.blocks[0].compact, true)
const missingHoursPage = createPage({ viewMode: 'day', currentDateText: '2026-10-12' })
const missingHoursEmptyState = missingHoursPage.buildDayView({
artists: [{ id: 1, name: '美甲师', color: '#000' }],
appointments: []
})
assert.strictEqual(missingHoursEmptyState.hours.length, 0)
assert.strictEqual(missingHoursEmptyState.dayLanes.length, 0)
assert.strictEqual(missingHoursEmptyState.hasTimedAppointments, false)
missingHoursPage.clearCalendarView()
assert.strictEqual(missingHoursPage.data.businessHoursText, '营业时间暂不可用')
const missingHoursWithBookingState = missingHoursPage.buildDayView({
artists: [{ id: 1, name: '美甲师', color: '#000' }],
appointments: [{ orderItemId: 10, date: '2026-10-12', startTime: '2026-10-12 15:30:00', durationMinutes: 60, artistId: 1 }]
})
assert.strictEqual(missingHoursWithBookingState.hasTimedAppointments, true)
assert.strictEqual(missingHoursWithBookingState.hours[0].label, '15:00')
assert.strictEqual(missingHoursWithBookingState.hours[1].label, '16:00')
assert.strictEqual(missingHoursWithBookingState.dayLanes.find(lane => lane.artistId === 1).blocks.length, 1)
assert.match(planningWxml, /class="hour-line" style="top: \{\{hour\.top\}\}rpx;"/)
assert.match(planningWxml, /class="time-label" style="top: \{\{item\.top\}\}rpx;"/)
assert.match(planningWxss, /\.hour-line\s*\{[^}]*transform:\s*translateY\(-50%\);/)
@@ -136,6 +154,8 @@ async function run() {
})
})
assert.match(planningWxml, /class="lane-unassigned-tag">不占档期/)
assert.match(planningWxml, /门店营业时间未设置/)
assert.match(planningWxml, /bindtap="openShopSettings"/)
assert.match(planningWxml, /class="week-unassigned-count">待分配 \{\{item\.unassignedCount\}\}/)
assert.match(planningWxml, /class="month-unassigned-count">待 \{\{item\.unassignedCount\}\}/)
assert.doesNotMatch(planningWxss, /background-size:\s*100% 240rpx/)
@@ -172,7 +192,7 @@ async function run() {
global.wx.navigateTo = options => navigations.push(options.url)
global.wx.showToast = options => toasts.push(options.title)
const quickCreatePage = createPage({ canCreateAppointment: true, selectedArtistId: '88' })
const quickCreatePage = createPage({ canCreateAppointment: true, businessHoursConfigured: true, selectedArtistId: '88' })
const today = dateUtil.formatDate(new Date())
quickCreatePage.quickCreateAppointment({ currentTarget: { dataset: { date: today } } })
assert.strictEqual(navigations.pop(), `/pages/appointment-form/index?date=${today}&artistId=88`)
@@ -190,14 +210,22 @@ async function run() {
quickCreatePage.quickCreateAppointment({ currentTarget: { dataset: { date: '2000-01-01' } } })
assert.strictEqual(navigations.pop(), '/pages/backfill-order/index?serviceDate=2000-01-01')
const readonlyPage = createPage({ canCreateAppointment: false, selectedArtistId: '88' })
const readonlyPage = createPage({ canCreateAppointment: false, businessHoursConfigured: true, selectedArtistId: '88' })
readonlyPage.quickCreateAppointment({ currentTarget: { dataset: { date: '2099-12-31' } } })
assert.strictEqual(navigations.length, 0)
assert.strictEqual(toasts.pop(), '当前账号仅支持查看预约')
const fabPage = createPage({ canCreateAppointment: true, currentDateText: '2026-10-12', selectedArtistId: '99' })
const fabPage = createPage({ canCreateAppointment: true, businessHoursConfigured: true, currentDateText: '2026-10-12', selectedArtistId: '99' })
fabPage.createAppointment()
assert.strictEqual(navigations.pop(), '/pages/appointment-form/index?date=2026-10-12&artistId=99')
const unconfiguredPage = createPage({ canCreateAppointment: true, businessHoursConfigured: false })
unconfiguredPage.quickCreateAppointment({ currentTarget: { dataset: { date: '2099-12-31' } } })
assert.strictEqual(navigations.length, 0)
assert.strictEqual(toasts.pop(), '请先在店铺设置中配置营业时间')
unconfiguredPage.openShopSettings()
assert.strictEqual(navigations.pop(), '/pages/shop-settings/index')
assert.strictEqual(unconfiguredPage._refreshCalendarOnShow, true)
}
run().catch(error => {
+12 -3
View File
@@ -10,7 +10,7 @@
</view>
<view class="date-center">
<text class="date-main">{{dateTitle}}</text>
<text class="date-sub">{{businessStartTime}}-{{businessEndTime}}</text>
<text class="date-sub">{{businessHoursText}}</text>
</view>
<view class="date-side date-tools">
<button class="today-btn" bindtap="goToday">今</button>
@@ -35,6 +35,11 @@
</view>
</view>
<view wx:if="{{!businessHoursConfigured && !calendarError}}" class="business-hours-notice">
<view class="business-hours-notice-copy"><text class="business-hours-notice-title">门店营业时间未设置</text><text class="business-hours-notice-desc">设置后才能安排普通预约,历史订单与补录不受影响。</text></view>
<button wx:if="{{canManageShopSettings}}" class="business-hours-action" bindtap="openShopSettings">去设置</button>
</view>
<view wx:if="{{profilePromptVisible}}" class="profile-prompt-mask">
<view class="profile-prompt">
<text class="profile-prompt-title">完善你的工作名片</text><text class="profile-prompt-desc">头像和昵称会用于门店协作展示,可暂时跳过。</text>
@@ -83,7 +88,11 @@
</view>
</view>
<scroll-view class="day-board card" scroll-y>
<view wx:if="{{!businessHoursConfigured && !hasTimedAppointments}}" class="day-board card business-hours-empty">
<text class="business-hours-empty-title">预约时间轴暂不可用</text>
<text class="business-hours-empty-desc">请先设置门店营业时间,再安排普通预约。</text>
</view>
<scroll-view wx:else class="day-board card" scroll-y>
<view class="timeline-wrap" style="height: {{timelineHeight}}rpx;">
<view class="time-axis">
<view wx:for="{{hours}}" wx:key="value" class="time-label" style="top: {{item.top}}rpx;">{{item.label}}</view>
@@ -197,5 +206,5 @@
</view>
</block>
<button wx:if="{{canCreateAppointment && !calendarError}}" class="fab" bindtap="createAppointment">+</button>
<button wx:if="{{canCreateAppointment && businessHoursConfigured && !calendarError}}" class="fab" bindtap="createAppointment">+</button>
</view>
+68
View File
@@ -171,6 +171,74 @@
font-size: 20rpx;
}
.business-hours-notice {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18rpx;
margin-top: 16rpx;
padding: 16rpx 18rpx;
border-left: 6rpx solid #d2a34e;
border-radius: 10rpx;
background: #fff9ea;
}
.business-hours-notice-copy {
display: flex;
min-width: 0;
flex-direction: column;
gap: 4rpx;
}
.business-hours-notice-title {
color: #775a25;
font-size: 23rpx;
font-weight: 800;
}
.business-hours-notice-desc {
color: #8a7751;
font-size: 20rpx;
line-height: 1.4;
}
.business-hours-action {
flex: 0 0 auto;
height: 54rpx;
margin: 0;
padding: 0 18rpx;
border-radius: 999rpx;
background: #247b63;
color: #fff;
font-size: 21rpx;
font-weight: 700;
line-height: 54rpx;
}
.business-hours-empty {
display: flex;
min-height: 240rpx;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 10rpx;
box-sizing: border-box;
padding: 36rpx 24rpx;
text-align: center;
}
.business-hours-empty-title {
color: #26342d;
font-size: 25rpx;
font-weight: 800;
}
.business-hours-empty-desc {
color: #71807a;
font-size: 21rpx;
line-height: 1.5;
}
.segmented {
display: grid;
grid-template-columns: repeat(3, 1fr);