From e3f5ad1ba1c68f58d78cf57abcd3e2e9019a9e4b Mon Sep 17 00:00:00 2001 From: xiaowang <2161656029@qq.com> Date: Tue, 21 Jul 2026 19:09:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=A2=84=E7=BA=A6=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E5=A1=AB=E5=86=99=E5=BC=B9=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/appointment-form/index.js | 89 ++++++++++++-- .../pages/appointment-form/index.wxml | 54 +++++---- .../pages/appointment-form/index.wxss | 113 +++++++++++++++++- 3 files changed, 223 insertions(+), 33 deletions(-) diff --git a/JY-Salon-WeChat/pages/appointment-form/index.js b/JY-Salon-WeChat/pages/appointment-form/index.js index 663e5bed..6837d94b 100644 --- a/JY-Salon-WeChat/pages/appointment-form/index.js +++ b/JY-Salon-WeChat/pages/appointment-form/index.js @@ -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 diff --git a/JY-Salon-WeChat/pages/appointment-form/index.wxml b/JY-Salon-WeChat/pages/appointment-form/index.wxml index f6d75966..c30a16b6 100644 --- a/JY-Salon-WeChat/pages/appointment-form/index.wxml +++ b/JY-Salon-WeChat/pages/appointment-form/index.wxml @@ -32,8 +32,8 @@ 选择作品 - - {{form.manualProductTitle || selectedProduct.title || '请选择作品'}} + + {{form.customerName ? (form.manualProductTitle || selectedProduct.title || '请选择作品') : '请先填写客户姓名'}} @@ -78,7 +78,7 @@ 备注 -