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

master
linzj 5 years ago
parent e60946e95b
commit de70d84795

@ -14,7 +14,7 @@ Page({
finalMoney: 0, finalMoney: 0,
totalMoney: 0, totalMoney: 0,
subtractMoney: 0, subtractMoney: 0,
allChecked: true allChecked: false
}, },
/** /**
@ -35,41 +35,42 @@ Page({
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow: function () { onShow: function () {
wx.showLoading(); this.loadBasketData();
//加载购物车
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();//计算总价
wx.hideLoading();
}
};
http.request(params);
http.getCartCount();//重新计算购物车总数量 http.getCartCount();//重新计算购物车总数量
}, },
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);
},
/** /**
* 去结算 * 去结算
@ -290,7 +291,7 @@ Page({
data: basketIds, data: basketIds,
callBack: function (res) { callBack: function (res) {
wx.hideLoading(); wx.hideLoading();
ths.onShow(); ths.loadBasketData();
} }
}; };
http.request(params); http.request(params);

Loading…
Cancel
Save