From c8e0806c4d6526115cb101b497aa77e2a074559b Mon Sep 17 00:00:00 2001 From: xiaowang <2161656029@qq.com> Date: Sat, 31 Oct 2026 03:48:49 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=8E=86=E5=8F=B2=E8=A1=A5?= =?UTF-8?q?=E5=BD=95=E4=B8=8E=E6=96=B0=E5=BB=BA=E9=A2=84=E7=BA=A6=E8=A1=A8?= =?UTF-8?q?=E5=8D=95=E4=BD=93=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/PlanningBackfillOrderCreateDTO.java | 7 + .../service/impl/PlanningServiceImpl.java | 8 + JC-Salon-WeChat/pages/backfill-order/index.js | 129 ++-- .../pages/backfill-order/index.wxml | 136 ++-- .../pages/backfill-order/index.wxss | 587 +----------------- .../backfill-order/product-selector.test.js | 4 +- 6 files changed, 153 insertions(+), 718 deletions(-) diff --git a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/planning/dto/PlanningBackfillOrderCreateDTO.java b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/planning/dto/PlanningBackfillOrderCreateDTO.java index cf6247a7..e4596e53 100644 --- a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/planning/dto/PlanningBackfillOrderCreateDTO.java +++ b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/planning/dto/PlanningBackfillOrderCreateDTO.java @@ -9,8 +9,15 @@ public class PlanningBackfillOrderCreateDTO { private Long productId; private String manualProductTitle; private BigDecimal manualProductPrice; + private Integer durationMinutes; + private String manualProductDescription; + private String manualProductTags; + private String manualProductTargetAudience; + private String manualProductPrecautions; + private String manualProductImageFileIds; private Long customerUserId; private String customerName; + private String wechatId; private String phone; private String serviceDate; private String serviceTime; diff --git a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/planning/service/impl/PlanningServiceImpl.java b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/planning/service/impl/PlanningServiceImpl.java index 9b5ea787..5b1e77f6 100644 --- a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/planning/service/impl/PlanningServiceImpl.java +++ b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/planning/service/impl/PlanningServiceImpl.java @@ -270,6 +270,14 @@ public class PlanningServiceImpl implements PlanningService { BigDecimal price = dto.getManualProductPrice() == null ? dto.getAmount() : dto.getManualProductPrice(); if (price == null || price.compareTo(BigDecimal.ZERO) < 0) throw new RuntimeException("项目金额不能小于0"); product = new ProductDO(); product.setShopId(shopId); product.setTitle(title); product.setPrice(price); + product.setDescription(trimToNull(dto.getManualProductDescription())); + product.setTags(trimToNull(dto.getManualProductTags())); + product.setTargetAudience(trimToNull(dto.getManualProductTargetAudience())); + product.setPrecautions(trimToNull(dto.getManualProductPrecautions())); + product.setImageFileIds(trimToNull(dto.getManualProductImageFileIds())); + int durationMinutes = dto.getDurationMinutes() == null || dto.getDurationMinutes() <= 0 ? DEFAULT_DURATION_MINUTES : dto.getDurationMinutes(); + product.setApproximateDuration(durationMinutes + "分钟"); + product.setBookableArtists(String.valueOf(dto.getArtistId())); product.setSourceType(PRODUCT_SOURCE_TYPE_MANAGER_APPOINTMENT); product.setFrontVisible(0); product.setLikeCount(0); product.setCollectCount(0); product.setIsDelete(0); productMapper.insert(product); } diff --git a/JC-Salon-WeChat/pages/backfill-order/index.js b/JC-Salon-WeChat/pages/backfill-order/index.js index b0ec1273..4abb0f48 100644 --- a/JC-Salon-WeChat/pages/backfill-order/index.js +++ b/JC-Salon-WeChat/pages/backfill-order/index.js @@ -3,91 +3,70 @@ const employeesApi = require('../../api/employees') const productsApi = require('../../api/products') const customersApi = require('../../api/customers') const dateUtil = require('../../utils/date') +const { uploadObjectFile } = require('../../utils/upload') + +function normalizeProduct(product, artists) { + const artistIds = String(product.bookableArtists || '').split(',').map(id => id.trim()).filter(Boolean) + const artistNames = artistIds.map(id => artists.find(artist => String(artist.id) === id)).filter(Boolean).map(artist => artist.name) + const imageUrls = Array.isArray(product.imageUrls) ? product.imageUrls : [] + const tags = Array.isArray(product.tagList) ? product.tagList : String(product.tags || '').split(/[;,,、]/).map(tag => tag.trim()).filter(Boolean) + return { ...product, title: product.title || '未命名款式', coverImage: imageUrls[0] || '', priceText: product.price == null ? '价格待定' : `¥${product.price}`, durationText: product.approximateDuration || (product.serviceDurationMinutes ? `${product.serviceDurationMinutes}分钟` : '时长待定'), artistText: artistIds.length ? artistNames.join('、') || `${artistIds.length}位美甲师可做` : '全部美甲师', tagList: tags.slice(0, 3) } +} + +function normalizeCustomer(customer) { + const name = customer.nickname || customer.name || customer.account || '' + const phone = customer.contactPhone || customer.phone || '' + return { ...customer, id: customer.id, name, phone, title: name || phone || '客户', subtitle: phone || '未填写手机号' } +} + +function imagePatch(images) { + const normalized = (images || []).slice(0, 9) + return { 'form.manualProductImages': normalized, 'form.manualProductImageFileIds': normalized.map(image => image.fileId).filter(Boolean).join(','), 'form.manualProductImageUrl': normalized[0] ? normalized[0].previewUrl || normalized[0].fileUrl || '' : '' } +} + +function chooseImages(count) { + return new Promise((resolve, reject) => wx.chooseMedia({ count: Math.min(9, Math.max(1, count)), mediaType: ['image'], sourceType: ['album', 'camera'], sizeType: ['compressed'], success: result => resolve((result.tempFiles || []).map(file => file.tempFilePath).filter(Boolean)), fail: error => String(error && error.errMsg || '').includes('cancel') ? resolve([]) : reject(new Error(`选择图片失败:${error && error.errMsg || '未知错误'}`)) })) +} Page({ - data: { form: { serviceDate: dateUtil.formatDate(new Date()), manualProductTitle: '', amount: '', customerName: '', phone: '', serviceTime: '', status: 4, remark: '', artistId: '', productId: '', customerUserId: '' }, manualProductDraft: { title: '', price: '' }, artists: [], artistOptions: [], allProductOptions: [], productOptions: [], customerOptions: [], allCustomerOptions: [], productSelectorVisible: false, manualProductSheetVisible: false, artistSelectorVisible: false, customerSelectorVisible: false, loadingProducts: false, loadingArtists: false, loadingCustomers: false, productKeyword: '', artistKeyword: '', customerKeyword: '', productError: '', artistError: '', customerError: '', selectedArtistName: '', selectedProduct: {}, selectedProductTitle: '', selectedProductPriceText: '', submitting: false }, - onLoad(options = {}) { - const serviceDate = options.serviceDate || this.data.form.serviceDate - const artistId = options.artistId || '' - this.setData({ 'form.serviceDate': serviceDate, 'form.artistId': artistId }) - this.loadArtists(artistId); this.loadProducts(); this.loadCustomers() + data: { + form: { serviceDate: dateUtil.formatDate(new Date()), serviceTime: '', artistId: '', productId: '', manualProductTitle: '', manualProductDescription: '', manualProductTags: '', manualProductTargetAudience: '', manualProductPrecautions: '', manualProductImageFileIds: '', manualProductImageUrl: '', manualProductImages: [], customerUserId: '', customerName: '', wechatId: '', phone: '', amount: '', durationMinutes: '60', status: 4, remark: '' }, + manualProductDraft: { title: '', price: '', durationMinutes: '60', description: '' }, + artists: [], artistOptions: [], products: [], productOptions: [], allCustomerOptions: [], customerOptions: [], productSelectorVisible: false, manualProductSheetVisible: false, artistSelectorVisible: false, customerSelectorVisible: false, loadingProducts: false, loadingArtists: false, loadingCustomers: false, manualImageUploading: false, submitting: false, productKeyword: '', artistKeyword: '', customerKeyword: '', productError: '', artistError: '', customerError: '', selectedArtistName: '', selectedProduct: {}, selectedProductTitle: '', selectedProductPriceText: '', manualProductTitleLength: 0, manualProductMoreVisible: false }, - async loadArtists(preferredArtistId) { - try { - const result = await employeesApi.list({ page: 1, size: 100 }) - const list = result.list || result || [] - const normalized = list.map(item => ({ ...item, name: item.name || item.nickname || item.account || `美甲师${item.id}` })) - const selected = normalized.find(item => String(item.id) === String(preferredArtistId || this.data.form.artistId)) - this.setData({ artists: normalized, artistOptions: normalized.map(item => ({ id: item.id, title: item.name, subtitle: item.phone || '' })), selectedArtistName: selected ? selected.name : '', 'form.artistId': selected ? selected.id : '' }) - this.refreshProductOptions() - } catch (error) { wx.showToast({ title: error.message || '美甲师加载失败', icon: 'none' }) } - }, - async loadProducts() { this.setData({ loadingProducts: true }); try { const result = await productsApi.list({ page: 1, size: 100 }); const list = result.list || result || []; this.setData({ products: list, productError: '' }); this.refreshProductOptions() } catch (error) { this.setData({ products: [], allProductOptions: [], productOptions: [], productError: error.message || '项目加载失败' }) } finally { this.setData({ loadingProducts: false }) } }, - refreshProductOptions() { - const options = (this.data.products || []).map(item => { - const artistIds = String(item.bookableArtists || '').split(',').map(id => id.trim()).filter(Boolean) - const artistNames = artistIds.map(id => this.data.artists.find(artist => String(artist.id) === id)).filter(Boolean).map(artist => artist.name) - const tagList = Array.isArray(item.tagList) ? item.tagList : Array.isArray(item.tagInfos) ? item.tagInfos.map(tag => tag.tagName).filter(Boolean) : String(item.tags || '').split(/[;,,、]/).map(tag => tag.trim()).filter(Boolean) - return { - id: item.id, - title: item.title, - price: item.price, - priceText: item.price == null ? '价格待定' : `¥${item.price}`, - coverImage: Array.isArray(item.imageUrls) ? item.imageUrls[0] || '' : '', - durationText: item.approximateDuration || (item.serviceDurationMinutes ? `${item.serviceDurationMinutes}分钟` : '时长待定'), - artistText: artistIds.length ? artistNames.join('、') || `${artistIds.length}位美甲师可做` : '全部美甲师', - tagList: tagList.slice(0, 3) - } - }) - const keyword = String(this.data.productKeyword || '').trim().toLowerCase() - this.setData({ allProductOptions: options, productOptions: options.filter(item => !keyword || `${item.title} ${item.artistText} ${item.tagList.join(' ')}`.toLowerCase().includes(keyword)) }) - }, - async loadCustomers() { this.setData({ loadingCustomers: true }); try { const result = await customersApi.list({ page: 1, size: 30 }); const list = result.list || result || []; const options = list.map(item => ({ id: item.id, title: item.nickname || item.name || item.account, subtitle: item.phone || item.contactPhone || '' })); this.setData({ allCustomerOptions: options, customerOptions: options, customerError: '' }) } catch (error) { this.setData({ customerError: error.message || '客户加载失败' }) } finally { this.setData({ loadingCustomers: false }) } }, - openProductSelector() { this.setData({ manualProductSheetVisible: true }) }, + onLoad(options = {}) { this.setData({ 'form.serviceDate': options.serviceDate || this.data.form.serviceDate, 'form.artistId': options.artistId || '' }); this.loadArtists(options.artistId); this.loadProducts(); this.loadCustomers() }, + async loadArtists(preferredArtistId) { this.setData({ loadingArtists: true }); try { const result = await employeesApi.list({ page: 1, size: 100 }); const list = result.list || result || []; const artists = list.map(item => ({ ...item, name: item.name || item.nickname || item.account || `美甲师${item.id}` })); const selected = artists.find(item => String(item.id) === String(preferredArtistId || this.data.form.artistId)); this.setData({ artists, artistOptions: artists.map(item => ({ id: item.id, title: item.name, subtitle: item.phone || '' })), selectedArtistName: selected ? selected.name : '', 'form.artistId': selected ? selected.id : '', artistError: '' }); this.refreshProductOptions() } catch (error) { this.setData({ artists: [], artistOptions: [], artistError: error.message || '美甲师加载失败' }) } finally { this.setData({ loadingArtists: false }) } }, + async loadProducts() { this.setData({ loadingProducts: true }); try { const result = await productsApi.list({ page: 1, size: 100 }); this.setData({ products: result.list || result || [], productError: '' }); this.refreshProductOptions() } catch (error) { this.setData({ products: [], productOptions: [], productError: error.message || '款式加载失败' }) } finally { this.setData({ loadingProducts: false }) } }, + refreshProductOptions() { const keyword = String(this.data.productKeyword || '').trim().toLowerCase(); const all = (this.data.products || []).map(product => normalizeProduct(product, this.data.artists)); this.setData({ productOptions: all.filter(item => !keyword || `${item.title} ${item.artistText} ${item.durationText} ${item.tagList.join(' ')}`.toLowerCase().includes(keyword)) }) }, + async loadCustomers() { this.setData({ loadingCustomers: true }); try { const result = customersApi.listForAppointment ? await customersApi.listForAppointment({ page: 1, size: 100 }) : await customersApi.list({ page: 1, size: 100 }); const options = (result.list || result || []).map(normalizeCustomer); this.setData({ allCustomerOptions: options, customerOptions: options, customerError: '' }) } catch (error) { this.setData({ customerError: error.message || '客户加载失败' }) } finally { this.setData({ loadingCustomers: false }) } }, + openProductSelector() { this.setData({ manualProductSheetVisible: true, manualProductTitleLength: String(this.data.manualProductDraft.title || '').length }) }, openProductLibrary() { this.setData({ manualProductSheetVisible: false, productSelectorVisible: true }) }, closeProductSelector() { this.setData({ productSelectorVisible: false }) }, closeManualProduct() { this.setData({ manualProductSheetVisible: false }) }, - openManualProduct() { this.setData({ productSelectorVisible: false, manualProductSheetVisible: true }) }, - onManualProductInput(e) { - const field = e.currentTarget && e.currentTarget.dataset.field || e.detail.field - this.setData({ [`manualProductDraft.${field}`]: e.detail.value }) - }, + openManualProduct() { this.setData({ productSelectorVisible: false, manualProductSheetVisible: true, manualProductMoreVisible: false }) }, + toggleManualProductMore() { this.setData({ manualProductMoreVisible: !this.data.manualProductMoreVisible }) }, + onManualProductInput(event) { const field = event.currentTarget.dataset.field; const patch = { [`manualProductDraft.${field}`]: event.detail.value }; if (field === 'title') { patch.manualProductTitleLength = String(event.detail.value || '').length; if (this.data.form.productId) { patch['form.productId'] = ''; patch.selectedProduct = {}; patch.selectedProductTitle = ''; patch.selectedProductPriceText = '' } } this.setData(patch) }, stopTap() {}, stopTouchMove() {}, openArtistSelector() { this.setData({ artistSelectorVisible: true }) }, closeArtistSelector() { this.setData({ artistSelectorVisible: false }) }, openCustomerSelector() { this.setData({ customerSelectorVisible: true }) }, closeCustomerSelector() { this.setData({ customerSelectorVisible: false }) }, - searchProducts(e) { const keyword = String(e.detail.value || '').trim().toLowerCase(); this.setData({ productKeyword: keyword, productOptions: this.data.allProductOptions.filter(item => !keyword || `${item.title} ${item.artistText} ${item.tagList.join(' ')}`.toLowerCase().includes(keyword)) }) }, - searchArtists(e) { const keyword = String(e.detail.value || '').toLowerCase(); this.setData({ artistKeyword: keyword, artistOptions: this.data.artists.map(item => ({ id: item.id, title: item.name, subtitle: item.phone || '' })).filter(item => !keyword || item.title.toLowerCase().includes(keyword)) }) }, - searchCustomers(e) { const keyword = String(e.detail.value || '').toLowerCase(); this.setData({ customerKeyword: keyword, customerOptions: this.data.allCustomerOptions.filter(item => !keyword || String(item.title).toLowerCase().includes(keyword) || String(item.subtitle).includes(keyword)) }) }, - selectProduct(e) { const item = e.detail.item; this.setData({ 'form.productId': item.id, selectedProduct: item, selectedProductTitle: item.title, selectedProductPriceText: item.priceText || (item.price == null ? '价格待定' : `¥${item.price}`), 'form.manualProductTitle': '', manualProductDraft: { title: '', price: '' }, 'form.amount': item.price == null ? this.data.form.amount : String(item.price), productSelectorVisible: false, manualProductSheetVisible: false }) }, - selectArtist(e) { const item = e.detail.item; this.setData({ 'form.artistId': item.id, selectedArtistName: item.title, artistSelectorVisible: false }) }, - selectCustomer(e) { const item = e.detail.item; this.setData({ 'form.customerUserId': item.id, 'form.customerName': item.title, 'form.phone': item.subtitle, customerSelectorVisible: false }) }, - useWalkIn() { this.setData({ 'form.customerUserId': '', 'form.customerName': '', 'form.phone': '', customerSelectorVisible: false }) }, - onCustomerNameInput(e) { this.setData({ 'form.customerName': e.detail.value, 'form.customerUserId': '' }) }, - useManualProduct() { - const title = String(this.data.manualProductDraft.title || '').trim() - const priceText = String(this.data.manualProductDraft.price === undefined ? '' : this.data.manualProductDraft.price).trim() - const price = Number(priceText) - if (!title || !priceText || !Number.isFinite(price) || price < 0) { - wx.showToast({ title: '请填写作品名称和价格', icon: 'none' }) - return - } - this.setData({ 'form.productId': '', 'form.manualProductTitle': title, selectedProduct: {}, selectedProductTitle: '', selectedProductPriceText: `¥${price}`, 'form.amount': String(price), productSelectorVisible: false, manualProductSheetVisible: false }) - }, - onInput(e) { this.setData({ [`form.${e.currentTarget.dataset.field}`]: e.detail.value }) }, - onDateChange(e) { this.setData({ 'form.serviceDate': e.detail.value }) }, - onTimeChange(e) { this.setData({ 'form.serviceTime': e.detail.value }) }, - onArtistChange(e) { const index = Number(e.detail.value); const item = this.data.artists[index] || {}; this.setData({ artistIndex: index, selectedArtistName: item.name || item.nickname || '', 'form.artistId': item.id }) }, - selectStatus(e) { this.setData({ 'form.status': Number(e.currentTarget.dataset.status) }) }, - async submit() { - const form = this.data.form - if (!form.serviceDate || (!form.productId && !form.manualProductTitle) || !form.amount || !form.artistId) { wx.showToast({ title: '请填写项目、金额、日期和美甲师', icon: 'none' }); return } - if (form.phone && !/^1[3-9]\d{9}$/.test(form.phone)) { wx.showToast({ title: '手机号格式不正确', icon: 'none' }); return } - this.setData({ submitting: true }) - try { await planningApi.createBackfillOrder(form); wx.showToast({ title: '补单已保存', icon: 'success' }); const app = getApp(); app.globalData.planningNeedRefresh = true; setTimeout(() => wx.navigateBack(), 500) } - catch (error) { wx.showToast({ title: error.message || '保存失败', icon: 'none' }) } - finally { this.setData({ submitting: false }) } - } + searchProducts(event) { const keyword = String(event.detail.value || '').trim().toLowerCase(); this.setData({ productKeyword: keyword }); this.refreshProductOptions() }, + searchArtists(event) { const keyword = String(event.detail.value || '').toLowerCase(); this.setData({ artistKeyword: keyword, artistOptions: this.data.artists.map(item => ({ id: item.id, title: item.name, subtitle: item.phone || '' })).filter(item => !keyword || item.title.toLowerCase().includes(keyword)) }) }, + searchCustomers(event) { const keyword = String(event.detail.value || '').toLowerCase(); this.setData({ customerKeyword: keyword, customerOptions: this.data.allCustomerOptions.filter(item => !keyword || `${item.name} ${item.phone}`.toLowerCase().includes(keyword)) }) }, + selectProduct(event) { const item = event.detail.item || {}; const duration = String(item.serviceDurationMinutes || String(item.approximateDuration || '').replace(/[^0-9]/g, '') || '60'); this.setData({ 'form.productId': item.id, 'form.manualProductTitle': '', 'form.amount': item.price == null ? this.data.form.amount : String(item.price), 'form.durationMinutes': duration, selectedProduct: item, selectedProductTitle: item.title, selectedProductPriceText: item.priceText || '价格待定', manualProductDraft: { title: '', price: '', durationMinutes: duration, description: '' }, productSelectorVisible: false, manualProductSheetVisible: false }) }, + selectArtist(event) { const item = event.detail.item; this.setData({ 'form.artistId': item.id, selectedArtistName: item.title, artistSelectorVisible: false }) }, + selectCustomer(event) { const item = event.detail.item || {}; this.setData({ 'form.customerUserId': item.id, 'form.customerName': item.name || item.title, 'form.phone': item.phone || '', customerSelectorVisible: false }) }, + useWalkIn() { this.setData({ 'form.customerUserId': '', 'form.customerName': '', 'form.wechatId': '', 'form.phone': '', customerSelectorVisible: false }) }, + onCustomerInput(event) { this.setData({ [`form.${event.currentTarget.dataset.field}`]: event.detail.value, 'form.customerUserId': '' }) }, + useManualProduct() { const title = String(this.data.manualProductDraft.title || '').trim(); const priceText = String(this.data.manualProductDraft.price || this.data.form.amount || '').trim(); const price = Number(priceText); const images = this.data.form.manualProductImages || []; if (this.data.form.productId) { if (!priceText || !Number.isFinite(price) || price < 0) { wx.showToast({ title: '请输入正确的款式价格', icon: 'none' }); return } this.setData({ 'form.amount': priceText, 'form.durationMinutes': String(this.data.manualProductDraft.durationMinutes || '60'), manualProductSheetVisible: false }); return } if (!title && !images.length) { wx.showToast({ title: '请填写款式名称或添加图片', icon: 'none' }); return } if (!priceText || !Number.isFinite(price) || price < 0) { wx.showToast({ title: '请输入正确的款式价格', icon: 'none' }); return } const duration = String(this.data.manualProductDraft.durationMinutes || '60'); this.setData({ 'form.productId': '', 'form.manualProductTitle': title, 'form.manualProductDescription': this.data.manualProductDraft.description || '', 'form.manualProductPrice': priceText, 'form.amount': priceText, 'form.durationMinutes': duration, 'manualProductDraft.price': priceText, selectedProduct: {}, selectedProductTitle: title, selectedProductPriceText: `¥${price}`, productSelectorVisible: false, manualProductSheetVisible: false }) }, + async chooseManualProductImage() { if (this.data.manualImageUploading) return; const remaining = 9 - (this.data.form.manualProductImages || []).length; if (remaining <= 0) { wx.showToast({ title: '最多添加9张图片', icon: 'none' }); return } try { this.setData({ manualImageUploading: true }); const paths = await chooseImages(remaining); for (const filePath of paths) { const result = await uploadObjectFile(filePath); const fileId = result.id || result.fileId; if (!fileId) throw new Error('图片上传成功但未返回文件ID'); this.setData(imagePatch((this.data.form.manualProductImages || []).concat({ fileId: String(fileId), fileUrl: result.fileUrl || result.primaryUrl || '', previewUrl: filePath }))) } } catch (error) { wx.showToast({ title: error.message || '图片上传失败', icon: 'none' }) } finally { this.setData({ manualImageUploading: false }) } }, + removeManualProductImage(event) { const index = Number(event.currentTarget.dataset.index); this.setData(imagePatch((this.data.form.manualProductImages || []).filter((item, itemIndex) => itemIndex !== index))) }, + onManualProductImageError(event) { const index = Number(event.currentTarget.dataset.index); const images = this.data.form.manualProductImages || []; if (!images[index] || !images[index].fileUrl) return; const fallback = images.slice(); fallback[index] = { ...fallback[index], previewUrl: fallback[index].fileUrl }; this.setData(imagePatch(fallback)) }, + onInput(event) { const field = event.currentTarget.dataset.field; const value = event.detail.value; this.setData({ [`form.${field}`]: value, ...(field === 'amount' ? { 'manualProductDraft.price': value } : {}) }) }, + onDateChange(event) { this.setData({ 'form.serviceDate': event.detail.value }) }, + onTimeChange(event) { this.setData({ 'form.serviceTime': event.detail.value }) }, + selectStatus(event) { this.setData({ 'form.status': Number(event.currentTarget.dataset.status) }) }, + async submit() { const form = this.data.form; if (!form.serviceDate || (!form.productId && !String(form.manualProductTitle || '').trim() && !(form.manualProductImages || []).length) || !String(form.amount || '').trim() || !form.artistId) { wx.showToast({ title: '请补全款式、金额、日期和美甲师', icon: 'none' }); return } if (form.phone && !/^1[3-9]\d{9}$/.test(String(form.phone).trim())) { wx.showToast({ title: '请输入正确手机号', icon: 'none' }); return } this.setData({ submitting: true }); try { const payload = { ...form, amount: Number(form.amount), manualProductPrice: Number(form.manualProductPrice || form.amount), durationMinutes: Number(form.durationMinutes) || 60, manualProductImageFileIds: String(form.manualProductImageFileIds || '').trim() || undefined, customerName: String(form.customerName || '').trim() || undefined, wechatId: String(form.wechatId || '').trim() || undefined, phone: String(form.phone || '').trim() || undefined, serviceTime: String(form.serviceTime || '').trim() || undefined }; if (!payload.manualProductTitle && payload.manualProductImageFileIds) payload.manualProductTitle = String(form.customerName || '').trim() || '散客款式'; await planningApi.createBackfillOrder(payload); wx.showToast({ title: '历史补单已保存', icon: 'success' }); const app = getApp(); app.globalData.planningNeedRefresh = true; setTimeout(() => wx.navigateBack(), 500) } catch (error) { wx.showToast({ title: error.message || '保存失败', icon: 'none' }) } finally { this.setData({ submitting: false }) } } }) diff --git a/JC-Salon-WeChat/pages/backfill-order/index.wxml b/JC-Salon-WeChat/pages/backfill-order/index.wxml index 406b5fad..7a105e23 100644 --- a/JC-Salon-WeChat/pages/backfill-order/index.wxml +++ b/JC-Salon-WeChat/pages/backfill-order/index.wxml @@ -1,82 +1,64 @@ - - - - HISTORICAL ORDER - 补录一笔历史订单 + + + + HISTORICAL ORDER + 补录一笔历史订单 - ◷{{form.serviceDate}} + ◷{{form.serviceDate}} - + 美甲款式* - 手动录入为主,也可从款式库快速选择 + - - - 实际成交金额(元) - 元 + + + ✦ + {{selectedProduct.title}}参考价 {{selectedProductPriceText || '待定'}} · 本次 {{form.amount || '待填'}} 元 · {{form.durationMinutes || '60'}} 分钟 + - - 补单备注 -