Browse Source

修复毛重显示错误:支持净重和毛重数据的正确识别和处理

pull/3/head
徐飞洋 2 months ago
parent
commit
512f86d61a
  1. 23
      pages/goods-detail/goods-detail.js

23
pages/goods-detail/goods-detail.js

@ -111,12 +111,17 @@ function processWeightAndQuantityData(weightSpecString, quantityString, specStri
console.log(`处理第${i}组数据: weightSpec=${weightSpec}, quantity=${quantity}`); console.log(`处理第${i}组数据: weightSpec=${weightSpec}, quantity=${quantity}`);
// 处理净重规格显示格式 - 保持原始格式,如果包含"净重"则保持,否则添加 // 处理净重规格显示格式 - 根据内容类型添加相应前缀
let weightSpecDisplay = ''; let weightSpecDisplay = '';
if (weightSpec) { if (weightSpec) {
if (weightSpec.includes('净重')) { if (weightSpec.includes('净重')) {
// 如果已包含"净重"前缀,保持不变
weightSpecDisplay = weightSpec;
} else if (weightSpec.includes('毛重')) {
// 如果已包含"毛重"前缀,保持不变
weightSpecDisplay = weightSpec; weightSpecDisplay = weightSpec;
} else { } else {
// 如果都不包含,默认为净重
weightSpecDisplay = `净重${weightSpec}`; weightSpecDisplay = `净重${weightSpec}`;
} }
} }
@ -338,20 +343,20 @@ Page({
console.log('product.minOrder:', product.minOrder); console.log('product.minOrder:', product.minOrder);
console.log('product.grossWeight:', grossWeightValue); console.log('product.grossWeight:', grossWeightValue);
if (product.spec && typeof product.spec === 'string' && product.spec.includes('净重')) { if (product.spec && typeof product.spec === 'string' && (product.spec.includes('净重') || product.spec.includes('毛重'))) {
// 如果规格字段包含净重信息,则使用该字段作为重规格数据 // 如果规格字段包含净重或毛重信息,则使用该字段作为重规格数据
weightSpecString = product.spec; weightSpecString = product.spec;
console.log('使用规格字段作为重规格数据:', weightSpecString); console.log('使用规格字段作为重规格数据:', weightSpecString);
} else if (product.specification && typeof product.specification === 'string' && product.specification.includes('净重')) { } else if (product.specification && typeof product.specification === 'string' && (product.specification.includes('净重') || product.specification.includes('毛重'))) {
// 检查specification字段 // 检查specification字段
weightSpecString = product.specification; weightSpecString = product.specification;
console.log('使用specification字段作为重规格数据:', weightSpecString); console.log('使用specification字段作为重规格数据:', weightSpecString);
} else if (grossWeightValue) { } else if (grossWeightValue) {
// 如果有单独的净重字段,则使用净重字段 // 如果有单独的重量字段,则使用该字段
weightSpecString = grossWeightValue; weightSpecString = grossWeightValue;
console.log('使用重字段作为重规格数据:', weightSpecString); console.log('使用重字段作为重规格数据:', weightSpecString);
} else { } else {
console.log('未找到重规格数据'); console.log('未找到重规格数据');
} }
// 处理件数数据 // 处理件数数据

Loading…
Cancel
Save