修改点击选择规格没反应的bug

This commit is contained in:
赵毅 2025-09-02 14:57:45 +08:00
parent a3980c4470
commit 1a3fd2c137

View File

@ -369,8 +369,19 @@ export default {
this.topShow = !this.topShow; this.topShow = !this.topShow;
}, },
// 选择商品规格 // 选择商品规格
chooseGG(e) { chooseGG(targetItems) {
e.isShow = !e.isShow; // 遍历tagList找到目标对象(排除"全部"选项,从索引1开始)
for (let i = 1; i < this.tagList.length; i++) {
const tagItem = this.tagList[i];
const infoIndex = tagItem.commodity_info_list.findIndex(item => item.id === targetItems.id);
if (infoIndex > -1) {
// 直接修改数据源中的对象,确保响应式
const currentItem = tagItem.commodity_info_list[infoIndex];
this.$set(currentItem, 'isShow', !currentItem.isShow);
console.log("修改后数据源中的isShow:", currentItem.isShow);
break;
}
}
}, },
//搜索页 //搜索页
searchPage() { searchPage() {
@ -378,7 +389,6 @@ export default {
}, },
//商品详情页 //商品详情页
goods(e) { goods(e) {
console.log(`${JSON.stringify(e)}`);
NavgateTo(`../goods/index?item=${JSON.stringify(e)}`); NavgateTo(`../goods/index?item=${JSON.stringify(e)}`);
// NavgateTo("../goods/index"); // NavgateTo("../goods/index");
}, },
@ -418,26 +428,25 @@ export default {
user_id: uni.getStorageSync("userId"), user_id: uni.getStorageSync("userId"),
id: this.secondId, id: this.secondId,
}).then((res) => { }).then((res) => {
console.log(123); // 深拷贝接口数据,避免引用问题
console.log(res) const commodityList = JSON.parse(JSON.stringify(res.commodity_list));
res.commodity_list.forEach((item) => { commodityList.forEach((tagItem) => { // 重命名外层变量,避免嵌套冲突
item.commodity_info_list.forEach((item) => { tagItem.commodity_info_list.forEach((infoItem) => { // 内层变量重命名
item.commodity_goods_info_list.forEach((param) => { // 初始化isShow为响应式属性
this.$set(infoItem, 'isShow', false);
infoItem.commodity_goods_info_list.forEach((param) => {
this.goodsDetail.forEach((goods) => { this.goodsDetail.forEach((goods) => {
if (goods.goods_id === param.id) { if (goods.goods_id === param.id) {
param.quantity = goods.count; this.$set(param, 'quantity', goods.count); // 同步数量也要用$set
} }
}); });
}); });
item.isShow = false;
}); });
}); });
// 保存原始数据 this.originalTagList = commodityList;
this.originalTagList = res.commodity_list; this.tagList1 = commodityList;
this.tagList1 = res.commodity_list; // 重新构建tagList,确保使用拷贝后的响应式数据
// 添加"全部"选项并设置为默认选中 this.tagList = [{ id: 'all', tag_name: '全部' }, ...commodityList];
this.tagList = [{ id: 'all', tag_name: '全部' }, ...res.commodity_list];
// 默认选中"全部"选项
this.rightTopActive = 0; this.rightTopActive = 0;
this.selectedTagId = 'all'; this.selectedTagId = 'all';
}); });
@ -445,7 +454,6 @@ export default {
getShopCarList() { getShopCarList() {
request(apiArr.getCar, "POST").then((res) => { request(apiArr.getCar, "POST").then((res) => {
console.log(res);
this.carNum = res.total; this.carNum = res.total;
// 合并当日达和普通商品数据 // 合并当日达和普通商品数据
this.goodsDetail = [].concat(res.same_day_cart_list, res.normal_cart_list) this.goodsDetail = [].concat(res.same_day_cart_list, res.normal_cart_list)