回溯点:保存注册预约客户流程修复进度
This commit is contained in:
@@ -1,17 +1,37 @@
|
||||
const { BRAND_CONFIG } = require('../../utils/config')
|
||||
const profileCache = require('../../utils/profile-cache')
|
||||
const shopApi = require('../../api/shop')
|
||||
|
||||
function resolveNameStatus(value) {
|
||||
const status = String(value || '').toUpperCase()
|
||||
if (status === 'PENDING' || status === 'RETRY') return '名称审核中'
|
||||
if (status === 'REJECTED') return '名称审核未通过'
|
||||
if (status === 'APPROVED') return '名称已通过审核'
|
||||
return '尚未提交审核'
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
profile: {},
|
||||
businessExpireDateText: '未设置',
|
||||
businessExpiryStatusText: '有效期未设置',
|
||||
form: { shopName: BRAND_CONFIG.defaultShopName, startTime: '10:00', endTime: '22:00', defaultDuration: 60, rule: '必须选择已有作品作为项目来源' }
|
||||
nameModerationText: '尚未提交审核',
|
||||
settingsLoading: false,
|
||||
settingsSaving: false,
|
||||
nameSaving: false,
|
||||
settingsError: '',
|
||||
form: { shopName: BRAND_CONFIG.defaultShopName, pendingShopName: '', startTime: '10:00', endTime: '22:00', defaultDuration: 60 }
|
||||
},
|
||||
onShow() { this.loadProfile() },
|
||||
async loadProfile(options = {}) {
|
||||
|
||||
onShow() { this.loadProfileAndSettings() },
|
||||
|
||||
async loadProfileAndSettings(options = {}) {
|
||||
this.setData({ settingsLoading: true, settingsError: '' })
|
||||
try {
|
||||
const profile = await profileCache.getProfile(options)
|
||||
const [profile, settings] = await Promise.all([
|
||||
profileCache.getProfile(options),
|
||||
shopApi.appointmentSettings()
|
||||
])
|
||||
const businessExpireDateText = profile.shopBusinessExpireTime ? String(profile.shopBusinessExpireTime).slice(0, 10) : '未设置'
|
||||
const remainingDays = profile.shopBusinessRemainingDays
|
||||
const hasRemainingDays = remainingDays !== null && remainingDays !== undefined && remainingDays !== '' && Number.isFinite(Number(remainingDays))
|
||||
@@ -20,30 +40,79 @@ Page({
|
||||
: hasRemainingDays
|
||||
? `剩余 ${remainingDays} 天`
|
||||
: '有效期未设置'
|
||||
this.setData({ profile, businessExpireDateText, businessExpiryStatusText })
|
||||
const [startTime, endTime] = String(settings.businessHours || '10:00-22:00').split('-')
|
||||
this.setData({
|
||||
profile,
|
||||
businessExpireDateText,
|
||||
businessExpiryStatusText,
|
||||
nameModerationText: resolveNameStatus(settings.shopNameModerationStatus),
|
||||
form: {
|
||||
...this.data.form,
|
||||
shopName: settings.pendingShopName || settings.shopName || profile.shopName || BRAND_CONFIG.defaultShopName,
|
||||
pendingShopName: settings.pendingShopName || '',
|
||||
startTime: startTime || '10:00',
|
||||
endTime: endTime || '22:00',
|
||||
defaultDuration: Number(settings.defaultAppointmentDurationMinutes) || 60
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
this.setData({ profile: {} })
|
||||
this.setData({ settingsError: error.message || '设置加载失败' })
|
||||
} finally {
|
||||
this.setData({ settingsLoading: false })
|
||||
}
|
||||
},
|
||||
|
||||
onInput(event) { this.setData({ [`form.${event.currentTarget.dataset.field}`]: event.detail.value }) },
|
||||
onStartChange(event) { this.setData({ 'form.startTime': event.detail.value }) },
|
||||
onEndChange(event) { this.setData({ 'form.endTime': event.detail.value }) },
|
||||
|
||||
async saveAppointmentSettings() {
|
||||
const { startTime, endTime, defaultDuration } = this.data.form
|
||||
const duration = Number(defaultDuration)
|
||||
if (startTime >= endTime) {
|
||||
wx.showToast({ title: '营业结束时间必须晚于开始时间', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!Number.isInteger(duration) || duration < 15 || duration > 720) {
|
||||
wx.showToast({ title: '默认时长需在15至720分钟之间', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.setData({ settingsSaving: true })
|
||||
try {
|
||||
await shopApi.saveAppointmentSettings({ businessHours: `${startTime}-${endTime}`, defaultAppointmentDurationMinutes: duration })
|
||||
wx.showToast({ title: '预约设置已生效', icon: 'success' })
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '保存失败,请重试', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ settingsSaving: false })
|
||||
}
|
||||
},
|
||||
|
||||
async submitShopName() {
|
||||
const shopName = String(this.data.form.shopName || '').trim()
|
||||
if (!shopName) {
|
||||
wx.showToast({ title: '请输入店铺名称', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.setData({ nameSaving: true })
|
||||
try {
|
||||
await shopApi.updateName(shopName)
|
||||
wx.showToast({ title: '店铺名称已提交审核', icon: 'success' })
|
||||
await this.loadProfileAndSettings({ force: true })
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '提交审核失败', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ nameSaving: false })
|
||||
}
|
||||
},
|
||||
|
||||
explainDefaultDuration() {
|
||||
wx.showModal({
|
||||
title: '默认时长',
|
||||
content: '用于手动创建预约或未选择作品时的默认服务时长,会影响可约时间校验和预约结束时间估算。',
|
||||
content: '用于新建预约表单的初始值和未设置款式时的后备时长。已选款式的时长或你在预约中修改的时长优先。',
|
||||
showCancel: false,
|
||||
confirmText: '知道了'
|
||||
})
|
||||
},
|
||||
explainBookingRule() {
|
||||
wx.showModal({
|
||||
title: '预约规则',
|
||||
content: '这是店铺给美甲师看的预约备注或说明文案,不参与自动排班、容量或冲突校验。',
|
||||
showCancel: false,
|
||||
confirmText: '知道了'
|
||||
})
|
||||
},
|
||||
save() { wx.showToast({ title: '已保存' }) },
|
||||
back() { wx.navigateBack() }
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user