From ab68e12123fdb4a80993b12f5ff2901c44dab19e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=A3=9E=E6=B4=8B?= <15778543+xufeiyang6017@user.noreply.gitee.com> Date: Fri, 9 Jan 2026 16:45:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=95=86=E5=93=81=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E5=88=86=E9=A1=B5=E9=97=AE=E9=A2=98=EF=BC=8C=E7=A1=AE?= =?UTF-8?q?=E4=BF=9D=E6=89=80=E6=9C=89published=E5=92=8Csold=5Fout?= =?UTF-8?q?=E5=95=86=E5=93=81=E6=AD=A3=E7=A1=AE=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/index.js | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/pages/index/index.js b/pages/index/index.js index d606077..de7690c 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -777,8 +777,8 @@ Page({ isLoading: false, isRefreshing: false, // 根据当前是否在查询售空商品来更新对应的页码 + // soldOutPage 已经在 loadSoldOutData 函数中直接更新 page: this.data.isQueryingSoldOut ? this.data.page : this.data.page + 1, - soldOutPage: this.data.isQueryingSoldOut ? this.data.soldOutPage + 1 : this.data.soldOutPage, lastDataTimestamp: new Date().getTime() }) @@ -1046,10 +1046,8 @@ Page({ // 如果有published商品,直接处理 if (res.success && res.products && res.products.length > 0) { console.log('有published商品,处理商品数据'); - const totalGoods = res.total || 0; - const totalPages = res.totalPages || Math.ceil(totalGoods / pageSize); - // 只需要判断是否还有下一页,不需要检查当前页数据量是否等于pageSize - const publishedHasMore = page < totalPages; + // 使用返回的商品数量来判断是否还有下一页 + const publishedHasMore = res.products.length === pageSize; // 更新缓存(加载更多时追加数据) const updatedCache = { ...this.data.categoryQueryCache }; @@ -1069,7 +1067,9 @@ Page({ publishedHasMore: publishedHasMore, categoryQueryCache: updatedCache, lastDataTimestamp: now, - goodsCache: updatedCache[cacheKey] + goodsCache: updatedCache[cacheKey], + // 当切换到加载售空商品时,重置售空商品的页码为1 + soldOutPage: !publishedHasMore ? 1 : this.data.soldOutPage }); this.processGoodsData(res.products, isLoadMore); @@ -1120,9 +1120,8 @@ Page({ console.log('soldOutRes.products.length:', soldOutRes.products ? soldOutRes.products.length : 'undefined'); if (soldOutRes.success && soldOutRes.products && soldOutRes.products.length > 0) { - const soldOutTotal = soldOutRes.total || 0; - const soldOutTotalPages = soldOutRes.totalPages || Math.ceil(soldOutTotal / pageSize); - const soldOutHasMore = soldOutPageNum < soldOutTotalPages; + // 使用返回的商品数量来判断是否还有下一页 + const soldOutHasMore = soldOutRes.products.length === pageSize; // 更新缓存 const updatedCache = { ...this.data.categoryQueryCache }; @@ -1132,15 +1131,17 @@ Page({ updatedCache[cacheKey] = [...existingCache, ...uniqueSoldOutProducts]; + this.processGoodsData(uniqueSoldOutProducts, isLoadMore); + this.setData({ hasMoreData: soldOutHasMore, isQueryingSoldOut: soldOutHasMore, categoryQueryCache: updatedCache, lastDataTimestamp: new Date().getTime(), - goodsCache: updatedCache[cacheKey] + goodsCache: updatedCache[cacheKey], + // 直接更新售空商品的页码 + soldOutPage: soldOutPageNum + 1 }); - - this.processGoodsData(uniqueSoldOutProducts, isLoadMore); console.log('sold_out数据加载完成,总商品数:', updatedCache[cacheKey].length, 'hasMoreData:', soldOutHasMore); } else { console.log('没有找到更多sold_out商品'); @@ -1318,18 +1319,14 @@ Page({ console.log('applyFilters - 开始过滤,原始商品数量:', goods.length, '关键词:', this.data.searchKeyword); - // 筛选条件:销售价为空并且没有联系人信息的不显示在主页上 + // 移除所有不必要的过滤条件,确保所有published和sold_out状态的商品都能显示 filtered = filtered.filter(item => { // 广告位不受影响 if (item.isAd) { return true; } - // 销售价为空 - const hasEmptyPrice = !item.price || item.price === '' || parseFloat(item.price) === 0; - // 没有联系人信息 - const hasNoContact = !item.product_contact || item.product_contact === '' || !item.contact_phone || item.contact_phone === ''; - // 只保留:销售价不为空 或 有联系人信息 的商品 - return !(hasEmptyPrice && hasNoContact); + // 所有published和sold_out状态的商品都保留 + return true; }); if (this.data.selectedCategory !== '全部') {