From 6c9108235b5dcbc395130368433d63c345bedb19 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 17:04:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=95=86=E5=93=81=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E9=A1=B5=E9=9D=A2=E9=87=87=E8=B4=AD=E4=BB=B7=E5=92=8C?= =?UTF-8?q?=E8=A7=84=E6=A0=BC=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/goods-update/goods-update.js | 31 +++++++++++++++++++++++----- pages/goods-update/goods-update.wxml | 6 +++++- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/pages/goods-update/goods-update.js b/pages/goods-update/goods-update.js index ae92231..6e489e5 100644 --- a/pages/goods-update/goods-update.js +++ b/pages/goods-update/goods-update.js @@ -814,6 +814,16 @@ Page({ // 分割规格字符串,支持多种逗号分隔符:英文逗号、中文逗号、全角逗号 if (spec) { specArray = spec.split(/[,,、]/).map(item => item.trim()).filter(item => item); + } else { + // 如果没有spec,尝试从weightQuantityData中获取规格 + if (goodsDetail.weightQuantityData && goodsDetail.weightQuantityData.length > 0) { + specArray = goodsDetail.weightQuantityData.map(item => { + // 移除净重/毛重前缀 + return item.weightSpec.replace(/^(净重|毛重)/, ''); + }); + } else { + specArray = ['']; + } } // 从weightQuantityData中获取每个规格对应的价格和采购价格 @@ -822,11 +832,22 @@ Page({ for (let i = 0; i < specArray.length; i++) { // 查找当前规格对应的weightQuantityData项 const currentSpec = specArray[i]; - const matchingItem = goodsDetail.weightQuantityData.find(item => - item.weightSpec === currentSpec || - item.weightSpec.includes(currentSpec) || - currentSpec.includes(item.weightSpec) - ); + // 处理规格前缀匹配问题,支持带净重/毛重前缀和不带前缀的情况 + const matchingItem = goodsDetail.weightQuantityData.find(item => { + // 完全匹配 + if (item.weightSpec === currentSpec) return true; + + // 处理带前缀的情况 + const hasPrefix = item.weightSpec.includes('净重') || item.weightSpec.includes('毛重'); + if (hasPrefix) { + // 如果weightSpec有前缀,移除前缀后比较 + const specWithoutPrefix = item.weightSpec.replace(/^(净重|毛重)/, ''); + return specWithoutPrefix === currentSpec; + } else { + // 如果weightSpec没有前缀,检查currentSpec是否包含weightSpec + return currentSpec.includes(item.weightSpec); + } + }); if (matchingItem) { // 如果找到匹配项,使用匹配项的价格和采购价格 diff --git a/pages/goods-update/goods-update.wxml b/pages/goods-update/goods-update.wxml index d46b629..4844de5 100644 --- a/pages/goods-update/goods-update.wxml +++ b/pages/goods-update/goods-update.wxml @@ -218,7 +218,7 @@ {{item}} - (采购价:¥{{editSupply.costpriceArray[index]}}) + (采购价:¥{{editSupply.costpriceArray[index]}}) + + {{editSupply.specArray[0] || ''}} + (采购价:¥{{editSupply.costpriceArray[0] || editSupply.costprice}}) +