From 367310efdce8d887ca1e2f63fea0f9e6fa9fad60 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: Thu, 4 Dec 2025 09:32:12 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=AE=9E=E7=8E=B0=E5=AE=8C=E5=85=A8?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/buyer/index.js | 59 ++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/pages/buyer/index.js b/pages/buyer/index.js index 322f26e..852f4d7 100644 --- a/pages/buyer/index.js +++ b/pages/buyer/index.js @@ -1070,8 +1070,6 @@ Page({ searchKeyword: searchKeyword }) - const { goods } = this.data - // 如果搜索词为空,重置分页并重新加载所有数据 if (!searchKeyword.trim()) { console.log('搜索词为空,重置分页状态并重新加载数据'); @@ -1091,22 +1089,13 @@ Page({ return } - // ✅ 修改:实时过滤当前已加载的商品(前端搜索) - // 注意:这是在前端对已加载数据进行搜索,如果要搜索全部数据需要后端支持 - const filtered = goods.filter(item => - (item.name && item.name.toLowerCase().includes(searchKeyword.toLowerCase())) || - (item.spec && item.spec.toLowerCase().includes(searchKeyword.toLowerCase())) || - (item.yolk && item.yolk.toLowerCase().includes(searchKeyword.toLowerCase())) - ) - - this.setData({ - filteredGoods: filtered - }) + // 实时搜索时不进行前端过滤,仅在用户点击搜索按钮时才向服务器请求完整结果 + // 这样可以确保搜索结果的完整性和准确性 }, // 搜索商品 searchGoods() { - const { searchKeyword, goods, totalGoods } = this.data + const { searchKeyword } = this.data // 如果搜索词为空,重置分页并重新加载 if (!searchKeyword.trim()) { @@ -1114,7 +1103,8 @@ Page({ this.setData({ page: 1, hasMoreData: true, - selectedCategory: '全部' + selectedCategory: '全部', + searchKeyword: '' }, () => { this.loadGoods().then(() => { console.log('搜索重置后数据加载完成'); @@ -1126,25 +1116,30 @@ Page({ return } - // ✅ 添加:搜索范围提示 - if (goods.length < totalGoods) { - wx.showToast({ - title: `正在${goods.length}个已加载商品中搜索`, - icon: 'none', - duration: 1500 - }); - } - - // ✅ 修改:在当前已加载商品中搜索(前端搜索) - const filtered = goods.filter(item => - (item.name && item.name.toLowerCase().includes(searchKeyword.toLowerCase())) || - (item.spec && item.spec.toLowerCase().includes(searchKeyword.toLowerCase())) || - (item.yolk && item.yolk.toLowerCase().includes(searchKeyword.toLowerCase())) - ) + // 显示正在搜索的提示 + wx.showLoading({ + title: '正在搜索中...', + mask: true + }); + // ✅ 修改:向服务器发送搜索请求,获取完整的搜索结果 + // 重置分页状态,获取第一页的搜索结果 this.setData({ - filteredGoods: filtered - }) + page: 1, + hasMoreData: true + }, () => { + this.loadGoods().then(() => { + console.log('搜索结果加载完成'); + wx.hideLoading(); + }).catch(err => { + console.error('搜索结果加载失败:', err); + wx.hideLoading(); + wx.showToast({ + title: '搜索失败,请重试', + icon: 'none' + }); + }); + }); }, From dc2de7f7eab06efbd9585cbc954429e5009fa937 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: Thu, 4 Dec 2025 09:41:15 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=8F=AA=E6=A3=80=E6=B5=8B=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93product=E8=A1=A8=E7=9A=84productName=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/buyer/index.js | 54 ++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/pages/buyer/index.js b/pages/buyer/index.js index 852f4d7..37d4270 100644 --- a/pages/buyer/index.js +++ b/pages/buyer/index.js @@ -1070,6 +1070,8 @@ Page({ searchKeyword: searchKeyword }) + const { goods } = this.data + // 如果搜索词为空,重置分页并重新加载所有数据 if (!searchKeyword.trim()) { console.log('搜索词为空,重置分页状态并重新加载数据'); @@ -1089,13 +1091,19 @@ Page({ return } - // 实时搜索时不进行前端过滤,仅在用户点击搜索按钮时才向服务器请求完整结果 - // 这样可以确保搜索结果的完整性和准确性 + // ✅ 修改:只搜索商品名称字段(对应数据库product表的productName字段) + const filtered = goods.filter(item => + item.name && item.name.toLowerCase().includes(searchKeyword.toLowerCase()) + ) + + this.setData({ + filteredGoods: filtered + }) }, // 搜索商品 searchGoods() { - const { searchKeyword } = this.data + const { searchKeyword, goods, totalGoods } = this.data // 如果搜索词为空,重置分页并重新加载 if (!searchKeyword.trim()) { @@ -1103,8 +1111,7 @@ Page({ this.setData({ page: 1, hasMoreData: true, - selectedCategory: '全部', - searchKeyword: '' + selectedCategory: '全部' }, () => { this.loadGoods().then(() => { console.log('搜索重置后数据加载完成'); @@ -1116,30 +1123,23 @@ Page({ return } - // 显示正在搜索的提示 - wx.showLoading({ - title: '正在搜索中...', - mask: true - }); + // ✅ 添加:搜索范围提示 + if (goods.length < totalGoods) { + wx.showToast({ + title: `正在${goods.length}个已加载商品中搜索`, + icon: 'none', + duration: 1500 + }); + } + + // ✅ 修改:只搜索商品名称字段(对应数据库product表的productName字段) + const filtered = goods.filter(item => + item.name && item.name.toLowerCase().includes(searchKeyword.toLowerCase()) + ) - // ✅ 修改:向服务器发送搜索请求,获取完整的搜索结果 - // 重置分页状态,获取第一页的搜索结果 this.setData({ - page: 1, - hasMoreData: true - }, () => { - this.loadGoods().then(() => { - console.log('搜索结果加载完成'); - wx.hideLoading(); - }).catch(err => { - console.error('搜索结果加载失败:', err); - wx.hideLoading(); - wx.showToast({ - title: '搜索失败,请重试', - icon: 'none' - }); - }); - }); + filteredGoods: filtered + }) }, From e777d4c89fb749e0f2e2bc593e5205c6b9328a73 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: Thu, 4 Dec 2025 09:51:19 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E9=A1=B5=EF=BC=9A=E5=8D=8A=E9=A1=B5=E7=A9=BA?= =?UTF-8?q?=E7=99=BD=E5=8C=BA=E5=9F=9F=E6=B7=BB=E5=8A=A0=E6=B7=A1=E5=8C=96?= =?UTF-8?q?=E6=96=87=E6=9C=AC=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/buyer/index.wxml | 5 +++++ pages/buyer/index.wxss | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/pages/buyer/index.wxml b/pages/buyer/index.wxml index 88b3626..72ac622 100644 --- a/pages/buyer/index.wxml +++ b/pages/buyer/index.wxml @@ -92,6 +92,11 @@ + + + 已加载全部商品 + + diff --git a/pages/buyer/index.wxss b/pages/buyer/index.wxss index 2e8865f..f2a7f32 100644 --- a/pages/buyer/index.wxss +++ b/pages/buyer/index.wxss @@ -468,4 +468,11 @@ button:after { height: 25vh; width: 100%; box-sizing: border-box; +} + +/* 半页空白页样式 */ +.half-page-blank { + height: 32vh; + width: 100%; + box-sizing: border-box; } \ No newline at end of file From b0073bba59911e8de9d36d5e25e840e72cd43555 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: Thu, 4 Dec 2025 09:57:52 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=95=86=E5=93=81?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E5=BC=B9=E7=AA=97=E5=9B=BE=E7=89=87=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E6=94=BE=E5=A4=A7=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/buyer/index.wxml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/buyer/index.wxml b/pages/buyer/index.wxml index 72ac622..b79a9b1 100644 --- a/pages/buyer/index.wxml +++ b/pages/buyer/index.wxml @@ -217,7 +217,7 @@ - + From d06510eaf05a644da5db6b02311b3bd5daa3f75d 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: Thu, 4 Dec 2025 10:12:33 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=9B=BE=E7=89=87=E9=A2=84=E8=A7=88?= =?UTF-8?q?=E5=BC=B9=E7=AA=97=E7=BD=AE=E9=A1=B6=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/buyer/index.wxml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/buyer/index.wxml b/pages/buyer/index.wxml index b79a9b1..d9d22aa 100644 --- a/pages/buyer/index.wxml +++ b/pages/buyer/index.wxml @@ -106,7 +106,7 @@ - +