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