修改点击选择规格没反应的bug
This commit is contained in:
parent
a3980c4470
commit
1a3fd2c137
@ -369,8 +369,19 @@ export default {
|
||||
this.topShow = !this.topShow;
|
||||
},
|
||||
// 选择商品规格
|
||||
chooseGG(e) {
|
||||
e.isShow = !e.isShow;
|
||||
chooseGG(targetItems) {
|
||||
// 遍历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() {
|
||||
@ -378,7 +389,6 @@ export default {
|
||||
},
|
||||
//商品详情页
|
||||
goods(e) {
|
||||
console.log(`${JSON.stringify(e)}`);
|
||||
NavgateTo(`../goods/index?item=${JSON.stringify(e)}`);
|
||||
// NavgateTo("../goods/index");
|
||||
},
|
||||
@ -418,26 +428,25 @@ export default {
|
||||
user_id: uni.getStorageSync("userId"),
|
||||
id: this.secondId,
|
||||
}).then((res) => {
|
||||
console.log(123);
|
||||
console.log(res)
|
||||
res.commodity_list.forEach((item) => {
|
||||
item.commodity_info_list.forEach((item) => {
|
||||
item.commodity_goods_info_list.forEach((param) => {
|
||||
// 深拷贝接口数据,避免引用问题
|
||||
const commodityList = JSON.parse(JSON.stringify(res.commodity_list));
|
||||
commodityList.forEach((tagItem) => { // 重命名外层变量,避免嵌套冲突
|
||||
tagItem.commodity_info_list.forEach((infoItem) => { // 内层变量重命名
|
||||
// 初始化isShow为响应式属性
|
||||
this.$set(infoItem, 'isShow', false);
|
||||
infoItem.commodity_goods_info_list.forEach((param) => {
|
||||
this.goodsDetail.forEach((goods) => {
|
||||
if (goods.goods_id === param.id) {
|
||||
param.quantity = goods.count;
|
||||
this.$set(param, 'quantity', goods.count); // 同步数量也要用$set
|
||||
}
|
||||
});
|
||||
});
|
||||
item.isShow = false;
|
||||
});
|
||||
});
|
||||
// 保存原始数据
|
||||
this.originalTagList = res.commodity_list;
|
||||
this.tagList1 = res.commodity_list;
|
||||
// 添加"全部"选项并设置为默认选中
|
||||
this.tagList = [{ id: 'all', tag_name: '全部' }, ...res.commodity_list];
|
||||
// 默认选中"全部"选项
|
||||
this.originalTagList = commodityList;
|
||||
this.tagList1 = commodityList;
|
||||
// 重新构建tagList,确保使用拷贝后的响应式数据
|
||||
this.tagList = [{ id: 'all', tag_name: '全部' }, ...commodityList];
|
||||
this.rightTopActive = 0;
|
||||
this.selectedTagId = 'all';
|
||||
});
|
||||
@ -445,7 +454,6 @@ export default {
|
||||
|
||||
getShopCarList() {
|
||||
request(apiArr.getCar, "POST").then((res) => {
|
||||
console.log(res);
|
||||
this.carNum = res.total;
|
||||
// 合并当日达和普通商品数据
|
||||
this.goodsDetail = [].concat(res.same_day_cart_list, res.normal_cart_list)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user