修复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' })
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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}`
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -10,6 +10,22 @@ function resolveNameStatus(value) {
|
||||
return '尚未提交审核'
|
||||
}
|
||||
|
||||
function resolveBusinessHours(value) {
|
||||
const parts = String(value || '').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(parts[0])
|
||||
const end = normalizeTime(parts[1])
|
||||
if (!start || !end || start >= end) return null
|
||||
return { start, end }
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
profile: {},
|
||||
@@ -18,9 +34,10 @@ Page({
|
||||
nameModerationText: '尚未提交审核',
|
||||
settingsLoading: false,
|
||||
settingsSaving: false,
|
||||
businessHoursConfigured: false,
|
||||
nameSaving: false,
|
||||
settingsError: '',
|
||||
form: { shopName: BRAND_CONFIG.defaultShopName, pendingShopName: '', startTime: '10:00', endTime: '22:00', defaultDuration: 60 }
|
||||
form: { shopName: BRAND_CONFIG.defaultShopName, pendingShopName: '', startTime: '', endTime: '', defaultDuration: 60 }
|
||||
},
|
||||
|
||||
onShow() { this.loadProfileAndSettings() },
|
||||
@@ -40,9 +57,10 @@ Page({
|
||||
: hasRemainingDays
|
||||
? `剩余 ${remainingDays} 天`
|
||||
: '有效期未设置'
|
||||
const [startTime, endTime] = String(settings.businessHours || '10:00-22:00').split('-')
|
||||
const businessHours = resolveBusinessHours(settings.businessHours)
|
||||
this.setData({
|
||||
profile,
|
||||
businessHoursConfigured: Boolean(businessHours),
|
||||
businessExpireDateText,
|
||||
businessExpiryStatusText,
|
||||
nameModerationText: resolveNameStatus(settings.shopNameModerationStatus),
|
||||
@@ -50,13 +68,18 @@ Page({
|
||||
...this.data.form,
|
||||
shopName: settings.pendingShopName || settings.shopName || profile.shopName || BRAND_CONFIG.defaultShopName,
|
||||
pendingShopName: settings.pendingShopName || '',
|
||||
startTime: startTime || '10:00',
|
||||
endTime: endTime || '22:00',
|
||||
startTime: businessHours ? businessHours.start : '',
|
||||
endTime: businessHours ? businessHours.end : '',
|
||||
defaultDuration: Number(settings.defaultAppointmentDurationMinutes) || 60
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
this.setData({ settingsError: error.message || '设置加载失败' })
|
||||
this.setData({
|
||||
settingsError: error.message || '设置加载失败',
|
||||
businessHoursConfigured: false,
|
||||
'form.startTime': '',
|
||||
'form.endTime': ''
|
||||
})
|
||||
} finally {
|
||||
this.setData({ settingsLoading: false })
|
||||
}
|
||||
@@ -69,8 +92,9 @@ Page({
|
||||
async saveAppointmentSettings() {
|
||||
const { startTime, endTime, defaultDuration } = this.data.form
|
||||
const duration = Number(defaultDuration)
|
||||
if (startTime >= endTime) {
|
||||
wx.showToast({ title: '营业结束时间必须晚于开始时间', icon: 'none' })
|
||||
const businessHours = resolveBusinessHours(`${startTime}-${endTime}`)
|
||||
if (!businessHours) {
|
||||
wx.showToast({ title: '请设置完整有效的营业时间', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!Number.isInteger(duration) || duration < 15 || duration > 720) {
|
||||
@@ -79,7 +103,8 @@ Page({
|
||||
}
|
||||
this.setData({ settingsSaving: true })
|
||||
try {
|
||||
await shopApi.saveAppointmentSettings({ businessHours: `${startTime}-${endTime}`, defaultAppointmentDurationMinutes: duration })
|
||||
await shopApi.saveAppointmentSettings({ businessHours: `${businessHours.start}-${businessHours.end}`, defaultAppointmentDurationMinutes: duration })
|
||||
this.setData({ businessHoursConfigured: true })
|
||||
wx.showToast({ title: '预约设置已生效', icon: 'success' })
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '保存失败,请重试', icon: 'none' })
|
||||
|
||||
@@ -4,20 +4,18 @@ const path = require('path')
|
||||
|
||||
let pageDefinition
|
||||
let currentProfile
|
||||
let currentSettings
|
||||
let savedSettings
|
||||
let toastTitle
|
||||
|
||||
global.Page = definition => { pageDefinition = definition }
|
||||
global.wx = { showToast: () => {} }
|
||||
global.wx = { showToast: options => { toastTitle = options.title } }
|
||||
|
||||
const profileCache = require('../../utils/profile-cache')
|
||||
profileCache.getProfile = async () => currentProfile
|
||||
const shopApi = require('../../api/shop')
|
||||
shopApi.appointmentSettings = async () => ({
|
||||
shopName: '薄荷美甲',
|
||||
businessHours: '09:30-21:30',
|
||||
defaultAppointmentDurationMinutes: 75,
|
||||
shopNameModerationStatus: 'PENDING',
|
||||
pendingShopName: '薄荷指尖'
|
||||
})
|
||||
shopApi.appointmentSettings = async () => ({ ...currentSettings })
|
||||
shopApi.saveAppointmentSettings = async settings => { savedSettings = settings }
|
||||
require('./index')
|
||||
|
||||
async function loadProfile(profile) {
|
||||
@@ -37,6 +35,13 @@ async function loadProfile(profile) {
|
||||
}
|
||||
|
||||
async function run() {
|
||||
currentSettings = {
|
||||
shopName: '薄荷美甲',
|
||||
businessHours: '09:30-21:30',
|
||||
defaultAppointmentDurationMinutes: 75,
|
||||
shopNameModerationStatus: 'PENDING',
|
||||
pendingShopName: '薄荷指尖'
|
||||
}
|
||||
const empty = await loadProfile({
|
||||
type: 2,
|
||||
shopBusinessExpireTime: null,
|
||||
@@ -64,17 +69,51 @@ async function run() {
|
||||
assert.strictEqual(expired.businessExpiryStatusText, '已过期,暂不能新增预约')
|
||||
assert.strictEqual(expired.form.startTime, '09:30')
|
||||
assert.strictEqual(expired.form.endTime, '21:30')
|
||||
assert.strictEqual(expired.businessHoursConfigured, true)
|
||||
assert.strictEqual(expired.form.defaultDuration, 75)
|
||||
assert.strictEqual(expired.nameModerationText, '名称审核中')
|
||||
assert.strictEqual(expired.form.pendingShopName, '薄荷指尖')
|
||||
|
||||
const shopSettingsWxml = fs.readFileSync(path.join(__dirname, 'index.wxml'), 'utf8')
|
||||
const accountSettingsWxml = fs.readFileSync(path.join(__dirname, '../account-settings/index.wxml'), 'utf8')
|
||||
assert(shopSettingsWxml.includes('预约运营设置'))
|
||||
assert(shopSettingsWxml.includes('营业时间'))
|
||||
assert(shopSettingsWxml.includes('默认预约时长'))
|
||||
assert(shopSettingsWxml.includes('catchtap="explainDefaultDuration"'))
|
||||
assert(shopSettingsWxml.includes('wx:if="{{profile.type == 2}}" class="card business-expiry-card"'))
|
||||
assert(!accountSettingsWxml.includes('business-expiry-card'))
|
||||
assert(!shopSettingsWxml.includes('预约规则'))
|
||||
assert(shopSettingsWxml.includes('提交名称审核'))
|
||||
assert(shopSettingsWxml.includes('保存预约设置'))
|
||||
assert(shopSettingsWxml.includes('设置开始时间'))
|
||||
assert(shopSettingsWxml.includes('营业时间尚未设置'))
|
||||
|
||||
currentSettings = { shopName: '新门店', businessHours: null, defaultAppointmentDurationMinutes: 60 }
|
||||
const unconfigured = await loadProfile({ type: 2 })
|
||||
assert.strictEqual(unconfigured.form.startTime, '')
|
||||
assert.strictEqual(unconfigured.form.endTime, '')
|
||||
assert.strictEqual(unconfigured.businessHoursConfigured, false)
|
||||
|
||||
const savePage = {
|
||||
data: { ...pageDefinition.data, businessHoursConfigured: false, form: { ...pageDefinition.data.form, startTime: '', endTime: '' } },
|
||||
setData(values) {
|
||||
Object.entries(values).forEach(([key, value]) => {
|
||||
const parts = key.split('.')
|
||||
if (parts.length === 1) this.data[key] = value
|
||||
else this.data[parts[0]] = { ...this.data[parts[0]], [parts[1]]: value }
|
||||
})
|
||||
}
|
||||
}
|
||||
savedSettings = undefined
|
||||
await pageDefinition.saveAppointmentSettings.call(savePage)
|
||||
assert.strictEqual(savedSettings, undefined)
|
||||
assert.strictEqual(toastTitle, '请设置完整有效的营业时间')
|
||||
|
||||
savePage.data.form.startTime = '09:00'
|
||||
savePage.data.form.endTime = '21:30'
|
||||
await pageDefinition.saveAppointmentSettings.call(savePage)
|
||||
assert.deepStrictEqual(savedSettings, { businessHours: '09:00-21:30', defaultAppointmentDurationMinutes: 60 })
|
||||
assert.strictEqual(savePage.data.businessHoursConfigured, true)
|
||||
}
|
||||
|
||||
run().catch(error => {
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
|
||||
<view class="settings-divider"></view>
|
||||
<view class="settings-section-head"><view><text class="section-title">预约运营设置</text><text class="settings-section-note">保存后立即生效,不需要门店资料审核</text></view></view>
|
||||
<view class="settings-field-row"><text class="settings-label">营业时间</text><view class="time-range"><picker mode="time" value="{{form.startTime}}" bindchange="onStartChange"><view class="time-value">{{form.startTime}}</view></picker><text>至</text><picker mode="time" value="{{form.endTime}}" bindchange="onEndChange"><view class="time-value">{{form.endTime}}</view></picker></view></view>
|
||||
<view class="settings-field-row"><text class="settings-label">营业时间</text><view class="time-range"><picker mode="time" value="{{form.startTime}}" bindchange="onStartChange"><view class="time-value {{!form.startTime ? 'unconfigured' : ''}}">{{form.startTime || '设置开始时间'}}</view></picker><text>至</text><picker mode="time" value="{{form.endTime}}" bindchange="onEndChange"><view class="time-value {{!form.endTime ? 'unconfigured' : ''}}">{{form.endTime || '设置结束时间'}}</view></picker></view></view>
|
||||
<text wx:if="{{!businessHoursConfigured}}" class="appointment-hours-note">营业时间尚未设置,保存后才能创建普通预约。</text>
|
||||
<view class="settings-field-row duration-row"><view class="label-with-help"><text class="settings-label">默认预约时长</text><text class="help-badge" catchtap="explainDefaultDuration">?</text></view><view class="duration-input"><input type="number" value="{{form.defaultDuration}}" data-field="defaultDuration" bindinput="onInput" /><text>分钟</text></view></view>
|
||||
<button class="settings-action" loading="{{settingsSaving}}" disabled="{{settingsSaving}}" bindtap="saveAppointmentSettings">保存预约设置</button>
|
||||
</view>
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
.settings-label { color: #26342d; font-size: 24rpx; font-weight: 600; }
|
||||
.time-range { display: flex; align-items: center; gap: 15rpx; color: #859189; font-size: 21rpx; }
|
||||
.time-value { min-width: 102rpx; padding: 13rpx 14rpx; border-radius: 10rpx; background: #f0f6f2; color: #247b63; font-size: 24rpx; text-align: center; }
|
||||
.time-value.unconfigured { color: #89958e; }
|
||||
.appointment-hours-note { display: block; margin-top: 10rpx; color: #8a7751; font-size: 20rpx; line-height: 1.4; }
|
||||
.duration-row { align-items: center; }
|
||||
.duration-input { display: flex; align-items: center; gap: 12rpx; color: #748279; font-size: 22rpx; }
|
||||
.duration-input input { box-sizing: border-box; width: 150rpx; height: 68rpx; padding: 0 16rpx; border: 1rpx solid #dce8e0; border-radius: 10rpx; background: #f7faf8; color: #17211f; text-align: right; }
|
||||
|
||||
Reference in New Issue
Block a user