From 6e9ad54e94052b56524e3f42acec98738a93130b Mon Sep 17 00:00:00 2001 From: xiaowang <2161656029@qq.com> Date: Wed, 21 Oct 2026 02:36:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=A2=84=E7=BA=A6=E6=AC=BE?= =?UTF-8?q?=E5=BC=8F=E5=A4=9A=E5=9B=BE=E5=BD=95=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/appointment-form/index.js | 123 ++++++++--- .../pages/appointment-form/index.wxml | 33 ++- .../pages/appointment-form/index.wxss | 203 ++++++++++++++---- .../appointment-form/product-selector.test.js | 100 ++++++++- ...-10-21-salon新增预约多图款式录入-design.md | 32 +++ docs/项目变更记录.md | 8 + 6 files changed, 423 insertions(+), 76 deletions(-) create mode 100644 docs/superpowers/specs/2026-10-21-salon新增预约多图款式录入-design.md diff --git a/JC-Salon-WeChat/pages/appointment-form/index.js b/JC-Salon-WeChat/pages/appointment-form/index.js index bbb90554..f10ba57a 100644 --- a/JC-Salon-WeChat/pages/appointment-form/index.js +++ b/JC-Salon-WeChat/pages/appointment-form/index.js @@ -3,7 +3,7 @@ const productsApi = require('../../api/products') const customersApi = require('../../api/customers') const dateUtil = require('../../utils/date') const { markPlanningRefresh } = require('../../utils/planning-refresh') -const { chooseImageFilePath, uploadObjectFile } = require('../../utils/upload') +const { uploadObjectFile } = require('../../utils/upload') const DRAFT_STORAGE_PREFIX = 'managerAppointmentDraft' const TIME_SLOT_MINUTES = 15 @@ -64,6 +64,53 @@ function removeDraftForm() { } } +function normalizeManualProductImages(form) { + const savedImages = form && Array.isArray(form.manualProductImages) ? form.manualProductImages : null + if (savedImages) { + return savedImages.map(image => ({ + fileId: image && image.fileId !== undefined ? String(image.fileId) : '', + fileUrl: image && (image.fileUrl || image.url) ? String(image.fileUrl || image.url) : '' + })).filter(image => image.fileId).slice(0, 9) + } + const fileIds = String(form && form.manualProductImageFileIds || '').split(',').map(fileId => fileId.trim()).filter(Boolean) + return fileIds.slice(0, 9).map((fileId, index) => ({ + fileId, + fileUrl: index === 0 && form && form.manualProductImageUrl ? String(form.manualProductImageUrl) : '' + })) +} + +function buildManualProductImagePatch(images) { + const normalizedImages = (images || []).slice(0, 9) + return { + 'form.manualProductImages': normalizedImages, + 'form.manualProductImageFileIds': normalizedImages.map(image => image.fileId).filter(Boolean).join(','), + 'form.manualProductImageUrl': normalizedImages[0] ? normalizedImages[0].fileUrl || '' : '' + } +} + +function chooseManualProductImagePaths(count) { + const normalizedCount = Math.min(9, Math.max(1, Math.floor(Number(count) || 1))) + return new Promise((resolve, reject) => { + wx.chooseMedia({ + count: normalizedCount, + mediaType: ['image'], + sourceType: ['album', 'camera'], + sizeType: ['compressed'], + success(result) { + resolve((result.tempFiles || []).map(file => file && file.tempFilePath).filter(Boolean).slice(0, normalizedCount)) + }, + fail(error) { + const message = error && error.errMsg ? error.errMsg : '' + if (message.includes('cancel')) { + resolve([]) + return + } + reject(new Error(`选择图片失败:${message || '未知错误'}`)) + } + }) + }) +} + function normalizeDuration(value) { const duration = Number(value) return Number.isFinite(duration) && duration > 0 ? Math.floor(duration) : 0 @@ -414,6 +461,7 @@ Page({ manualProductPrecautions: '', manualProductImageFileIds: '', manualProductImageUrl: '', + manualProductImages: [], durationMinutes: '60', artistId: '', createCustomerRecord: false, @@ -440,6 +488,7 @@ Page({ selectedArtist: {}, productModalVisible: false, manualProductSheetVisible: false, + manualProductMoreVisible: false, productKeyword: '', productError: '', loadingProducts: false, @@ -471,6 +520,7 @@ Page({ const creatable = canCreateAppointment() const draftForm = creatable && !hasPresetOptions(options) ? readDraftForm() : null const baseForm = draftForm || {} + const manualProductImages = normalizeManualProductImages(baseForm) const appointmentDate = options.date || baseForm.appointmentDate || dateUtil.formatDate(new Date()) const dateLabels = buildAppointmentDateLabels(appointmentDate) this.setData({ @@ -478,6 +528,9 @@ Page({ form: { ...this.data.form, ...baseForm, + manualProductImages, + manualProductImageFileIds: manualProductImages.map(image => image.fileId).join(','), + manualProductImageUrl: manualProductImages[0] ? manualProductImages[0].fileUrl : '', customerName: options.customerName ? decodeURIComponent(options.customerName) : (baseForm.customerName || ''), phone: options.phone ? decodeURIComponent(options.phone) : (baseForm.phone || ''), appointmentDate, @@ -621,8 +674,7 @@ Page({ patch['form.productId'] = '' patch.selectedProduct = {} patch.selectedProductPriceText = '' - patch['form.manualProductImageFileIds'] = '' - patch['form.manualProductImageUrl'] = '' + Object.assign(patch, buildManualProductImagePatch([])) } this.setData(patch) }, @@ -822,7 +874,8 @@ Page({ openManualProduct() { this.setData({ productModalVisible: false, - manualProductSheetVisible: true + manualProductSheetVisible: true, + manualProductMoreVisible: false }) }, @@ -830,9 +883,13 @@ Page({ this.setData({ manualProductSheetVisible: false }) }, + toggleManualProductMore() { + this.setData({ manualProductMoreVisible: !this.data.manualProductMoreVisible }) + }, + confirmManualProduct() { const hasTitle = Boolean(String(this.data.form.manualProductTitle || '').trim()) - const hasImage = Boolean(String(this.data.form.manualProductImageFileIds || '').trim()) + const hasImage = (this.data.form.manualProductImages || []).length > 0 || Boolean(String(this.data.form.manualProductImageFileIds || '').trim()) const hasFallbackName = Boolean(String(this.data.form.customerName || '').trim()) if (this.data.form.productId && !hasTitle && !hasImage) { this.closeManualProduct() @@ -876,6 +933,7 @@ Page({ 'form.manualProductPrecautions': '', 'form.manualProductImageFileIds': '', 'form.manualProductImageUrl': '', + 'form.manualProductImages': [], 'form.amount': selectedProduct.price === undefined || selectedProduct.price === null ? '' : String(selectedProduct.price), 'form.durationMinutes': String(selectedDuration || this.data.form.durationMinutes || '') }) @@ -888,25 +946,35 @@ Page({ if (this.data.manualImageUploading) { return } + const remainingCount = 9 - (this.data.form.manualProductImages || []).length + if (remainingCount <= 0) { + wx.showToast({ title: '最多添加9张图片', icon: 'none' }) + return + } try { - const filePath = await chooseImageFilePath() - if (!filePath) { + this.setData({ manualImageUploading: true }) + const filePaths = await chooseManualProductImagePaths(remainingCount) + if (!filePaths.length) { return } - this.setData({ manualImageUploading: true }) - const uploadResult = await uploadObjectFile(filePath) - const fileId = uploadResult.id || uploadResult.fileId - const fileUrl = uploadResult.fileUrl || uploadResult.primaryUrl || filePath - if (!fileId) { - throw new Error('作品图片上传成功但未返回文件ID') + for (const filePath of filePaths) { + const uploadResult = await uploadObjectFile(filePath) + const fileId = uploadResult.id || uploadResult.fileId + const fileUrl = uploadResult.fileUrl || uploadResult.primaryUrl || filePath + if (!fileId) { + throw new Error('作品图片上传成功但未返回文件ID') + } + const images = (this.data.form.manualProductImages || []).concat({ fileId: String(fileId), fileUrl }).slice(0, 9) + this.setData({ + ...buildManualProductImagePatch(images), + 'form.productId': '', + selectedProduct: {}, + selectedProductPriceText: '' + }) + } + if (filePaths.length > 1) { + wx.showToast({ title: `已添加${filePaths.length}张图片`, icon: 'success' }) } - this.setData({ - 'form.productId': '', - selectedProduct: {}, - selectedProductPriceText: '', - 'form.manualProductImageFileIds': String(fileId), - 'form.manualProductImageUrl': fileUrl - }) } catch (error) { wx.showToast({ title: error.message || '图片上传失败', icon: 'none' }) } finally { @@ -914,11 +982,16 @@ Page({ } }, - removeManualProductImage() { - this.setData({ - 'form.manualProductImageFileIds': '', - 'form.manualProductImageUrl': '' - }) + removeManualProductImage(event) { + if (this.data.manualImageUploading) { + return + } + const index = Number(event && event.currentTarget && event.currentTarget.dataset.index) + const images = this.data.form.manualProductImages || [] + if (!Number.isInteger(index) || index < 0 || index >= images.length) { + return + } + this.setData(buildManualProductImagePatch(images.filter((image, imageIndex) => imageIndex !== index))) }, filterArtistItems(artists, keywordValue) { diff --git a/JC-Salon-WeChat/pages/appointment-form/index.wxml b/JC-Salon-WeChat/pages/appointment-form/index.wxml index 510e38a9..0cb10936 100644 --- a/JC-Salon-WeChat/pages/appointment-form/index.wxml +++ b/JC-Salon-WeChat/pages/appointment-form/index.wxml @@ -19,9 +19,9 @@ ✦ {{form.manualProductTitle}} - 已添加款式图片 + 已添加 {{form.manualProductImages.length}} 张款式图片 填写款式名称或添加图片 - 点击可手动录入,提交预约后自动加入款式库 + {{form.manualProductImages.length ? '已添加 ' + form.manualProductImages.length + ' 张图片 · 点击可编辑' : '点击可手动录入,提交预约后自动加入款式库'}} › @@ -32,7 +32,7 @@ - + 款式备注