|
@@ -195,14 +195,14 @@
|
|
|
// 获取购物车列表
|
|
// 获取购物车列表
|
|
|
this.$u.api.getShopCartListAjax({}).then(res => {
|
|
this.$u.api.getShopCartListAjax({}).then(res => {
|
|
|
this.loading = false;
|
|
this.loading = false;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 获取本地缓存的选中状态,和当前列表的选中状态合并
|
|
// 获取本地缓存的选中状态,和当前列表的选中状态合并
|
|
|
let storageCheckedIds = uni.getStorageSync('cartCheckedIds') || [];
|
|
let storageCheckedIds = uni.getStorageSync('cartCheckedIds') || [];
|
|
|
const currentCheckedIds = this.cartList.filter(i => i.checked).map(i => i.id);
|
|
const currentCheckedIds = this.cartList.filter(i => i.checked).map(i => i.id);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 合并并去重
|
|
// 合并并去重
|
|
|
let checkedIds = [...new Set([...storageCheckedIds, ...currentCheckedIds])];
|
|
let checkedIds = [...new Set([...storageCheckedIds, ...currentCheckedIds])];
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 本地添加选中状态属性
|
|
// 本地添加选中状态属性
|
|
|
const list = res.rows || [];
|
|
const list = res.rows || [];
|
|
|
this.cartList = list.map(item => {
|
|
this.cartList = list.map(item => {
|
|
@@ -212,11 +212,11 @@
|
|
|
show: false
|
|
show: false
|
|
|
};
|
|
};
|
|
|
});
|
|
});
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 更新缓存中存在的且当前在购物车里的项
|
|
// 更新缓存中存在的且当前在购物车里的项
|
|
|
const finalCheckedIds = this.cartList.filter(i => i.checked).map(i => i.id);
|
|
const finalCheckedIds = this.cartList.filter(i => i.checked).map(i => i.id);
|
|
|
uni.setStorageSync('cartCheckedIds', finalCheckedIds);
|
|
uni.setStorageSync('cartCheckedIds', finalCheckedIds);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
}).catch(() => {
|
|
}).catch(() => {
|
|
|
this.loading = false;
|
|
this.loading = false;
|
|
|
});
|
|
});
|
|
@@ -401,26 +401,7 @@
|
|
|
uni.hideLoading();
|
|
uni.hideLoading();
|
|
|
this.$u.toast('更新成功');
|
|
this.$u.toast('更新成功');
|
|
|
|
|
|
|
|
- // 在列表中查找并更新,确保视图刷新
|
|
|
|
|
- const index = this.cartList.findIndex(i => i.id === this.currentItem.id);
|
|
|
|
|
- if (index > -1) {
|
|
|
|
|
- const targetItem = this.cartList[index];
|
|
|
|
|
- // 确保转换为数字类型
|
|
|
|
|
- const newType = Number(sku.conditionType);
|
|
|
|
|
-
|
|
|
|
|
- this.$set(targetItem, 'conditionType', newType);
|
|
|
|
|
- this.$set(targetItem, 'productPrice', sku.price);
|
|
|
|
|
-
|
|
|
|
|
- if (sku.reduceMoney !== undefined) {
|
|
|
|
|
- this.$set(targetItem, 'reduceMoney', sku.reduceMoney);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 强制更新 currentItem 引用(虽然它指向同一个对象,但为了保险)
|
|
|
|
|
- this.currentItem = targetItem;
|
|
|
|
|
- } else {
|
|
|
|
|
- // 如果找不到(极少情况),重新加载
|
|
|
|
|
- this.loadData();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ this.loadData();
|
|
|
}).catch(() => {
|
|
}).catch(() => {
|
|
|
uni.hideLoading();
|
|
uni.hideLoading();
|
|
|
});
|
|
});
|