|
|
@ -40,8 +40,6 @@ Page({ |
|
|
// 商品相关 - 淘宝风格
|
|
|
// 商品相关 - 淘宝风格
|
|
|
goods: [], |
|
|
goods: [], |
|
|
filteredGoods: [], |
|
|
filteredGoods: [], |
|
|
leftColumnGoods: [], |
|
|
|
|
|
rightColumnGoods: [], |
|
|
|
|
|
selectedCategory: '全部', |
|
|
selectedCategory: '全部', |
|
|
categories: ['全部', '粉壳', '褐壳', '绿壳', '白壳'], |
|
|
categories: ['全部', '粉壳', '褐壳', '绿壳', '白壳'], |
|
|
loadingMore: false, |
|
|
loadingMore: false, |
|
|
@ -279,16 +277,13 @@ Page({ |
|
|
|
|
|
|
|
|
this.setData({ |
|
|
this.setData({ |
|
|
goods: updatedGoods |
|
|
goods: updatedGoods |
|
|
}, () => { |
|
|
}, () => { |
|
|
// 重新应用筛选条件,确保显示的商品收藏状态也更新
|
|
|
// 重新应用筛选条件,确保显示的商品收藏状态也更新
|
|
|
const filteredGoods = this.applyFilters(this.data.goods, false); |
|
|
const filteredGoods = this.applyFilters(this.data.goods, false); |
|
|
const { leftColumnGoods, rightColumnGoods } = this.distributeToColumns(filteredGoods); |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
filteredGoods: filteredGoods, |
|
|
filteredGoods: filteredGoods, |
|
|
}); |
|
|
leftColumnGoods: leftColumnGoods, |
|
|
|
|
|
rightColumnGoods: rightColumnGoods |
|
|
|
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
}; |
|
|
}; |
|
|
app.eventBus.on('favoriteChanged', this.favoriteChangedHandler); |
|
|
app.eventBus.on('favoriteChanged', this.favoriteChangedHandler); |
|
|
}, |
|
|
}, |
|
|
@ -367,8 +362,6 @@ Page({ |
|
|
hasMoreData: true, |
|
|
hasMoreData: true, |
|
|
goods: existingGoods, |
|
|
goods: existingGoods, |
|
|
filteredGoods: [], |
|
|
filteredGoods: [], |
|
|
leftColumnGoods: [], |
|
|
|
|
|
rightColumnGoods: [] |
|
|
|
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
const timestamp = new Date().getTime(); |
|
|
const timestamp = new Date().getTime(); |
|
|
@ -529,17 +522,9 @@ Page({ |
|
|
console.log('filteredGoods[1].category:', filteredGoods[1] ? filteredGoods[1].category : 'N/A') |
|
|
console.log('filteredGoods[1].category:', filteredGoods[1] ? filteredGoods[1].category : 'N/A') |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const { leftColumnGoods, rightColumnGoods } = this.distributeToColumns(filteredGoods) |
|
|
|
|
|
console.log('leftColumnGoods 数量:', leftColumnGoods.length) |
|
|
|
|
|
console.log('rightColumnGoods 数量:', rightColumnGoods.length) |
|
|
|
|
|
console.log('leftColumnGoods[0]:', leftColumnGoods[0]) |
|
|
|
|
|
console.log('rightColumnGoods[0]:', rightColumnGoods[0]) |
|
|
|
|
|
|
|
|
|
|
|
this.setData({ |
|
|
this.setData({ |
|
|
goods: updatedGoods, |
|
|
goods: updatedGoods, |
|
|
filteredGoods: filteredGoods, |
|
|
filteredGoods: filteredGoods, |
|
|
leftColumnGoods: leftColumnGoods, |
|
|
|
|
|
rightColumnGoods: rightColumnGoods, |
|
|
|
|
|
loadingMore: false, |
|
|
loadingMore: false, |
|
|
isLoading: false, |
|
|
isLoading: false, |
|
|
page: this.data.page + 1 |
|
|
page: this.data.page + 1 |
|
|
@ -585,13 +570,9 @@ Page({ |
|
|
|
|
|
|
|
|
const filteredGoods = this.applyFilters(updatedGoods, false) |
|
|
const filteredGoods = this.applyFilters(updatedGoods, false) |
|
|
|
|
|
|
|
|
const { leftColumnGoods, rightColumnGoods } = this.distributeToColumns(filteredGoods) |
|
|
|
|
|
|
|
|
|
|
|
this.setData({ |
|
|
this.setData({ |
|
|
goods: updatedGoods, |
|
|
goods: updatedGoods, |
|
|
filteredGoods: filteredGoods, |
|
|
filteredGoods: filteredGoods, |
|
|
leftColumnGoods: leftColumnGoods, |
|
|
|
|
|
rightColumnGoods: rightColumnGoods, |
|
|
|
|
|
loadingMore: false, |
|
|
loadingMore: false, |
|
|
isLoading: false, |
|
|
isLoading: false, |
|
|
page: this.data.page + 1 |
|
|
page: this.data.page + 1 |
|
|
@ -806,16 +787,11 @@ Page({ |
|
|
this.updateGoodsFavoriteStatus(processedGoods, false); |
|
|
this.updateGoodsFavoriteStatus(processedGoods, false); |
|
|
|
|
|
|
|
|
// 应用筛选条件
|
|
|
// 应用筛选条件
|
|
|
let filteredGoods = this.applyFilters(processedGoods, false); |
|
|
const filteredGoods = this.applyFilters(processedGoods, false); |
|
|
|
|
|
|
|
|
// 分配到两列
|
|
|
|
|
|
const { leftColumnGoods, rightColumnGoods } = this.distributeToColumns(filteredGoods); |
|
|
|
|
|
|
|
|
|
|
|
this.setData({ |
|
|
this.setData({ |
|
|
goods: processedGoods, |
|
|
goods: processedGoods, |
|
|
filteredGoods: filteredGoods, |
|
|
filteredGoods: filteredGoods, |
|
|
leftColumnGoods: leftColumnGoods, |
|
|
|
|
|
rightColumnGoods: rightColumnGoods, |
|
|
|
|
|
loadingMore: false, |
|
|
loadingMore: false, |
|
|
isLoading: false, |
|
|
isLoading: false, |
|
|
hasMoreData: false // 缓存数据不分页
|
|
|
hasMoreData: false // 缓存数据不分页
|
|
|
@ -835,6 +811,34 @@ Page({ |
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// 统一字段长度
|
|
|
|
|
|
normalizeFieldLength: function(item) { |
|
|
|
|
|
const normalized = { ...item } |
|
|
|
|
|
|
|
|
|
|
|
// 统一 name 字段长度为 20 字符
|
|
|
|
|
|
if (normalized.name) { |
|
|
|
|
|
normalized.name = normalized.name.length > 20 ? |
|
|
|
|
|
normalized.name.substring(0, 17) + '...' : |
|
|
|
|
|
normalized.name.padEnd(20, ' ') |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 统一 region 字段长度为 15 字符
|
|
|
|
|
|
if (normalized.region) { |
|
|
|
|
|
normalized.region = normalized.region.length > 15 ? |
|
|
|
|
|
normalized.region.substring(0, 12) + '...' : |
|
|
|
|
|
normalized.region.padEnd(15, ' ') |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 统一 grossWeight 字段长度为 10 字符
|
|
|
|
|
|
if (normalized.grossWeight) { |
|
|
|
|
|
normalized.grossWeight = normalized.grossWeight.length > 10 ? |
|
|
|
|
|
normalized.grossWeight.substring(0, 7) + '...' : |
|
|
|
|
|
normalized.grossWeight.padEnd(10, ' ') |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return normalized |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
// 应用筛选条件
|
|
|
// 应用筛选条件
|
|
|
applyFilters: function(goods, shouldSort = true) { |
|
|
applyFilters: function(goods, shouldSort = true) { |
|
|
let filtered = [...goods] |
|
|
let filtered = [...goods] |
|
|
@ -874,6 +878,9 @@ Page({ |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 统一字段长度
|
|
|
|
|
|
filtered = filtered.map(item => this.normalizeFieldLength(item)) |
|
|
|
|
|
|
|
|
return filtered |
|
|
return filtered |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
@ -1019,12 +1026,9 @@ Page({ |
|
|
|
|
|
|
|
|
const filteredGoods = this.applyFilters(this.data.goods, false) |
|
|
const filteredGoods = this.applyFilters(this.data.goods, false) |
|
|
const groupedGoods = this.groupGoodsForStaggeredLayout(filteredGoods) |
|
|
const groupedGoods = this.groupGoodsForStaggeredLayout(filteredGoods) |
|
|
const { leftColumnGoods, rightColumnGoods } = this.distributeToColumns(filteredGoods) |
|
|
|
|
|
this.setData({ |
|
|
this.setData({ |
|
|
filteredGoods: filteredGoods, |
|
|
filteredGoods: filteredGoods, |
|
|
groupedGoods: groupedGoods, |
|
|
groupedGoods: groupedGoods, |
|
|
leftColumnGoods: leftColumnGoods, |
|
|
|
|
|
rightColumnGoods: rightColumnGoods |
|
|
|
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
@ -1059,12 +1063,9 @@ Page({ |
|
|
// 否则仅对本地商品进行筛选
|
|
|
// 否则仅对本地商品进行筛选
|
|
|
const filteredGoods = this.applyFilters(this.data.goods, false) |
|
|
const filteredGoods = this.applyFilters(this.data.goods, false) |
|
|
const groupedGoods = this.groupGoodsForStaggeredLayout(filteredGoods) |
|
|
const groupedGoods = this.groupGoodsForStaggeredLayout(filteredGoods) |
|
|
const { leftColumnGoods, rightColumnGoods } = this.distributeToColumns(filteredGoods) |
|
|
|
|
|
this.setData({ |
|
|
this.setData({ |
|
|
filteredGoods: filteredGoods, |
|
|
filteredGoods: filteredGoods, |
|
|
groupedGoods: groupedGoods, |
|
|
groupedGoods: groupedGoods, |
|
|
leftColumnGoods: leftColumnGoods, |
|
|
|
|
|
rightColumnGoods: rightColumnGoods |
|
|
|
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
@ -1093,8 +1094,6 @@ Page({ |
|
|
hasMoreData: true, |
|
|
hasMoreData: true, |
|
|
goods: [], |
|
|
goods: [], |
|
|
filteredGoods: [], |
|
|
filteredGoods: [], |
|
|
leftColumnGoods: [], |
|
|
|
|
|
rightColumnGoods: [], |
|
|
|
|
|
loadingMore: false, |
|
|
loadingMore: false, |
|
|
isLoading: true |
|
|
isLoading: true |
|
|
}) |
|
|
}) |
|
|
@ -1120,15 +1119,8 @@ Page({ |
|
|
|
|
|
|
|
|
// 查看商品详情
|
|
|
// 查看商品详情
|
|
|
viewGoodsDetail: function(e) { |
|
|
viewGoodsDetail: function(e) { |
|
|
// 检查登录状态
|
|
|
|
|
|
if (this.data.needPhoneAuth) { |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
showOneKeyLoginModal: true |
|
|
|
|
|
}) |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const item = e.currentTarget.dataset.item |
|
|
const item = e.currentTarget.dataset.item |
|
|
|
|
|
|
|
|
// 确保productId存在,优先使用id,其次使用productId
|
|
|
// 确保productId存在,优先使用id,其次使用productId
|
|
|
const productId = String(item.id || item.productId || '') |
|
|
const productId = String(item.id || item.productId || '') |
|
|
|
|
|
|
|
|
@ -1143,8 +1135,10 @@ Page({ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 将完整的商品数据传递给详情页,包含联系人信息,与buyer页面保持一致
|
|
|
// 将完整的商品数据传递给详情页,包含联系人信息,与buyer页面保持一致
|
|
|
|
|
|
// 同时传递登录状态信息,让详情页决定是否显示登录弹窗
|
|
|
|
|
|
const needLogin = this.data.needPhoneAuth; |
|
|
wx.navigateTo({ |
|
|
wx.navigateTo({ |
|
|
url: `/pages/goods-detail/goods-detail?goodsData=${encodeURIComponent(JSON.stringify(item))}&productId=${productId}` |
|
|
url: `/pages/goods-detail/goods-detail?goodsData=${encodeURIComponent(JSON.stringify(item))}&productId=${productId}&needLogin=${needLogin}` |
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
@ -1351,11 +1345,8 @@ Page({ |
|
|
}, () => { |
|
|
}, () => { |
|
|
// 重新应用筛选条件,确保显示的商品收藏状态也更新
|
|
|
// 重新应用筛选条件,确保显示的商品收藏状态也更新
|
|
|
const filteredGoods = this.applyFilters(this.data.goods, false); |
|
|
const filteredGoods = this.applyFilters(this.data.goods, false); |
|
|
const { leftColumnGoods, rightColumnGoods } = this.distributeToColumns(filteredGoods); |
|
|
|
|
|
this.setData({ |
|
|
this.setData({ |
|
|
filteredGoods: filteredGoods, |
|
|
filteredGoods: filteredGoods, |
|
|
leftColumnGoods: leftColumnGoods, |
|
|
|
|
|
rightColumnGoods: rightColumnGoods |
|
|
|
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|