diff --git a/pages/goods/index.js b/pages/goods/index.js index a0190c3..0de3cde 100644 --- a/pages/goods/index.js +++ b/pages/goods/index.js @@ -416,11 +416,21 @@ Page({ publishedGoods = this.filterGoodsList(publishedGoods) } - // 按时间倒序排序 + // 排序逻辑:有销售价格的商品排在最前面,然后按时间倒序排序 publishedGoods.sort((a, b) => { - const timeA = new Date(a.updated_at || a.updatedAt || a.created_at || a.createTime).getTime() - const timeB = new Date(b.updated_at || b.updatedAt || b.created_at || b.createTime).getTime() - return timeB - timeA + // 检查是否有销售价格 + const hasPriceA = !!(a.price && a.price.trim() !== ''); + const hasPriceB = !!(b.price && b.price.trim() !== ''); + + // 有销售价格的排在前面 + if (hasPriceA !== hasPriceB) { + return hasPriceA ? -1 : 1; + } + + // 都有或都没有销售价格时,按时间倒序排序 + const timeA = new Date(a.updated_at || a.updatedAt || a.created_at || a.createTime).getTime(); + const timeB = new Date(b.updated_at || b.updatedAt || b.created_at || b.createTime).getTime(); + return timeB - timeA; }) // 进行分页处理 @@ -474,11 +484,21 @@ Page({ soldOutGoods = this.filterGoodsList(soldOutGoods) } - // 按时间倒序排序 + // 排序逻辑:有销售价格的商品排在最前面,然后按时间倒序排序 soldOutGoods.sort((a, b) => { - const timeA = new Date(a.updated_at || a.updatedAt || a.created_at || a.createTime).getTime() - const timeB = new Date(b.updated_at || b.updatedAt || b.created_at || b.createTime).getTime() - return timeB - timeA + // 检查是否有销售价格 + const hasPriceA = !!(a.price && a.price.trim() !== ''); + const hasPriceB = !!(b.price && b.price.trim() !== ''); + + // 有销售价格的排在前面 + if (hasPriceA !== hasPriceB) { + return hasPriceA ? -1 : 1; + } + + // 都有或都没有销售价格时,按时间倒序排序 + const timeA = new Date(a.updated_at || a.updatedAt || a.created_at || a.createTime).getTime(); + const timeB = new Date(b.updated_at || b.updatedAt || b.created_at || b.createTime).getTime(); + return timeB - timeA; }) // 进行分页处理