修复预约草稿恢复逻辑
This commit is contained in:
@@ -118,10 +118,6 @@ function buildDraftKey() {
|
||||
return `${DRAFT_STORAGE_PREFIX}:${userInfo.id || 'guest'}:${userInfo.shopId || 'default'}`
|
||||
}
|
||||
|
||||
function hasPresetOptions(options) {
|
||||
return Boolean(options.customerName || options.phone || options.date || options.artistId)
|
||||
}
|
||||
|
||||
function readDraftForm() {
|
||||
try {
|
||||
const draft = wx.getStorageSync(buildDraftKey())
|
||||
@@ -573,6 +569,32 @@ function normalizeCustomer(customer) {
|
||||
}
|
||||
}
|
||||
|
||||
function buildInitialAppointmentForm(defaultForm, draftForm, options) {
|
||||
const baseForm = draftForm || {}
|
||||
const optionCustomerName = options.customerName ? decodeURIComponent(options.customerName) : ''
|
||||
const optionPhone = options.phone ? decodeURIComponent(options.phone) : ''
|
||||
const optionDate = options.date || ''
|
||||
const optionArtistId = options.artistId || ''
|
||||
const baseArtistId = baseForm.artistId || ''
|
||||
const appointmentDate = optionDate || baseForm.appointmentDate || dateUtil.formatDate(new Date())
|
||||
const artistId = optionArtistId || baseArtistId
|
||||
const shouldClearCustomerUserId = Boolean(optionCustomerName || optionPhone)
|
||||
const shouldClearAppointmentTime = Boolean(
|
||||
(optionDate && optionDate !== baseForm.appointmentDate) ||
|
||||
(optionArtistId && String(optionArtistId) !== String(baseArtistId))
|
||||
)
|
||||
return {
|
||||
...defaultForm,
|
||||
...baseForm,
|
||||
customerUserId: shouldClearCustomerUserId ? '' : (baseForm.customerUserId || ''),
|
||||
customerName: optionCustomerName || baseForm.customerName || '',
|
||||
phone: optionPhone || baseForm.phone || '',
|
||||
appointmentDate,
|
||||
appointmentTime: shouldClearAppointmentTime ? '' : (baseForm.appointmentTime || ''),
|
||||
artistId
|
||||
}
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
form: {
|
||||
@@ -631,19 +653,12 @@ Page({
|
||||
|
||||
onLoad(options) {
|
||||
const creatable = canCreateAppointment()
|
||||
const draftForm = creatable && !hasPresetOptions(options) ? readDraftForm() : null
|
||||
const baseForm = draftForm || {}
|
||||
const draftForm = creatable ? readDraftForm() : null
|
||||
const initialForm = buildInitialAppointmentForm(this.data.form, draftForm, options)
|
||||
this.setData({
|
||||
canCreateAppointment: creatable,
|
||||
form: {
|
||||
...this.data.form,
|
||||
...baseForm,
|
||||
customerName: options.customerName ? decodeURIComponent(options.customerName) : (baseForm.customerName || ''),
|
||||
phone: options.phone ? decodeURIComponent(options.phone) : (baseForm.phone || ''),
|
||||
appointmentDate: options.date || baseForm.appointmentDate || dateUtil.formatDate(new Date()),
|
||||
artistId: options.artistId || baseForm.artistId || ''
|
||||
},
|
||||
manualProductImageUrls: splitManualImageValues(baseForm.manualProductImageUrl || ''),
|
||||
form: initialForm,
|
||||
manualProductImageUrls: splitManualImageValues(initialForm.manualProductImageUrl || ''),
|
||||
draftSavedAtText: draftForm ? '已恢复本机草稿' : ''
|
||||
})
|
||||
if (!creatable) {
|
||||
|
||||
Reference in New Issue
Block a user