From b1b885801e0e4176b4c0849580015dd413618137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=A3=9E=E6=B4=8B?= <15778543+xufeiyang6017@user.noreply.gitee.com> Date: Tue, 13 Jan 2026 16:28:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=95=86=E5=93=81=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=8E=92=E5=BA=8F=E9=80=BB=E8=BE=91=EF=BC=8C=E6=9C=89?= =?UTF-8?q?=E9=94=80=E5=94=AE=E4=BB=B7=E6=A0=BC=E7=9A=84=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=8E=92=E5=9C=A8=E6=9C=80=E5=89=8D=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/goods/index.js | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) 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; }) // 进行分页处理