Browse Source

优化商品详情页价格对比功能,添加基于category字段的相同种类筛选

pull/12/head
徐飞洋 2 months ago
parent
commit
b7f4955edc
  1. 10
      pages/goods-detail/goods-detail.js

10
pages/goods-detail/goods-detail.js

@ -2493,6 +2493,9 @@ Page({
// 提取当前商品的净重规格(如"净重41-42") // 提取当前商品的净重规格(如"净重41-42")
const currentWeightSpecs = currentSpecifications.map(item => item.weightSpec.trim()) const currentWeightSpecs = currentSpecifications.map(item => item.weightSpec.trim())
.filter(spec => spec && (spec.includes('净重') || spec.includes('毛重'))); .filter(spec => spec && (spec.includes('净重') || spec.includes('毛重')));
// 提取当前商品的种类(category)
const currentCategory = currentGoods.category || '';
console.log('当前商品的种类:', currentCategory);
// 调用API获取首页商品列表 // 调用API获取首页商品列表
API.getProducts() API.getProducts()
@ -2547,7 +2550,12 @@ Page({
formattedDate: formattedDate // 添加格式化的日期字段 formattedDate: formattedDate // 添加格式化的日期字段
}; };
}).filter(goods => { }).filter(goods => {
// 只有当当前商品有明确的规格时才进行筛选 // 1. 先过滤相同种类(category)的商品
if (currentCategory && goods.category !== currentCategory) {
return false;
}
// 2. 只有当当前商品有明确的规格时才进行筛选
if (currentWeightSpecs.length === 0) { if (currentWeightSpecs.length === 0) {
return true; return true;
} }

Loading…
Cancel
Save