Browse Source

添加商品时保持原有排列顺序

pull/1/head
徐飞洋 2 months ago
parent
commit
530844e57d
  1. 6
      pages/index/index.js

6
pages/index/index.js

@ -481,7 +481,7 @@ Page({
updatedGoods = newGoods
}
const filteredGoods = this.applyFilters(updatedGoods)
const filteredGoods = this.applyFilters(updatedGoods, !isLoadMore)
console.log('filteredGoods 数量:', filteredGoods.length)
console.log('filteredGoods[0]:', filteredGoods[0])
console.log('filteredGoods[1]:', filteredGoods[1])
@ -618,7 +618,7 @@ Page({
},
// 应用筛选条件
applyFilters: function(goods) {
applyFilters: function(goods, shouldSort = true) {
let filtered = [...goods]
if (this.data.selectedCategory !== '全部') {
@ -640,6 +640,7 @@ Page({
filtered = filtered.filter(item => item.isAd || (item.region && item.region.includes(selectedRegion)))
}
if (shouldSort) {
filtered.sort((a, b) => {
const reservedCountA = a.reservedCount || 0
const reservedCountB = b.reservedCount || 0
@ -653,6 +654,7 @@ Page({
const createdAtB = new Date(b.createdAt || 0).getTime()
return createdAtB - createdAtA
})
}
return filtered
},

Loading…
Cancel
Save