|
@@ -8,6 +8,9 @@ Page({
|
|
*/
|
|
*/
|
|
data: {
|
|
data: {
|
|
carList:[],// 购物车列表数组
|
|
carList:[],// 购物车列表数组
|
|
|
|
+ host: app.globalData.servsers,
|
|
|
|
+ amount:0, //总价
|
|
|
|
+ checkAll:false, // 全选
|
|
},
|
|
},
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -28,7 +31,9 @@ Page({
|
|
* 生命周期函数--监听页面显示
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
*/
|
|
onShow: function () {
|
|
onShow: function () {
|
|
- this.getCarlist(this)
|
|
|
|
|
|
+ let that = this;
|
|
|
|
+ that.getCarlist(that)
|
|
|
|
+
|
|
},
|
|
},
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -65,6 +70,42 @@ Page({
|
|
onShareAppMessage: function () {
|
|
onShareAppMessage: function () {
|
|
|
|
|
|
},
|
|
},
|
|
|
|
+ subtraction(e){ // 减少
|
|
|
|
+ let that = this;
|
|
|
|
+ console.log(e)
|
|
|
|
+ let index = e.target.dataset.index,carList = that.data.carList;
|
|
|
|
+ if (carList[index].customGoodsNum > 1){
|
|
|
|
+ // 表示最小数量,不可减少
|
|
|
|
+ carList[index].customGoodsNum--;
|
|
|
|
+ that.setData({
|
|
|
|
+ carList: carList
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ that.totalPrice(that)
|
|
|
|
+ },
|
|
|
|
+ add(e) { // 减少
|
|
|
|
+ let that = this;
|
|
|
|
+ console.log(e)
|
|
|
|
+ let index = e.target.dataset.index, carList = that.data.carList;
|
|
|
|
+ carList[index].customGoodsNum++;
|
|
|
|
+ that.setData({
|
|
|
|
+ carList: carList
|
|
|
|
+ })
|
|
|
|
+ that.totalPrice(that)
|
|
|
|
+ },
|
|
|
|
+ checkboxChange(e){
|
|
|
|
+ let index = e.target.dataset.index, that = this, carList = that.data.carList;
|
|
|
|
+ if (e.detail.value[0]){ // 表示价格增加
|
|
|
|
+ that.data.carList[index].checked = true; // 表示选中
|
|
|
|
+ } else {
|
|
|
|
+ that.data.carList[index].checked = false; // 表示选中
|
|
|
|
+ }
|
|
|
|
+ that.setData({
|
|
|
|
+ carList: carList
|
|
|
|
+ })
|
|
|
|
+ that.totalPrice(that)
|
|
|
|
+
|
|
|
|
+ },
|
|
getCarlist(that){
|
|
getCarlist(that){
|
|
wx.request({
|
|
wx.request({
|
|
url: host +'/queryShopCar',
|
|
url: host +'/queryShopCar',
|
|
@@ -73,11 +114,37 @@ Page({
|
|
'content-type': 'application/x-www-form-urlencoded'
|
|
'content-type': 'application/x-www-form-urlencoded'
|
|
},
|
|
},
|
|
data:{
|
|
data:{
|
|
- userId: app.globalData.user_id,
|
|
|
|
|
|
+ userId: 'oovpNwjlsY6xx8ceCebFa1dOLd9E' //app.globalData.user_id,
|
|
},
|
|
},
|
|
success:function(res){
|
|
success:function(res){
|
|
console.log('购物车列表数据',res)
|
|
console.log('购物车列表数据',res)
|
|
|
|
+ let carList = [],imgArray=[];
|
|
|
|
+ res.data.forEach((el,index)=>{
|
|
|
|
+ imgArray =el.customGoodsImg.split(',');
|
|
|
|
+ carList.push(el);
|
|
|
|
+ carList[index]['imgArray'] = imgArray;
|
|
|
|
+ carList[index]['checked'] = false;
|
|
|
|
+ })
|
|
|
|
+ that.setData({
|
|
|
|
+ carList: carList
|
|
|
|
+ })
|
|
|
|
+ console.log(that.data.carList,"carListcarList")
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
+ },
|
|
|
|
+ totalPrice(that){
|
|
|
|
+ let amount = 0,checkAll = true;
|
|
|
|
+ that.data.carList.forEach(res=>{
|
|
|
|
+ if(res.checked){
|
|
|
|
+ amount += res.customgoodsPriceNow * res.customGoodsNum
|
|
|
|
+ }
|
|
|
|
+ if (!res.checked) {
|
|
|
|
+ checkAll = false
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ that.setData({
|
|
|
|
+ amount:amount.toFixed(2),
|
|
|
|
+ checkAll: checkAll
|
|
|
|
+ })
|
|
}
|
|
}
|
|
})
|
|
})
|