From c75b79701f81c1c0225516e0e57645870c90feb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=A3=9E=E6=B4=8B?= <15778543+xufeiyang6017@user.noreply.gitee.com> Date: Fri, 9 Jan 2026 11:37:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=8A=A8=E6=80=81=E4=BB=B7?= =?UTF-8?q?=E6=A0=BC=E8=BE=93=E5=85=A5=E6=A1=86=E5=8A=9F=E8=83=BD=E5=B9=B6?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/goods-update/goods-update.js | 122 +++++++++++++++++++++------ pages/goods-update/goods-update.wxml | 30 ++++++- pages/goods-update/goods-update.wxss | 20 ++++- 3 files changed, 140 insertions(+), 32 deletions(-) diff --git a/pages/goods-update/goods-update.js b/pages/goods-update/goods-update.js index c04790f..d0032fd 100644 --- a/pages/goods-update/goods-update.js +++ b/pages/goods-update/goods-update.js @@ -762,20 +762,45 @@ Page({ // 打开编辑弹窗(实际执行打开操作的内部方法) openEditModal: function(goodsDetail) { + const spec = goodsDetail.spec || ''; + let specArray = []; + let priceArray = []; + + // 分割规格字符串,支持多种逗号分隔符:英文逗号、中文逗号、全角逗号 + if (spec) { + specArray = spec.split(/[,,、]/).map(item => item.trim()).filter(item => item); + } + + // 处理价格字段 + const price = goodsDetail.price || ''; + if (price) { + if (typeof price === 'string' && price.includes(',')) { + // 如果价格是字符串且包含逗号,分割成数组 + priceArray = price.split(',').map(item => item.trim()).filter(item => item); + } else { + // 如果只有一个价格,为所有规格设置相同的价格 + priceArray = Array(specArray.length).fill(String(price)); + } + } + + // 创建editSupply对象 + const editSupply = { + id: goodsDetail.id || goodsDetail.productId, + imageUrls: goodsDetail.imageUrls || [], + name: goodsDetail.name || '', + spec: spec, + specArray: specArray, // 新增:规格数组 + priceArray: priceArray, // 新增:价格数组 + minOrder: goodsDetail.minOrder || '', + yolk: goodsDetail.yolk || '', + region: goodsDetail.region || '', + grossWeight: goodsDetail.grossWeight || '', + product_contact: goodsDetail.product_contact || '', + contact_phone: goodsDetail.contact_phone || '' + }; + this.setData({ - editSupply: { - id: goodsDetail.id || goodsDetail.productId, - imageUrls: goodsDetail.imageUrls || [], - name: goodsDetail.name || '', - price: goodsDetail.price || '', - minOrder: goodsDetail.minOrder || '', - yolk: goodsDetail.yolk || '', - spec: goodsDetail.spec || '', - region: goodsDetail.region || '', - grossWeight: goodsDetail.grossWeight || '', - product_contact: goodsDetail.product_contact || '', - contact_phone: goodsDetail.contact_phone || '' - }, + editSupply: editSupply, showEditModal: true }); }, @@ -792,8 +817,51 @@ Page({ console.log('保存编辑'); const editSupply = this.data.editSupply; - // 验证必填字段 - if (!editSupply.price) { + // 处理价格字段,将价格数组合并成字符串 + let priceStr = ''; + if (editSupply.priceArray && editSupply.priceArray.length > 0) { + // 移除空值 + const validPrices = editSupply.priceArray.filter(price => price && price.trim() !== ''); + + // 验证必填字段 + if (validPrices.length === 0) { + wx.showToast({ + title: '请填写销售价格', + icon: 'none', + duration: 2000 + }); + return; + } + + // 验证价格是否为有效数字 + for (const price of validPrices) { + const priceNum = parseFloat(price); + if (isNaN(priceNum) || priceNum < 0) { + wx.showToast({ + title: '请填写有效的价格', + icon: 'none', + duration: 2000 + }); + return; + } + } + + // 合并价格数组为字符串 + priceStr = validPrices.join(','); + } else if (editSupply.price) { + // 兼容旧的单个价格字段 + const priceNum = parseFloat(editSupply.price); + if (isNaN(priceNum) || priceNum < 0) { + wx.showToast({ + title: '请填写有效的价格', + icon: 'none', + duration: 2000 + }); + return; + } + priceStr = editSupply.price; + } else { + // 没有价格 wx.showToast({ title: '请填写销售价格', icon: 'none', @@ -802,17 +870,6 @@ Page({ return; } - // 验证价格是否为有效数字 - const priceNum = parseFloat(editSupply.price); - if (isNaN(priceNum) || priceNum < 0) { - wx.showToast({ - title: '请填写有效的价格', - icon: 'none', - duration: 2000 - }); - return; - } - // 验证联系人 if (!editSupply.product_contact || editSupply.product_contact === '联系人信息暂不可用') { wx.showToast({ @@ -850,7 +907,7 @@ Page({ // 使用新的快速更新接口,只更新价格、联系人和电话 const updateData = { productId: productId, - price: editSupply.price, + price: priceStr, product_contact: editSupply.product_contact || '', contact_phone: editSupply.contact_phone || '', }; @@ -1104,6 +1161,17 @@ Page({ }); }, + // 价格输入处理(用于动态生成的价格输入框) + onEditPriceInput: function(e) { + const index = e.currentTarget.dataset.index; + const value = e.detail.value; + + // 更新价格数组中的对应元素 + this.setData({ + [`editSupply.priceArray[${index}]`]: value + }); + }, + // 打开规格选择弹窗(编辑模式) onEditSpecChange: function() { console.log('打开规格选择弹窗(编辑模式)'); diff --git a/pages/goods-update/goods-update.wxml b/pages/goods-update/goods-update.wxml index d1dfb16..60506bf 100644 --- a/pages/goods-update/goods-update.wxml +++ b/pages/goods-update/goods-update.wxml @@ -209,9 +209,33 @@ - - 销售价格 - + + + + + {{item}} + + + + + + + + 联系人 diff --git a/pages/goods-update/goods-update.wxss b/pages/goods-update/goods-update.wxss index 37a161d..ddf3a33 100644 --- a/pages/goods-update/goods-update.wxss +++ b/pages/goods-update/goods-update.wxss @@ -277,9 +277,25 @@ video.slider-media .wx-video-volume-icon { align-items: flex-start; } +.dynamic-price-container { + margin-bottom: 30rpx; +} + .price-item { - display: flex; - align-items: center; + margin-bottom: 20rpx; +} + +.spec-label { + font-size: 28rpx; + color: #666; + margin-bottom: 10rpx; + display: block; + word-wrap: break-word; + word-break: break-all; +} + +.price-input { + width: 100%; } .goods-info::after {