优化预约内容填写弹窗

This commit is contained in:
2026-07-21 19:09:43 +08:00
parent df6eccda0f
commit e3f5ad1ba1
3 changed files with 223 additions and 33 deletions
@@ -327,6 +327,43 @@ function formatProductPrice(value) {
return String(price)
}
function sanitizePriceInput(value) {
const rawValue = String(value || '')
let nextValue = ''
let hasDot = false
for (let index = 0; index < rawValue.length; index += 1) {
const char = rawValue[index]
if (char >= '0' && char <= '9') {
nextValue += char
continue
}
if (char === '.' && !hasDot) {
nextValue += char
hasDot = true
}
}
if (nextValue.startsWith('.')) {
return `0${nextValue}`
}
return nextValue
}
function normalizeConfirmedPrice(value) {
const priceText = sanitizePriceInput(value).trim()
if (!/^\d+(\.\d+)?$/.test(priceText)) {
return ''
}
const price = Number(priceText)
if (!Number.isFinite(price) || price < 0) {
return ''
}
return String(price)
}
function collectManualProductImages(fileIds, imageUrls) {
return splitManualImageValues(`${fileIds || ''},${imageUrls || ''}`)
}
function isScheduleCoveringTime(schedule, form, startMinute, endMinute) {
if (!schedule || String(schedule.artistId) !== String(form.artistId) || schedule.date !== form.appointmentDate) {
return false
@@ -491,8 +528,11 @@ Page({
onInput(event) {
const field = event.currentTarget.dataset.field
const value = field === 'manualProductPrice'
? sanitizePriceInput(event.detail.value)
: event.detail.value
const patch = {
[`form.${field}`]: event.detail.value
[`form.${field}`]: value
}
if (field === 'customerName' || field === 'phone') {
patch['form.customerUserId'] = ''
@@ -506,6 +546,7 @@ Page({
this.refreshAvailableTimes()
this.checkAvailability()
}
return value
},
toggleFlag(event) {
@@ -599,6 +640,11 @@ Page({
},
openProductModal() {
const customerName = String(this.data.form.customerName || '').trim()
if (!customerName) {
wx.showToast({ title: '请先填写客户姓名', icon: 'none' })
return
}
this.openManualProductPanel()
},
@@ -617,14 +663,26 @@ Page({
},
openManualProductPanel() {
const customerName = String(this.data.form.customerName || '').trim()
if (!customerName) {
wx.showToast({ title: '请先填写客户姓名', icon: 'none' })
return
}
const imageUrls = this.data.manualProductImageUrls.length > 0
? this.data.manualProductImageUrls
: splitManualImageValues(this.data.form.manualProductImageUrl)
this.setData({
const productTitle = String(this.data.form.manualProductTitle || '').trim()
const patch = {
manualProductPanelVisible: true,
productModalVisible: false,
manualProductImageUrls: imageUrls,
tagPickerIndex: resolveTagPickerIndex(this.data.tagOptions, this.data.form.manualProductTags)
}
if (!productTitle) {
patch['form.manualProductTitle'] = customerName
}
this.setData({
...patch
})
},
@@ -683,16 +741,25 @@ Page({
useManualProduct() {
const title = String(this.data.form.manualProductTitle || '').trim()
const price = Number(this.data.form.manualProductPrice)
if (!title || Number.isNaN(price) || price < 0) {
wx.showToast({ title: '请填写作品名称和价格', icon: 'none' })
const priceText = normalizeConfirmedPrice(this.data.form.manualProductPrice)
const imageValues = collectManualProductImages(this.data.form.manualProductImageFileIds, this.data.form.manualProductImageUrl)
if (!title) {
wx.showToast({ title: '请填写作品名称', icon: 'none' })
return
}
if (!priceText) {
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': String(price),
'form.manualProductPrice': priceText,
manualProductPanelVisible: false
})
this.closeProductModal()
@@ -944,11 +1011,17 @@ Page({
wx.showToast({ title: '请补全预约信息', icon: 'none' })
return
}
const appointmentPrice = Number(form.manualProductPrice)
if (!Number.isFinite(appointmentPrice) || appointmentPrice < 0) {
const appointmentPriceText = normalizeConfirmedPrice(form.manualProductPrice)
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