Browse Source

修复售空状态下规格显示错误的问题

main
TraeAI 7 hours ago
parent
commit
fdbd49a0ae
  1. 33
      pages/freight-calculator/index.js
  2. 2
      pages/freight-calculator/index.wxml
  3. 20
      pages/goods-detail/goods-detail.js

33
pages/freight-calculator/index.js

@ -17,6 +17,8 @@ Page({
district: '',
detail: ''
},
// 是否从货源详情页进入(携带产品ID)
isFromGoodsDetail: false,
// 货物信息
goodsInfo: {
weight: '', // 重量(kg)
@ -155,7 +157,10 @@ Page({
// 初始化地址选择器数据
this.initRegionData();
// 如果从商品详情页跳转过来,获取商品信息
// 如果从商品详情页或货源详情页跳转过来,设置标志并获取商品信息
if (options.goodsId || options.goodsInfo || options.goodsData) {
this.setData({ isFromGoodsDetail: true });
if (options.goodsId) {
this.loadGoodsInfo(options.goodsId);
}
@ -164,10 +169,15 @@ Page({
if (options.goodsInfo) {
try {
const goodsInfo = JSON.parse(options.goodsInfo);
let weight = goodsInfo.grossWeight || '';
if (!weight && goodsInfo.netWeight && goodsInfo.quantity) {
// 计算总重量:净重(斤) * 件数 / 2(换算为公斤)
weight = (parseFloat(goodsInfo.netWeight) * parseInt(goodsInfo.quantity)) / 2;
}
this.setData({
selectedGoods: goodsInfo,
'goodsInfo.weight': goodsInfo.grossWeight || '',
'goodsInfo.quantity': 1
'goodsInfo.weight': weight,
'goodsInfo.quantity': goodsInfo.quantity || 1
});
} catch (e) {
console.error('解析货源信息失败:', e);
@ -192,10 +202,16 @@ Page({
}
}
let weight = goodsData.grossWeight || '';
if (!weight && goodsData.netWeight && goodsData.quantity) {
// 计算总重量:净重(斤) * 件数 / 2(换算为公斤)
weight = (parseFloat(goodsData.netWeight) * parseInt(goodsData.quantity)) / 2;
}
this.setData({
selectedGoods: goodsData,
'goodsInfo.weight': goodsData.grossWeight || '',
'goodsInfo.quantity': 1
'goodsInfo.weight': weight,
'goodsInfo.quantity': goodsData.quantity || 1
});
// 设置出发地为商品所在地
@ -216,6 +232,7 @@ Page({
console.error('解析货源信息失败:', e);
}
}
}
// 加载历史记录(在设置完 selectedGoods 后)
this.loadHistoryRecords();
@ -266,6 +283,12 @@ Page({
this.setData({
'goodsInfo.weight': goodsItem.grossWeight
});
} else if (goodsItem.netWeight && goodsItem.quantity) {
// 计算总重量:净重(斤) * 件数 / 2(换算为公斤)
const totalWeight = (parseFloat(goodsItem.netWeight) * parseInt(goodsItem.quantity)) / 2;
this.setData({
'goodsInfo.weight': totalWeight
});
}
}
},

2
pages/freight-calculator/index.wxml

@ -2,7 +2,7 @@
<view class="container">
<view class="main-content">
<!-- 出发地信息 -->
<view class="section">
<view class="section" wx:if="{{!isFromGoodsDetail}}">
<text class="section-title">出发地</text>
<view class="address-form">
<view class="form-item address-row">

20
pages/goods-detail/goods-detail.js

@ -2223,13 +2223,27 @@ Page({
const price = priceArray[index] || '';
// 使用实际的quantity字段,而不是从spec中提取
const soldQuantity = quantityArray[index] || product.quantity || 0;
// 处理规格显示格式 - 根据内容类型添加相应前缀
let weightSpecDisplay = '';
if (spec) {
if (spec.includes('净重')) {
// 如果已包含"净重"前缀,保持不变
weightSpecDisplay = spec;
} else if (spec.includes('毛重')) {
// 如果已包含"毛重"前缀,保持不变
weightSpecDisplay = spec;
} else {
// 如果都不包含,默认为净重
weightSpecDisplay = `净重${spec}`;
}
}
return {
weightSpec: spec.includes('毛重') ? spec : `毛重${spec}`,
weightSpec: weightSpecDisplay,
quantity: soldQuantity,
price: price,
display: price ?
`${spec.includes('毛重') ? spec : `毛重${spec}`}【已售${soldQuantity}件】¥${price}` :
`${spec.includes('毛重') ? spec : `毛重${spec}`}【已售${soldQuantity}件】`,
`${weightSpecDisplay}【已售${soldQuantity}件】¥${price}` :
`${weightSpecDisplay}【已售${soldQuantity}件】`,
isSoldOut: true
};
});

Loading…
Cancel
Save