refactor(GoodsClassNav): 优化品牌ID处理与选择逻辑

- 重构品牌ID的获取方式,使用新方法 appendBrandIdsByNames 简化逻辑
- 更新多选确认逻辑,避免重复选择相同类型
- 调整标签内容显示逻辑,确保品牌标签在选择时正确显示
- 修复商品列表页的分页参数,确保从第一页开始加载数据
This commit is contained in:
田香琪
2026-09-03 17:17:11 +08:00
parent 2d80a795a7
commit fddb82e680
2 changed files with 30 additions and 23 deletions

View File

@@ -291,8 +291,12 @@ export default {
this.multSelected.push(item); this.multSelected.push(item);
} }
} else { } else {
const type = this.tagsContent[index].key;
if (this.selectedItem.some((selected) => selected.type === type)) {
return;
}
this.selectedItem.push({ this.selectedItem.push({
type: this.tagsContent[index].key, type,
name: item name: item
}); });
@@ -300,12 +304,7 @@ export default {
if (index === 0) { if (index === 0) {
// 如果是品牌获取品牌id // 如果是品牌获取品牌id
this.appendBrandIdsByNames([item]);
let brands = this.tagsContent[0].values;
brands.forEach((val) => {
if (val.name === item) this.brandIds.push(val.value);
});
} }
} }
}, },
@@ -336,19 +335,19 @@ export default {
}, },
sure (index) { sure (index) {
// 多选确认按钮 // 多选确认按钮
const type = this.tagsContent[index].key;
if (this.selectedItem.some((selected) => selected.type === type)) {
this.cancel();
return;
}
this.selectedItem.push({ this.selectedItem.push({
type: this.tagsContent[index].key, type,
name: this.multSelected.join('、') name: this.multSelected.join('、')
}); });
if (index === 0) { if (index === 0) {
// 如果是品牌获取品牌id // 如果是品牌获取品牌id
this.appendBrandIdsByNames(this.multSelected);
let brands = this.tagsContent[0].values;
brands.forEach((val) => {
if (this.multSelected.includes(val.name)) this.brandIds.push(val.value);
});
} }
this.tagsContent[index].show = false; this.tagsContent[index].show = false;
@@ -360,22 +359,30 @@ export default {
this.tagsContent[0].more = false; this.tagsContent[0].more = false;
this.multiple = 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) { getFilterList (params) {
// 筛选、分类 列表 // 筛选、分类 列表
APIGoods.filterList(params).then((res) => { APIGoods.filterList(params).then((res) => {
if (res.success) { if (res.success) {
const data = res.result; const data = res.result;
const hiddenKeys = new Set(this.selectedItem.map((item) => item.type));
this.tagsContent = [{ this.tagsContent = [{
key: '品牌', key: '品牌',
more: false, more: false,
show: true, show: !hiddenKeys.has('品牌'),
values: [] values: data.brands || []
}] }].concat(data.paramOptions || []);
this.tagsContent[0].values = data.brands;
this.tagsContent = this.tagsContent.concat(data.paramOptions);
this.tagsContent.forEach((item) => { this.tagsContent.forEach((item) => {
item['show'] = true item.show = !hiddenKeys.has(item.key);
item['more'] = false item.more = false;
}); });
} }
}); });

View File

@@ -148,7 +148,7 @@ export default {
total: 0, // 列表总数 total: 0, // 列表总数
params: { params: {
// 请求参数 // 请求参数
pageNumber: 0, pageNumber: 1,
pageSize: 20, pageSize: 20,
categoryId: "", categoryId: "",
}, },
@@ -179,7 +179,7 @@ export default {
handleSearch(key) { handleSearch(key) {
this.params.keyword = key; this.params.keyword = key;
this.$route.query.keyword = key this.$route.query.keyword = key
this.params.pageNumber = 0; this.params.pageNumber = 1;
this.getGoodsList(); this.getGoodsList();
}, },
orderBy(data, index) { orderBy(data, index) {