修复Salon注册预约客户流程
This commit is contained in:
@@ -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