完善店务预约状态与详情流程
This commit is contained in:
@@ -7,6 +7,7 @@ const { markPlanningRefresh } = require('../../utils/planning-refresh')
|
||||
const { chooseImageFilePaths, uploadObjectFile, resolveUploadedImagePreviewUrl } = require('../../utils/upload')
|
||||
|
||||
const DRAFT_STORAGE_PREFIX = 'managerAppointmentDraft'
|
||||
const PLANNING_RETURN_TARGET_STORAGE_KEY = 'planningReturnTarget'
|
||||
const TIME_SLOT_MINUTES = 15
|
||||
const DAY_MINUTES = 24 * 60
|
||||
const DAY_END_COVER_MINUTE = 23 * 60 + 59
|
||||
@@ -146,6 +147,41 @@ function removeDraftForm() {
|
||||
}
|
||||
}
|
||||
|
||||
function writePlanningReturnTarget(target) {
|
||||
try {
|
||||
wx.setStorageSync(PLANNING_RETURN_TARGET_STORAGE_KEY, target)
|
||||
} catch (error) {
|
||||
throw new Error(`写入规划页返回目标失败:${error.message || error}`)
|
||||
}
|
||||
}
|
||||
|
||||
function confirmAppointmentSubmit() {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.showModal({
|
||||
title: '确认提交预约',
|
||||
content: '提交成功后将返回规划月视图。',
|
||||
confirmText: '提交',
|
||||
cancelText: '再检查',
|
||||
success: result => resolve(!!result.confirm),
|
||||
fail: error => reject(new Error(`打开预约确认弹窗失败:${error.errMsg || error.message || error}`))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function confirmFormAction(title, content, confirmText, confirmColor) {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.showModal({
|
||||
title,
|
||||
content,
|
||||
cancelText: '取消',
|
||||
confirmText,
|
||||
confirmColor,
|
||||
success: result => resolve(!!result.confirm),
|
||||
fail: error => reject(new Error(`打开确认弹窗失败:${error.errMsg || error.message || error}`))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function normalizeDuration(value) {
|
||||
const duration = Number(value)
|
||||
return Number.isFinite(duration) && duration > 0 ? Math.floor(duration) : 0
|
||||
@@ -440,12 +476,16 @@ function normalizeProduct(product, artists) {
|
||||
.map(id => findArtist(artists, id).name)
|
||||
.filter(Boolean)
|
||||
const durationText = product.approximateDuration || (product.serviceDurationMinutes ? `${product.serviceDurationMinutes}分钟` : '')
|
||||
const productPrice = formatProductPrice(product.price)
|
||||
const productPriceText = productPrice === '0'
|
||||
? '未定'
|
||||
: productPrice ? `¥${productPrice}` : '价格待定'
|
||||
return {
|
||||
...product,
|
||||
coverImage: imageUrls[0] || '',
|
||||
tagList: parseProductTags(product).slice(0, 4),
|
||||
artistText: artistNames.length > 0 ? artistNames.join('、') : '全部美甲师',
|
||||
priceText: product.price || product.price === 0 ? `¥${product.price}` : '价格待定',
|
||||
priceText: productPriceText,
|
||||
durationText
|
||||
}
|
||||
}
|
||||
@@ -553,8 +593,11 @@ function normalizeConfirmedPrice(value) {
|
||||
return String(price)
|
||||
}
|
||||
|
||||
function collectManualProductImages(fileIds, imageUrls) {
|
||||
return splitManualImageValues(`${fileIds || ''},${imageUrls || ''}`)
|
||||
function resolveAppointmentPriceText(form) {
|
||||
if (form.manualProductPriceUndetermined) {
|
||||
return '0'
|
||||
}
|
||||
return normalizeConfirmedPrice(form.manualProductPrice)
|
||||
}
|
||||
|
||||
function normalizeCustomer(customer) {
|
||||
@@ -606,6 +649,7 @@ Page({
|
||||
productId: '',
|
||||
manualProductTitle: '',
|
||||
manualProductPrice: '',
|
||||
manualProductPriceUndetermined: false,
|
||||
manualProductDescription: '',
|
||||
manualProductTags: '',
|
||||
manualProductPrecautions: '',
|
||||
@@ -740,6 +784,9 @@ Page({
|
||||
const patch = {
|
||||
[`form.${field}`]: value
|
||||
}
|
||||
if (field === 'manualProductPrice' && value) {
|
||||
patch['form.manualProductPriceUndetermined'] = false
|
||||
}
|
||||
if (field === 'customerName' || field === 'phone') {
|
||||
patch['form.customerUserId'] = ''
|
||||
patch.customerDropdownVisible = true
|
||||
@@ -762,6 +809,17 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
onPriceUndeterminedChange(event) {
|
||||
const checked = !!event.detail.value
|
||||
const patch = {
|
||||
'form.manualProductPriceUndetermined': checked
|
||||
}
|
||||
if (checked) {
|
||||
patch['form.manualProductPrice'] = ''
|
||||
}
|
||||
this.setData(patch)
|
||||
},
|
||||
|
||||
onCustomerFocus(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
this.setData({
|
||||
@@ -919,13 +977,15 @@ Page({
|
||||
selectProduct(event) {
|
||||
const selectedProduct = this.data.filteredProducts.find(item => String(item.id) === String(event.currentTarget.dataset.id)) || {}
|
||||
const price = formatProductPrice(selectedProduct.price)
|
||||
const priceUndetermined = price === '' || price === '0'
|
||||
const productTag = resolveTagValue(this.data.tagOptions, parseProductTags(selectedProduct).join(','))
|
||||
const imageUrls = Array.isArray(selectedProduct.imageUrls) ? selectedProduct.imageUrls : []
|
||||
this.setData({
|
||||
selectedProduct,
|
||||
'form.productId': '',
|
||||
'form.manualProductTitle': selectedProduct.title || '',
|
||||
'form.manualProductPrice': price,
|
||||
'form.manualProductPrice': priceUndetermined ? '' : price,
|
||||
'form.manualProductPriceUndetermined': priceUndetermined,
|
||||
'form.manualProductDescription': selectedProduct.description || '',
|
||||
'form.manualProductTags': productTag,
|
||||
'form.manualProductPrecautions': selectedProduct.precautions || '',
|
||||
@@ -953,8 +1013,8 @@ Page({
|
||||
|
||||
useManualProduct() {
|
||||
const title = String(this.data.form.manualProductTitle || '').trim()
|
||||
const priceText = normalizeConfirmedPrice(this.data.form.manualProductPrice)
|
||||
const imageValues = collectManualProductImages(this.data.form.manualProductImageFileIds, this.data.form.manualProductImageUrl)
|
||||
const priceUndetermined = !!this.data.form.manualProductPriceUndetermined
|
||||
const priceText = resolveAppointmentPriceText(this.data.form)
|
||||
if (!title) {
|
||||
wx.showToast({ title: '请填写作品名称', icon: 'none' })
|
||||
return
|
||||
@@ -963,15 +1023,11 @@ Page({
|
||||
wx.showToast({ title: '请填写正确的作品价格', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (imageValues.length === 0) {
|
||||
wx.showToast({ title: '请上传作品图片', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.setData({
|
||||
selectedProduct: {},
|
||||
'form.productId': '',
|
||||
'form.manualProductTitle': title,
|
||||
'form.manualProductPrice': priceText,
|
||||
'form.manualProductPrice': priceUndetermined ? '' : priceText,
|
||||
manualProductPanelVisible: false
|
||||
})
|
||||
this.closeProductModal()
|
||||
@@ -1225,7 +1281,7 @@ Page({
|
||||
return
|
||||
}
|
||||
const form = this.data.form
|
||||
const hasManualProduct = String(form.manualProductTitle || '').trim() && String(form.manualProductPrice || '').trim()
|
||||
const hasManualProduct = String(form.manualProductTitle || '').trim()
|
||||
const customerName = String(form.customerName || '').trim()
|
||||
const phone = String(form.phone || '').trim()
|
||||
const durationMinutes = normalizeDuration(form.durationMinutes)
|
||||
@@ -1233,17 +1289,12 @@ Page({
|
||||
wx.showToast({ title: '请补全预约信息', icon: 'none' })
|
||||
return
|
||||
}
|
||||
const appointmentPriceText = normalizeConfirmedPrice(form.manualProductPrice)
|
||||
const appointmentPriceText = resolveAppointmentPriceText(form)
|
||||
if (!appointmentPriceText) {
|
||||
wx.showToast({ title: '请填写本次价格', icon: 'none' })
|
||||
return
|
||||
}
|
||||
const appointmentPrice = Number(appointmentPriceText)
|
||||
const manualProductImages = collectManualProductImages(form.manualProductImageFileIds, form.manualProductImageUrl)
|
||||
if (!form.productId && manualProductImages.length === 0) {
|
||||
wx.showToast({ title: '请上传作品图片', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!durationMinutes) {
|
||||
wx.showToast({ title: '请填写预约时长', icon: 'none' })
|
||||
return
|
||||
@@ -1253,6 +1304,16 @@ Page({
|
||||
wx.showToast({ title: availability.tip || '该时段已被预约', icon: 'none' })
|
||||
return
|
||||
}
|
||||
let confirmed
|
||||
try {
|
||||
confirmed = await confirmAppointmentSubmit()
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '确认提交失败', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!confirmed) {
|
||||
return
|
||||
}
|
||||
this.setData({ loading: true })
|
||||
try {
|
||||
const payload = {
|
||||
@@ -1267,6 +1328,7 @@ Page({
|
||||
durationMinutes,
|
||||
clientRequestId: buildClientRequestId('manager-appointment')
|
||||
}
|
||||
delete payload.manualProductPriceUndetermined
|
||||
if (form.productId) {
|
||||
payload.productId = String(form.productId)
|
||||
payload.manualProductTitle = undefined
|
||||
@@ -1282,8 +1344,16 @@ Page({
|
||||
}
|
||||
const result = await planningApi.createAppointment(payload)
|
||||
removeDraftForm()
|
||||
writePlanningReturnTarget({
|
||||
source: 'appointment-create',
|
||||
date: form.appointmentDate,
|
||||
orderItemId: result.orderItemId || result.id || ''
|
||||
})
|
||||
markPlanningRefresh()
|
||||
wx.redirectTo({ url: `/pages/appointment-detail/index?id=${result.orderItemId}` })
|
||||
wx.switchTab({
|
||||
url: '/pages/planning/index',
|
||||
fail: error => wx.showToast({ title: `跳转规划页失败:${error.errMsg || error.message || error}`, icon: 'none' })
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '提交失败', icon: 'none' })
|
||||
} finally {
|
||||
@@ -1301,7 +1371,17 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
clearDraft() {
|
||||
async clearDraft() {
|
||||
let confirmed
|
||||
try {
|
||||
confirmed = await confirmFormAction('清空草稿', '确认清空当前本机预约草稿?', '清空', '#d98d8d')
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '确认清空失败', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!confirmed) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
removeDraftForm()
|
||||
this.setData({ draftSavedAtText: '' })
|
||||
|
||||
Reference in New Issue
Block a user