From fddb82e680eec9ea98a79c2b64fdc00a42d95a39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B0=E9=A6=99=E7=90=AA?= <624506849@qq.com> Date: Thu, 3 Sep 2026 17:17:11 +0800 Subject: [PATCH] =?UTF-8?q?refactor(GoodsClassNav):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=93=81=E7=89=8CID=E5=A4=84=E7=90=86=E4=B8=8E=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 重构品牌ID的获取方式,使用新方法 appendBrandIdsByNames 简化逻辑 - 更新多选确认逻辑,避免重复选择相同类型 - 调整标签内容显示逻辑,确保品牌标签在选择时正确显示 - 修复商品列表页的分页参数,确保从第一页开始加载数据 --- buyer/src/components/nav/GoodsClassNav.vue | 49 ++++++++++++---------- buyer/src/pages/GoodsList.vue | 4 +- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/buyer/src/components/nav/GoodsClassNav.vue b/buyer/src/components/nav/GoodsClassNav.vue index 9fb4d5bf..baefe88e 100644 --- a/buyer/src/components/nav/GoodsClassNav.vue +++ b/buyer/src/components/nav/GoodsClassNav.vue @@ -291,8 +291,12 @@ export default { this.multSelected.push(item); } } else { + const type = this.tagsContent[index].key; + if (this.selectedItem.some((selected) => selected.type === type)) { + return; + } this.selectedItem.push({ - type: this.tagsContent[index].key, + type, name: item }); @@ -300,12 +304,7 @@ export default { if (index === 0) { // 如果是品牌,获取品牌id - - let brands = this.tagsContent[0].values; - - brands.forEach((val) => { - if (val.name === item) this.brandIds.push(val.value); - }); + this.appendBrandIdsByNames([item]); } } }, @@ -336,19 +335,19 @@ export default { }, sure (index) { // 多选确认按钮 + const type = this.tagsContent[index].key; + if (this.selectedItem.some((selected) => selected.type === type)) { + this.cancel(); + return; + } this.selectedItem.push({ - type: this.tagsContent[index].key, + type, name: this.multSelected.join('、') }); if (index === 0) { // 如果是品牌,获取品牌id - - let brands = this.tagsContent[0].values; - - brands.forEach((val) => { - if (this.multSelected.includes(val.name)) this.brandIds.push(val.value); - }); + this.appendBrandIdsByNames(this.multSelected); } this.tagsContent[index].show = false; @@ -360,22 +359,30 @@ export default { this.tagsContent[0].more = false; this.multiple = false; }, + appendBrandIdsByNames (names) { + const selectedNames = names || []; + const brands = this.tagsContent[0] && this.tagsContent[0].values ? this.tagsContent[0].values : []; + brands.forEach((val) => { + if (selectedNames.includes(val.name) && val.value && !this.brandIds.includes(val.value)) { + this.brandIds.push(val.value); + } + }); + }, getFilterList (params) { // 筛选、分类 列表 APIGoods.filterList(params).then((res) => { if (res.success) { const data = res.result; + const hiddenKeys = new Set(this.selectedItem.map((item) => item.type)); this.tagsContent = [{ key: '品牌', more: false, - show: true, - values: [] - }] - this.tagsContent[0].values = data.brands; - this.tagsContent = this.tagsContent.concat(data.paramOptions); + show: !hiddenKeys.has('品牌'), + values: data.brands || [] + }].concat(data.paramOptions || []); this.tagsContent.forEach((item) => { - item['show'] = true - item['more'] = false + item.show = !hiddenKeys.has(item.key); + item.more = false; }); } }); diff --git a/buyer/src/pages/GoodsList.vue b/buyer/src/pages/GoodsList.vue index 8644a133..38c09aa6 100644 --- a/buyer/src/pages/GoodsList.vue +++ b/buyer/src/pages/GoodsList.vue @@ -148,7 +148,7 @@ export default { total: 0, // 列表总数 params: { // 请求参数 - pageNumber: 0, + pageNumber: 1, pageSize: 20, categoryId: "", }, @@ -179,7 +179,7 @@ export default { handleSearch(key) { this.params.keyword = key; this.$route.query.keyword = key - this.params.pageNumber = 0; + this.params.pageNumber = 1; this.getGoodsList(); }, orderBy(data, index) {