Browse Source

Merge branch 'Xfy' of http://8.137.125.67:4000/SwtTt29/Mini-Program into Xfy

pull/11/head
Default User 2 months ago
parent
commit
1eece04703
  1. 35
      pages/index/index.js

35
pages/index/index.js

@ -777,8 +777,8 @@ Page({
isLoading: false, isLoading: false,
isRefreshing: false, isRefreshing: false,
// 根据当前是否在查询售空商品来更新对应的页码 // 根据当前是否在查询售空商品来更新对应的页码
// soldOutPage 已经在 loadSoldOutData 函数中直接更新
page: this.data.isQueryingSoldOut ? this.data.page : this.data.page + 1, 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() lastDataTimestamp: new Date().getTime()
}) })
@ -1046,10 +1046,8 @@ Page({
// 如果有published商品,直接处理 // 如果有published商品,直接处理
if (res.success && res.products && res.products.length > 0) { if (res.success && res.products && res.products.length > 0) {
console.log('有published商品,处理商品数据'); console.log('有published商品,处理商品数据');
const totalGoods = res.total || 0; // 使用返回的商品数量来判断是否还有下一页
const totalPages = res.totalPages || Math.ceil(totalGoods / pageSize); const publishedHasMore = res.products.length === pageSize;
// 只需要判断是否还有下一页,不需要检查当前页数据量是否等于pageSize
const publishedHasMore = page < totalPages;
// 更新缓存(加载更多时追加数据) // 更新缓存(加载更多时追加数据)
const updatedCache = { ...this.data.categoryQueryCache }; const updatedCache = { ...this.data.categoryQueryCache };
@ -1069,7 +1067,9 @@ Page({
publishedHasMore: publishedHasMore, publishedHasMore: publishedHasMore,
categoryQueryCache: updatedCache, categoryQueryCache: updatedCache,
lastDataTimestamp: now, lastDataTimestamp: now,
goodsCache: updatedCache[cacheKey] goodsCache: updatedCache[cacheKey],
// 当切换到加载售空商品时,重置售空商品的页码为1
soldOutPage: !publishedHasMore ? 1 : this.data.soldOutPage
}); });
this.processGoodsData(res.products, isLoadMore); this.processGoodsData(res.products, isLoadMore);
@ -1120,9 +1120,8 @@ Page({
console.log('soldOutRes.products.length:', soldOutRes.products ? soldOutRes.products.length : 'undefined'); console.log('soldOutRes.products.length:', soldOutRes.products ? soldOutRes.products.length : 'undefined');
if (soldOutRes.success && soldOutRes.products && soldOutRes.products.length > 0) { if (soldOutRes.success && soldOutRes.products && soldOutRes.products.length > 0) {
const soldOutTotal = soldOutRes.total || 0; // 使用返回的商品数量来判断是否还有下一页
const soldOutTotalPages = soldOutRes.totalPages || Math.ceil(soldOutTotal / pageSize); const soldOutHasMore = soldOutRes.products.length === pageSize;
const soldOutHasMore = soldOutPageNum < soldOutTotalPages;
// 更新缓存 // 更新缓存
const updatedCache = { ...this.data.categoryQueryCache }; const updatedCache = { ...this.data.categoryQueryCache };
@ -1132,15 +1131,17 @@ Page({
updatedCache[cacheKey] = [...existingCache, ...uniqueSoldOutProducts]; updatedCache[cacheKey] = [...existingCache, ...uniqueSoldOutProducts];
this.processGoodsData(uniqueSoldOutProducts, isLoadMore);
this.setData({ this.setData({
hasMoreData: soldOutHasMore, hasMoreData: soldOutHasMore,
isQueryingSoldOut: soldOutHasMore, isQueryingSoldOut: soldOutHasMore,
categoryQueryCache: updatedCache, categoryQueryCache: updatedCache,
lastDataTimestamp: new Date().getTime(), 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); console.log('sold_out数据加载完成,总商品数:', updatedCache[cacheKey].length, 'hasMoreData:', soldOutHasMore);
} else { } else {
console.log('没有找到更多sold_out商品'); console.log('没有找到更多sold_out商品');
@ -1318,18 +1319,14 @@ Page({
console.log('applyFilters - 开始过滤,原始商品数量:', goods.length, '关键词:', this.data.searchKeyword); console.log('applyFilters - 开始过滤,原始商品数量:', goods.length, '关键词:', this.data.searchKeyword);
// 筛选条件:销售价为空并且没有联系人信息的不显示在主页上 // 移除所有不必要的过滤条件,确保所有published和sold_out状态的商品都能显示
filtered = filtered.filter(item => { filtered = filtered.filter(item => {
// 广告位不受影响 // 广告位不受影响
if (item.isAd) { if (item.isAd) {
return true; return true;
} }
// 销售价为空 // 所有published和sold_out状态的商品都保留
const hasEmptyPrice = !item.price || item.price === '' || parseFloat(item.price) === 0; return true;
// 没有联系人信息
const hasNoContact = !item.product_contact || item.product_contact === '' || !item.contact_phone || item.contact_phone === '';
// 只保留:销售价不为空 或 有联系人信息 的商品
return !(hasEmptyPrice && hasNoContact);
}); });
if (this.data.selectedCategory !== '全部') { if (this.data.selectedCategory !== '全部') {

Loading…
Cancel
Save