Browse Source

修复商品更新页面采购价和规格显示问题

pull/11/head
徐飞洋 2 months ago
parent
commit
6c9108235b
  1. 31
      pages/goods-update/goods-update.js
  2. 6
      pages/goods-update/goods-update.wxml

31
pages/goods-update/goods-update.js

@ -814,6 +814,16 @@ Page({
// 分割规格字符串,支持多种逗号分隔符:英文逗号、中文逗号、全角逗号 // 分割规格字符串,支持多种逗号分隔符:英文逗号、中文逗号、全角逗号
if (spec) { if (spec) {
specArray = spec.split(/[,,、]/).map(item => item.trim()).filter(item => item); 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中获取每个规格对应的价格和采购价格 // 从weightQuantityData中获取每个规格对应的价格和采购价格
@ -822,11 +832,22 @@ Page({
for (let i = 0; i < specArray.length; i++) { for (let i = 0; i < specArray.length; i++) {
// 查找当前规格对应的weightQuantityData项 // 查找当前规格对应的weightQuantityData项
const currentSpec = specArray[i]; const currentSpec = specArray[i];
const matchingItem = goodsDetail.weightQuantityData.find(item => // 处理规格前缀匹配问题,支持带净重/毛重前缀和不带前缀的情况
item.weightSpec === currentSpec || const matchingItem = goodsDetail.weightQuantityData.find(item => {
item.weightSpec.includes(currentSpec) || // 完全匹配
currentSpec.includes(item.weightSpec) 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) { if (matchingItem) {
// 如果找到匹配项,使用匹配项的价格和采购价格 // 如果找到匹配项,使用匹配项的价格和采购价格

6
pages/goods-update/goods-update.wxml

@ -218,7 +218,7 @@
<view class="price-item" wx:for="{{editSupply.specArray}}" wx:key="index"> <view class="price-item" wx:for="{{editSupply.specArray}}" wx:key="index">
<view class="spec-label"> <view class="spec-label">
{{item}} {{item}}
<text class="costprice-info" wx:if="{{editSupply.costpriceArray[index]}}">(采购价:¥{{editSupply.costpriceArray[index]}})</text> <text class="costprice-info" wx:if="{{editSupply.costpriceArray[index] !== undefined && editSupply.costpriceArray[index] !== null && editSupply.costpriceArray[index] !== ''}}">(采购价:¥{{editSupply.costpriceArray[index]}})</text>
</view> </view>
<input <input
class="edit-form-input price-input" class="edit-form-input price-input"
@ -233,6 +233,10 @@
</block> </block>
<!-- 单个规格时显示普通输入框 --> <!-- 单个规格时显示普通输入框 -->
<block wx:else> <block wx:else>
<view class="spec-label single-spec-label">
{{editSupply.specArray[0] || ''}}
<text class="costprice-info" wx:if="{{editSupply.costpriceArray[0] || editSupply.costprice}}">(采购价:¥{{editSupply.costpriceArray[0] || editSupply.costprice}})</text>
</view>
<input <input
class="edit-form-input" class="edit-form-input"
type="text" type="text"

Loading…
Cancel
Save