购物车页面加载问题与选中修复

This commit is contained in:
linzj
2021-04-20 17:18:52 +08:00
parent fc42935f7b
commit e60946e95b

View File

@@ -129,7 +129,7 @@ export default {
finalMoney: 0,
totalMoney: 0,
subtractMoney: 0,
allChecked: true
allChecked: false
};
},
@@ -150,40 +150,43 @@ export default {
* 生命周期函数--监听页面显示
*/
onShow: function () {
uni.showLoading(); //加载购物车
var params = {
url: "/p/shopCart/info",
method: "POST",
data: {},
callBack: res => {
if (res.length > 0) {
// 默认全选
var shopCartItemDiscounts = res[0].shopCartItemDiscounts;
shopCartItemDiscounts.forEach(shopCartItemDiscount => {
shopCartItemDiscount.shopCartItems.forEach(shopCartItem => {
shopCartItem.checked = true;
});
});
this.setData({
shopCartItemDiscounts: shopCartItemDiscounts,
allChecked: true
});
} else {
this.setData({
shopCartItemDiscounts: []
});
}
this.calTotalPrice(); //计算总价
uni.hideLoading();
}
};
http.request(params);
this.loadBasketData();
http.getCartCount(); //重新计算购物车总数量
},
methods: {
loadBasketData(){
uni.showLoading(); //加载购物车
var params = {
url: "/p/shopCart/info",
method: "POST",
data: {},
callBack: res => {
if (res.length > 0) {
// 默认不选中
var shopCartItemDiscounts = res[0].shopCartItemDiscounts;
shopCartItemDiscounts.forEach(shopCartItemDiscount => {
shopCartItemDiscount.shopCartItems.forEach(shopCartItem => {
shopCartItem.checked = false;
});
});
this.setData({
shopCartItemDiscounts: shopCartItemDiscounts,
allChecked: false
});
} else {
this.setData({
shopCartItemDiscounts: []
});
}
this.calTotalPrice(); //计算总价
uni.hideLoading();
}
};
http.request(params);
},
/**
* 去结算
*/
@@ -416,7 +419,7 @@ export default {
data: basketIds,
callBack: function (res) {
uni.hideLoading();
ths.onShow();
ths.loadBasketData();
}
};
http.request(params);