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

Loading…
Cancel
Save