|
|
|
@ -532,27 +532,46 @@ Page({ |
|
|
|
const categories = this.data.categories; |
|
|
|
const selectedCategory = this.data.selectedCategory; |
|
|
|
|
|
|
|
categories.forEach(cat => { |
|
|
|
if (cat === '全部') { |
|
|
|
categorizedGoods[cat] = updatedGoods; |
|
|
|
} else if (cat === selectedCategory) { |
|
|
|
categorizedGoods[cat] = updatedGoods.filter(item => item.isAd || !item.category || item.category === cat); |
|
|
|
} else { |
|
|
|
categorizedGoods[cat] = []; |
|
|
|
} |
|
|
|
}); |
|
|
|
// 如果是首次加载全部数据,需要把返回的所有数据按实际分类存储
|
|
|
|
if (selectedCategory === '全部' && !isLoadMore) { |
|
|
|
categories.forEach(cat => { |
|
|
|
if (cat === '全部') { |
|
|
|
categorizedGoods[cat] = updatedGoods; |
|
|
|
} else { |
|
|
|
categorizedGoods[cat] = updatedGoods.filter(item => item.isAd || item.category === cat); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else { |
|
|
|
// 只更新当前选中的分类
|
|
|
|
categories.forEach(cat => { |
|
|
|
if (cat === '全部') { |
|
|
|
categorizedGoods[cat] = updatedGoods; |
|
|
|
} else if (cat === selectedCategory) { |
|
|
|
categorizedGoods[cat] = updatedGoods.filter(item => item.isAd || !item.category || item.category === cat); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
// 应用地区筛选后的分类数据
|
|
|
|
const filteredByRegion = this.applyRegionFilter(updatedGoods); |
|
|
|
categories.forEach(cat => { |
|
|
|
if (cat !== '全部') { |
|
|
|
if (cat === selectedCategory) { |
|
|
|
categorizedGoods[cat + '_filtered'] = filteredByRegion.filter(item => item.isAd || !item.category || item.category === cat); |
|
|
|
} else { |
|
|
|
categorizedGoods[cat + '_filtered'] = []; |
|
|
|
|
|
|
|
if (selectedCategory === '全部' && !isLoadMore) { |
|
|
|
categories.forEach(cat => { |
|
|
|
if (cat !== '全部') { |
|
|
|
categorizedGoods[cat + '_filtered'] = filteredByRegion.filter(item => item.isAd || item.category === cat); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
categories.forEach(cat => { |
|
|
|
if (cat !== '全部') { |
|
|
|
if (cat === selectedCategory) { |
|
|
|
categorizedGoods[cat + '_filtered'] = filteredByRegion.filter(item => item.isAd || !item.category || item.category === cat); |
|
|
|
} else { |
|
|
|
categorizedGoods[cat + '_filtered'] = []; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
// 根据当前选中的分类和地区筛选获取商品
|
|
|
|
let filteredGoods; |
|
|
|
@ -719,13 +738,16 @@ Page({ |
|
|
|
const timestamp = new Date().getTime(); |
|
|
|
const currentPage = isLoadMore ? this.data.page : 1 |
|
|
|
|
|
|
|
// 首次加载时获取全部数据,在本地进行分类
|
|
|
|
const shouldLoadAll = !isLoadMore && this.data.selectedCategory === '全部'; |
|
|
|
|
|
|
|
API.getProductList('published', { |
|
|
|
timestamp: timestamp, |
|
|
|
viewMode: 'shopping', |
|
|
|
page: currentPage, |
|
|
|
pageSize: this.data.pageSize, |
|
|
|
keyword: this.data.searchKeyword, |
|
|
|
category: this.data.selectedCategory === '全部' ? '' : this.data.selectedCategory |
|
|
|
category: shouldLoadAll ? '' : this.data.selectedCategory |
|
|
|
}) |
|
|
|
.then(res => { |
|
|
|
wx.hideLoading(); |
|
|
|
|