|
|
@ -368,7 +368,7 @@ Page({ |
|
|
goods: updatedGoods |
|
|
goods: updatedGoods |
|
|
}, () => { |
|
|
}, () => { |
|
|
// 重新应用筛选条件,确保显示的商品收藏状态也更新
|
|
|
// 重新应用筛选条件,确保显示的商品收藏状态也更新
|
|
|
const filteredGoods = this.applyFilters(this.data.goods, false); |
|
|
const filteredGoods = this.applyFilters(this.data.goods, true); |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
filteredGoods: filteredGoods, |
|
|
filteredGoods: filteredGoods, |
|
|
}); |
|
|
}); |
|
|
@ -463,8 +463,8 @@ Page({ |
|
|
lastDataTimestamp: 0 |
|
|
lastDataTimestamp: 0 |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// 查询published和sold_out状态的商品
|
|
|
// 先只查询published状态的商品
|
|
|
const statusList = ['published', 'sold_out']; |
|
|
const statusList = ['published']; |
|
|
const apiParams = { |
|
|
const apiParams = { |
|
|
timestamp: timestamp, |
|
|
timestamp: timestamp, |
|
|
viewMode: 'shopping', |
|
|
viewMode: 'shopping', |
|
|
@ -688,7 +688,7 @@ Page({ |
|
|
region: product.region ? this.extractProvince(product.region) : '', |
|
|
region: product.region ? this.extractProvince(product.region) : '', |
|
|
grossWeight: product.grossWeight || product.weight || '', |
|
|
grossWeight: product.grossWeight || product.weight || '', |
|
|
displayGrossWeight: product.grossWeight || product.weight || '', |
|
|
displayGrossWeight: product.grossWeight || product.weight || '', |
|
|
status: product.status || 'published', |
|
|
status: product.status, |
|
|
createdAt: product.created_at || product.createTime || null, |
|
|
createdAt: product.created_at || product.createTime || null, |
|
|
reservedCount: product.reservedCount || product.selected || 0, |
|
|
reservedCount: product.reservedCount || product.selected || 0, |
|
|
reservedCountDisplay: product.reservedCount || product.selected || 0, |
|
|
reservedCountDisplay: product.reservedCount || product.selected || 0, |
|
|
@ -797,7 +797,7 @@ Page({ |
|
|
region: product.region ? this.extractProvince(product.region) : '', |
|
|
region: product.region ? this.extractProvince(product.region) : '', |
|
|
grossWeight: product.grossWeight || product.weight || '', |
|
|
grossWeight: product.grossWeight || product.weight || '', |
|
|
displayGrossWeight: product.grossWeight || product.weight || '', |
|
|
displayGrossWeight: product.grossWeight || product.weight || '', |
|
|
status: product.status || 'published', |
|
|
status: product.status, |
|
|
createdAt: product.created_at || product.createTime || null, |
|
|
createdAt: product.created_at || product.createTime || null, |
|
|
reservedCount: product.reservedCount || product.selected || 0, |
|
|
reservedCount: product.reservedCount || product.selected || 0, |
|
|
reservedCountDisplay: product.reservedCount || product.selected || 0, |
|
|
reservedCountDisplay: product.reservedCount || product.selected || 0, |
|
|
@ -930,7 +930,8 @@ Page({ |
|
|
|
|
|
|
|
|
// 加载商品数据 - 优化版带缓存,支持状态优先级
|
|
|
// 加载商品数据 - 优化版带缓存,支持状态优先级
|
|
|
loadGoods: function (isLoadMore = false, forceRefresh = false) { |
|
|
loadGoods: function (isLoadMore = false, forceRefresh = false) { |
|
|
if (isLoadMore && !this.data.hasMoreData) { |
|
|
// 允许继续加载的条件:1. 有更多数据;或者 2. 正在加载售空商品
|
|
|
|
|
|
if (isLoadMore && !this.data.hasMoreData && !this.data.isQueryingSoldOut) { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -946,7 +947,7 @@ Page({ |
|
|
|
|
|
|
|
|
// 如果正在加载sold_out,继续加载sold_out
|
|
|
// 如果正在加载sold_out,继续加载sold_out
|
|
|
if (isLoadMore && this.data.isQueryingSoldOut) { |
|
|
if (isLoadMore && this.data.isQueryingSoldOut) { |
|
|
this.loadSoldOutData(cacheKey, currentKeyword, currentCategory, timestamp, isLoadMore); |
|
|
this.loadSoldOutData(cacheKey, currentKeyword, currentCategory, timestamp, true); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -986,8 +987,8 @@ Page({ |
|
|
|
|
|
|
|
|
console.log('loadGoods - API请求参数:', apiParams); |
|
|
console.log('loadGoods - API请求参数:', apiParams); |
|
|
|
|
|
|
|
|
// 查询published和sold_out状态的商品
|
|
|
// 先只查询published状态的商品
|
|
|
const statusList = ['published', 'sold_out']; |
|
|
const statusList = ['published']; |
|
|
console.log('loadGoods - 查询状态列表:', statusList); |
|
|
console.log('loadGoods - 查询状态列表:', statusList); |
|
|
|
|
|
|
|
|
API.getProductList(statusList, apiParams) |
|
|
API.getProductList(statusList, apiParams) |
|
|
@ -1008,9 +1009,6 @@ Page({ |
|
|
// 只需要判断是否还有下一页,不需要检查当前页数据量是否等于pageSize
|
|
|
// 只需要判断是否还有下一页,不需要检查当前页数据量是否等于pageSize
|
|
|
const publishedHasMore = page < totalPages; |
|
|
const publishedHasMore = page < totalPages; |
|
|
|
|
|
|
|
|
// 当published商品没有更多数据时,查询sold_out商品
|
|
|
|
|
|
const shouldQuerySoldOut = !publishedHasMore; |
|
|
|
|
|
|
|
|
|
|
|
// 更新缓存(加载更多时追加数据)
|
|
|
// 更新缓存(加载更多时追加数据)
|
|
|
const updatedCache = { ...this.data.categoryQueryCache }; |
|
|
const updatedCache = { ...this.data.categoryQueryCache }; |
|
|
if (isLoadMore && updatedCache[cacheKey]) { |
|
|
if (isLoadMore && updatedCache[cacheKey]) { |
|
|
@ -1023,33 +1021,16 @@ Page({ |
|
|
updatedCache[cacheKey] = res.products; |
|
|
updatedCache[cacheKey] = res.products; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 计算sold_out起始页码和每页数量
|
|
|
|
|
|
let soldOutPageNum = 1; |
|
|
|
|
|
let soldOutPageSize = pageSize; |
|
|
|
|
|
if (shouldQuerySoldOut || (!publishedHasMore && isLoadMore)) { |
|
|
|
|
|
// 如果published已无更多数据,查询sold_out商品
|
|
|
|
|
|
soldOutPageNum = isLoadMore ? this.data.soldOutPage + 1 : 1; |
|
|
|
|
|
soldOutPageSize = pageSize; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.setData({ |
|
|
this.setData({ |
|
|
hasMoreData: publishedHasMore || (shouldQuerySoldOut || this.data.isQueryingSoldOut), |
|
|
hasMoreData: publishedHasMore || true, // 当切换到加载售空商品时,保持hasMoreData为true以允许继续加载
|
|
|
isQueryingSoldOut: shouldQuerySoldOut || (!publishedHasMore && isLoadMore), |
|
|
isQueryingSoldOut: !publishedHasMore, // 当已发布商品加载完毕时,切换到加载售空商品
|
|
|
publishedHasMore: publishedHasMore, |
|
|
publishedHasMore: publishedHasMore, |
|
|
soldOutPage: soldOutPageNum, |
|
|
|
|
|
soldOutPageSize: soldOutPageSize, |
|
|
|
|
|
categoryQueryCache: updatedCache, |
|
|
categoryQueryCache: updatedCache, |
|
|
lastDataTimestamp: now, |
|
|
lastDataTimestamp: now, |
|
|
goodsCache: updatedCache[cacheKey] |
|
|
goodsCache: updatedCache[cacheKey] |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
this.processGoodsData(res.products, isLoadMore); |
|
|
this.processGoodsData(res.products, isLoadMore); |
|
|
|
|
|
|
|
|
// 如果需要查询sold_out
|
|
|
|
|
|
if (this.data.isQueryingSoldOut) { |
|
|
|
|
|
this.loadSoldOutData(cacheKey, currentKeyword, currentCategory, timestamp, isLoadMore); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -1205,7 +1186,7 @@ Page({ |
|
|
region: product.region ? this.extractProvince(product.region) : '', |
|
|
region: product.region ? this.extractProvince(product.region) : '', |
|
|
grossWeight: product.grossWeight || product.weight || '', |
|
|
grossWeight: product.grossWeight || product.weight || '', |
|
|
displayGrossWeight: product.grossWeight || product.weight || '', |
|
|
displayGrossWeight: product.grossWeight || product.weight || '', |
|
|
status: product.status || 'published', |
|
|
status: product.status, |
|
|
createdAt: product.created_at || product.createTime || null, |
|
|
createdAt: product.created_at || product.createTime || null, |
|
|
reservedCount: product.reservedCount || product.selected || 0, |
|
|
reservedCount: product.reservedCount || product.selected || 0, |
|
|
reservedCountDisplay: product.reservedCount || product.selected || 0, |
|
|
reservedCountDisplay: product.reservedCount || product.selected || 0, |
|
|
@ -1234,7 +1215,7 @@ Page({ |
|
|
this.updateGoodsFavoriteStatus(processedGoods, false); |
|
|
this.updateGoodsFavoriteStatus(processedGoods, false); |
|
|
|
|
|
|
|
|
// 应用筛选条件
|
|
|
// 应用筛选条件
|
|
|
const filteredGoods = this.applyFilters(processedGoods, false); |
|
|
const filteredGoods = this.applyFilters(processedGoods, true); |
|
|
const groupedGoods = this.groupGoodsForStaggeredLayout(filteredGoods); |
|
|
const groupedGoods = this.groupGoodsForStaggeredLayout(filteredGoods); |
|
|
|
|
|
|
|
|
this.setData({ |
|
|
this.setData({ |
|
|
@ -1388,7 +1369,21 @@ Page({ |
|
|
filtered = Array.from(uniqueGoodsMap.values()); |
|
|
filtered = Array.from(uniqueGoodsMap.values()); |
|
|
|
|
|
|
|
|
if (shouldSort) { |
|
|
if (shouldSort) { |
|
|
filtered.sort((a, b) => { |
|
|
// First, separate items by status
|
|
|
|
|
|
const publishedItems = [] |
|
|
|
|
|
const soldOutItems = [] |
|
|
|
|
|
|
|
|
|
|
|
filtered.forEach(item => { |
|
|
|
|
|
const status = (item.status || '').toLowerCase() |
|
|
|
|
|
if (status === 'published') { |
|
|
|
|
|
publishedItems.push(item) |
|
|
|
|
|
} else if (status === 'sold_out') { |
|
|
|
|
|
soldOutItems.push(item) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
// Define the sorting function for existing criteria
|
|
|
|
|
|
const sortByExistingCriteria = (a, b) => { |
|
|
const reservedCountA = a.reservedCount || 0 |
|
|
const reservedCountA = a.reservedCount || 0 |
|
|
const reservedCountB = b.reservedCount || 0 |
|
|
const reservedCountB = b.reservedCount || 0 |
|
|
if (reservedCountB !== reservedCountA) return reservedCountB - reservedCountA |
|
|
if (reservedCountB !== reservedCountA) return reservedCountB - reservedCountA |
|
|
@ -1400,7 +1395,14 @@ Page({ |
|
|
const createdAtA = new Date(a.createdAt || 0).getTime() |
|
|
const createdAtA = new Date(a.createdAt || 0).getTime() |
|
|
const createdAtB = new Date(b.createdAt || 0).getTime() |
|
|
const createdAtB = new Date(b.createdAt || 0).getTime() |
|
|
return createdAtB - createdAtA |
|
|
return createdAtB - createdAtA |
|
|
}) |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Sort each group by existing criteria
|
|
|
|
|
|
publishedItems.sort(sortByExistingCriteria) |
|
|
|
|
|
soldOutItems.sort(sortByExistingCriteria) |
|
|
|
|
|
|
|
|
|
|
|
// Combine groups: all published first, then all sold_out
|
|
|
|
|
|
filtered = [...publishedItems, ...soldOutItems] |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 统一字段长度
|
|
|
// 统一字段长度
|
|
|
@ -1544,7 +1546,7 @@ Page({ |
|
|
console.log('searchGoods - 本地已有商品数量:', this.data.goods.length); |
|
|
console.log('searchGoods - 本地已有商品数量:', this.data.goods.length); |
|
|
|
|
|
|
|
|
// 先对本地已加载的商品进行过滤
|
|
|
// 先对本地已加载的商品进行过滤
|
|
|
const filteredGoods = this.applyFilters(this.data.goods, false); |
|
|
const filteredGoods = this.applyFilters(this.data.goods, true); |
|
|
|
|
|
|
|
|
console.log('searchGoods - 本地过滤结果数量:', filteredGoods.length); |
|
|
console.log('searchGoods - 本地过滤结果数量:', filteredGoods.length); |
|
|
|
|
|
|
|
|
@ -1896,7 +1898,7 @@ Page({ |
|
|
goods: updatedGoodsList |
|
|
goods: updatedGoodsList |
|
|
}, () => { |
|
|
}, () => { |
|
|
// 重新应用筛选条件,确保显示的商品收藏状态也更新
|
|
|
// 重新应用筛选条件,确保显示的商品收藏状态也更新
|
|
|
const filteredGoods = this.applyFilters(this.data.goods, false); |
|
|
const filteredGoods = this.applyFilters(this.data.goods, true); |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
filteredGoods: filteredGoods, |
|
|
filteredGoods: filteredGoods, |
|
|
}); |
|
|
}); |
|
|
|