Browse Source

Fix filter function for goods list

pull/19/head
徐飞洋 1 month ago
parent
commit
59ac5ddc60
  1. 30
      pages/goods/index.js

30
pages/goods/index.js

@ -558,13 +558,17 @@ Page({
if (!isLoadMore && this.isCacheValid()) {
const cache = this.data.cache
// 重新应用当前筛选条件到缓存数据
const allCachedGoods = [...cache.publishedGoods, ...cache.soldOutGoods]
const filteredGoods = this.filterGoodsList(allCachedGoods)
this.setData({
goodsList: [...cache.publishedGoods, ...cache.soldOutGoods],
goodsList: filteredGoods,
publishedLoaded: true,
soldOutLoaded: true,
publishedHasMore: false,
soldOutHasMore: false,
total: cache.publishedGoods.length + cache.soldOutGoods.length
total: filteredGoods.length
})
return
@ -586,9 +590,12 @@ Page({
this.data.searchKeyword
)
newGoods = result.goods
// 应用筛选逻辑
let filteredGoods = this.filterGoodsList(result.goods)
newGoods = filteredGoods
updatedPublishedHasMore = result.hasMore
publishedGoods = result.goods
publishedGoods = filteredGoods
// 如果是加载更多,追加数据;否则替换数据
this.setData({
@ -620,9 +627,12 @@ Page({
this.data.searchKeyword
)
newGoods = result.goods
// 应用筛选逻辑
let filteredGoods = this.filterGoodsList(result.goods)
newGoods = filteredGoods
updatedSoldOutHasMore = result.hasMore
soldOutGoods = result.goods
soldOutGoods = filteredGoods
// 追加售空商品数据
this.setData({
@ -649,9 +659,13 @@ Page({
const publishedResult = await this.loadGoodsData(1, 1000, 'published', this.data.searchKeyword)
const soldOutResult = await this.loadGoodsData(1, 1000, 'sold_out', this.data.searchKeyword)
// 应用筛选逻辑到缓存数据
const filteredPublishedGoods = this.filterGoodsList(publishedResult.goods)
const filteredSoldOutGoods = this.filterGoodsList(soldOutResult.goods)
this.setData({
'cache.publishedGoods': publishedResult.goods,
'cache.soldOutGoods': soldOutResult.goods,
'cache.publishedGoods': filteredPublishedGoods,
'cache.soldOutGoods': filteredSoldOutGoods,
'cache.timestamp': Date.now()
})
}

Loading…
Cancel
Save