|
|
@ -266,7 +266,7 @@ Page({ |
|
|
goods: updatedGoods |
|
|
goods: updatedGoods |
|
|
}, () => { |
|
|
}, () => { |
|
|
// 重新应用筛选条件,确保显示的商品收藏状态也更新
|
|
|
// 重新应用筛选条件,确保显示的商品收藏状态也更新
|
|
|
const filteredGoods = this.applyFilters(this.data.goods); |
|
|
const filteredGoods = this.applyFilters(this.data.goods, false); |
|
|
const { leftColumnGoods, rightColumnGoods } = this.distributeToColumns(filteredGoods); |
|
|
const { leftColumnGoods, rightColumnGoods } = this.distributeToColumns(filteredGoods); |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
filteredGoods: filteredGoods, |
|
|
filteredGoods: filteredGoods, |
|
|
@ -326,11 +326,13 @@ Page({ |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const existingGoods = [...this.data.goods] |
|
|
|
|
|
|
|
|
this.setData({ |
|
|
this.setData({ |
|
|
isRefreshing: true, |
|
|
isRefreshing: true, |
|
|
page: 1, |
|
|
page: 1, |
|
|
hasMoreData: true, |
|
|
hasMoreData: true, |
|
|
goods: [], |
|
|
goods: existingGoods, |
|
|
filteredGoods: [], |
|
|
filteredGoods: [], |
|
|
leftColumnGoods: [], |
|
|
leftColumnGoods: [], |
|
|
rightColumnGoods: [] |
|
|
rightColumnGoods: [] |
|
|
@ -350,7 +352,7 @@ Page({ |
|
|
this.setData({ isRefreshing: false }) |
|
|
this.setData({ isRefreshing: false }) |
|
|
|
|
|
|
|
|
if (res.success && res.products) { |
|
|
if (res.success && res.products) { |
|
|
this.processGoodsData(res.products, false) |
|
|
this.processRefreshData(res.products, existingGoods) |
|
|
wx.showToast({ |
|
|
wx.showToast({ |
|
|
title: '刷新成功', |
|
|
title: '刷新成功', |
|
|
icon: 'success', |
|
|
icon: 'success', |
|
|
@ -503,6 +505,57 @@ Page({ |
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// 处理刷新数据 - 查重并保持原有商品
|
|
|
|
|
|
processRefreshData: function(newProducts, existingGoods) { |
|
|
|
|
|
let newGoods = newProducts.map(product => { |
|
|
|
|
|
const imageUrls = product.imageUrls || product.images || []; |
|
|
|
|
|
const formattedImageUrls = Array.isArray(imageUrls) ? imageUrls : [imageUrls]; |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
|
...product, |
|
|
|
|
|
fullRegion: product.region || '', |
|
|
|
|
|
region: product.region ? this.extractProvince(product.region) : '', |
|
|
|
|
|
grossWeight: product.grossWeight || product.weight || '', |
|
|
|
|
|
displayGrossWeight: product.grossWeight || product.weight || '', |
|
|
|
|
|
status: product.status || 'published', |
|
|
|
|
|
createdAt: product.created_at || product.createTime || null, |
|
|
|
|
|
reservedCount: product.reservedCount || product.selected || 0, |
|
|
|
|
|
reservedCountDisplay: product.reservedCount || product.selected || 0, |
|
|
|
|
|
sales: product.sales || product.reservedCount || Math.floor(Math.random() * 1000) + 100, |
|
|
|
|
|
product_contact: product.product_contact || '', |
|
|
|
|
|
contact_phone: product.contact_phone || '', |
|
|
|
|
|
supplyStatus: product.supplyStatus || '', |
|
|
|
|
|
sourceType: product.sourceType || '', |
|
|
|
|
|
negotiateStatus: '可议价', |
|
|
|
|
|
isReserved: false, |
|
|
|
|
|
isFavorite: false, |
|
|
|
|
|
currentImageIndex: 0, |
|
|
|
|
|
imageUrls: formattedImageUrls |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
newGoods = newGoods.filter(item => (item.status || '').toLowerCase() !== 'hidden') |
|
|
|
|
|
|
|
|
|
|
|
const existingIds = new Set(existingGoods.filter(item => !item.isAd).map(item => item.id)); |
|
|
|
|
|
const uniqueNewGoods = newGoods.filter(item => !existingIds.has(item.id)); |
|
|
|
|
|
|
|
|
|
|
|
const updatedGoods = [...existingGoods, ...uniqueNewGoods] |
|
|
|
|
|
|
|
|
|
|
|
const filteredGoods = this.applyFilters(updatedGoods, false) |
|
|
|
|
|
|
|
|
|
|
|
const { leftColumnGoods, rightColumnGoods } = this.distributeToColumns(filteredGoods) |
|
|
|
|
|
|
|
|
|
|
|
this.setData({ |
|
|
|
|
|
goods: updatedGoods, |
|
|
|
|
|
filteredGoods: filteredGoods, |
|
|
|
|
|
leftColumnGoods: leftColumnGoods, |
|
|
|
|
|
rightColumnGoods: rightColumnGoods, |
|
|
|
|
|
loadingMore: false, |
|
|
|
|
|
isLoading: false, |
|
|
|
|
|
page: this.data.page + 1 |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
// 插入广告位数据
|
|
|
// 插入广告位数据
|
|
|
insertAdSlots: function(goods) { |
|
|
insertAdSlots: function(goods) { |
|
|
if (!goods || goods.length === 0) return goods |
|
|
if (!goods || goods.length === 0) return goods |
|
|
@ -770,7 +823,7 @@ Page({ |
|
|
app.globalData.showTabBar = true; |
|
|
app.globalData.showTabBar = true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const filteredGoods = this.applyFilters(this.data.goods) |
|
|
const filteredGoods = this.applyFilters(this.data.goods, false) |
|
|
const groupedGoods = this.groupGoodsForStaggeredLayout(filteredGoods) |
|
|
const groupedGoods = this.groupGoodsForStaggeredLayout(filteredGoods) |
|
|
const { leftColumnGoods, rightColumnGoods } = this.distributeToColumns(filteredGoods) |
|
|
const { leftColumnGoods, rightColumnGoods } = this.distributeToColumns(filteredGoods) |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
@ -809,7 +862,7 @@ Page({ |
|
|
this.refreshGoodsList(); |
|
|
this.refreshGoodsList(); |
|
|
} else { |
|
|
} else { |
|
|
// 否则仅对本地商品进行筛选
|
|
|
// 否则仅对本地商品进行筛选
|
|
|
const filteredGoods = this.applyFilters(this.data.goods) |
|
|
const filteredGoods = this.applyFilters(this.data.goods, false) |
|
|
const groupedGoods = this.groupGoodsForStaggeredLayout(filteredGoods) |
|
|
const groupedGoods = this.groupGoodsForStaggeredLayout(filteredGoods) |
|
|
const { leftColumnGoods, rightColumnGoods } = this.distributeToColumns(filteredGoods) |
|
|
const { leftColumnGoods, rightColumnGoods } = this.distributeToColumns(filteredGoods) |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
@ -1063,7 +1116,7 @@ Page({ |
|
|
goods: updatedGoodsList |
|
|
goods: updatedGoodsList |
|
|
}, () => { |
|
|
}, () => { |
|
|
// 重新应用筛选条件,确保显示的商品收藏状态也更新
|
|
|
// 重新应用筛选条件,确保显示的商品收藏状态也更新
|
|
|
const filteredGoods = this.applyFilters(this.data.goods); |
|
|
const filteredGoods = this.applyFilters(this.data.goods, false); |
|
|
const { leftColumnGoods, rightColumnGoods } = this.distributeToColumns(filteredGoods); |
|
|
const { leftColumnGoods, rightColumnGoods } = this.distributeToColumns(filteredGoods); |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
filteredGoods: filteredGoods, |
|
|
filteredGoods: filteredGoods, |
|
|
|