|
|
|
@ -73,6 +73,8 @@ Page({ |
|
|
|
|
|
|
|
// 从原始商品数据中计算价格范围
|
|
|
|
const allProducts = wx.getStorageSync('allProducts') || []; |
|
|
|
console.log('本地存储中的商品总数:', allProducts.length); |
|
|
|
console.log('当前分类:', this.data.category); |
|
|
|
if (allProducts.length > 0) { |
|
|
|
// 过滤出当前分类下的商品
|
|
|
|
const categoryProducts = allProducts.filter(product => { |
|
|
|
@ -80,19 +82,26 @@ Page({ |
|
|
|
const productCategory = String(product.category).trim(); |
|
|
|
return productCategory === this.data.category; |
|
|
|
}); |
|
|
|
console.log('当前分类下的商品数量:', categoryProducts.length); |
|
|
|
console.log('当前分类下的商品详情:', categoryProducts); |
|
|
|
|
|
|
|
// 按规格分组计算平均价格
|
|
|
|
const specPriceMap = {}; |
|
|
|
categoryProducts.forEach(product => { |
|
|
|
console.log('处理商品:', product.productName || product.name, '价格:', product.price, '规格:', product.specification || product.spec); |
|
|
|
if (product.price && (product.specification || product.spec)) { |
|
|
|
const priceStr = String(product.price).trim(); |
|
|
|
const specStr = String(product.specification || product.spec).trim(); |
|
|
|
|
|
|
|
console.log('商品价格字符串:', priceStr, '规格字符串:', specStr); |
|
|
|
|
|
|
|
// 处理逗号分隔的多个价格
|
|
|
|
const priceArray = priceStr.split(',').map(p => p.trim()).filter(p => p && p.trim() !== ''); |
|
|
|
console.log('处理后的价格数组:', priceArray); |
|
|
|
|
|
|
|
// 处理逗号分隔的多个规格
|
|
|
|
let specs = specStr.split(',').map(spec => spec.trim()).filter(spec => spec.length > 0); |
|
|
|
console.log('处理后的规格数组:', specs); |
|
|
|
|
|
|
|
// 进一步处理规格,确保每个规格都是独立的
|
|
|
|
const processedSpecs = []; |
|
|
|
@ -106,9 +115,11 @@ Page({ |
|
|
|
} |
|
|
|
}); |
|
|
|
specs = processedSpecs; |
|
|
|
console.log('最终规格数组:', specs); |
|
|
|
|
|
|
|
// 将规格和价格配对
|
|
|
|
specs.forEach((spec, index) => { |
|
|
|
console.log('处理规格:', spec, '对应价格索引:', index); |
|
|
|
if (spec.length > 0 && index < priceArray.length) { |
|
|
|
const price = priceArray[index]; |
|
|
|
if (price && price.trim() !== '') { |
|
|
|
@ -116,6 +127,7 @@ Page({ |
|
|
|
if (!isNaN(priceValue)) { |
|
|
|
// 解析规格
|
|
|
|
const specInfo = this.parseSpecification(spec); |
|
|
|
console.log('解析规格结果:', specInfo); |
|
|
|
|
|
|
|
// 价格<10的需要按照公式计算
|
|
|
|
let finalPrice = priceValue; |
|
|
|
@ -127,6 +139,7 @@ Page({ |
|
|
|
// 毛重:(规格平均值 - 5) × 价格
|
|
|
|
finalPrice = (specInfo.avg - 5) * priceValue; |
|
|
|
} |
|
|
|
console.log('价格计算:', priceValue, '->', finalPrice); |
|
|
|
} |
|
|
|
|
|
|
|
// 按规格分组存储价格
|
|
|
|
@ -134,10 +147,19 @@ Page({ |
|
|
|
specPriceMap[spec] = []; |
|
|
|
} |
|
|
|
specPriceMap[spec].push(finalPrice); |
|
|
|
console.log('存储价格:', finalPrice, '到规格:', spec); |
|
|
|
} else { |
|
|
|
console.log('价格解析失败:', price); |
|
|
|
} |
|
|
|
} else { |
|
|
|
console.log('价格为空或无效:', price); |
|
|
|
} |
|
|
|
} else { |
|
|
|
console.log('规格长度为0或价格索引超出范围:', spec.length, index, priceArray.length); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else { |
|
|
|
console.log('商品缺少价格或规格:', !product.price ? '无价格' : '', !product.specification && !product.spec ? '无规格' : ''); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
|