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}}) +