| const app=getApp(); | 
| var util = require('../../utils/util.js'); | 
| var api = require('../../utils/service-api.js'); | 
| var comReq = require('../../utils/common-request.js'); | 
| Page({ | 
|   data: { | 
|     selectAllStatus: 1, | 
|     carts: [], // 购物车列表 | 
|     totalPrice: 0, // 总价,初始为0 | 
|     totalNum: 0, // 总数,初始为0 | 
|     couponGroupList: [{}], | 
|     selectCount: "", | 
|   }, | 
|   | 
|   onShow() { | 
|     comReq.refreshUserCartCount(); | 
|     this.loadCarList(); | 
|   }, | 
|   | 
|   onLoad() {}, | 
|   | 
|   /** | 
|    * 删除购物车当前商品 | 
|    */ | 
|   deleteList(e) { | 
|     var _this = this; | 
|     const id = e.currentTarget.dataset.id; | 
|     util.request({ | 
|       method: "POST", | 
|       api: api.shoppingCart.deleteByCartId + id, | 
|       callback: function(data) { | 
|         _this.loadCarList(); | 
|         comReq.refreshUserCartCount(); | 
|       } | 
|     }); | 
|   | 
|   }, | 
|   | 
|   /** | 
|    * 当前商品选中事件 | 
|    */ | 
|   selectList(e) { | 
|     let id = e.currentTarget.dataset.id; | 
|     let isSelected = e.currentTarget.dataset.selected; | 
|     isSelected = (isSelected == 1 ? 2 : 1); | 
|     var _this = this; | 
|     util.request({ | 
|       method: "POST", | 
|       api: api.shoppingCart.updateCartSelected, | 
|       data: { | 
|         "cartId": id, | 
|         "isSelected": isSelected | 
|       }, | 
|       callback: function() { | 
|         _this.loadCarList(); | 
|       } | 
|     }); | 
|   }, | 
|   | 
|   | 
|   /** | 
|    * 购物车全选事件 | 
|    */ | 
|   selectAll(e) { | 
|     var _this = this; | 
|     let selectAllStatus = this.data.selectAllStatus; | 
|     selectAllStatus = (selectAllStatus == 1 ? 2 : 1); | 
|     this.setData({ | 
|       "selectAllStatus": selectAllStatus, | 
|     }); | 
|     util.request({ | 
|       method: "POST", | 
|       api: api.shoppingCart.updateCartAllSelected + app.shopInfo.id +"/"+ selectAllStatus, | 
|       callback: function() { | 
|         _this.loadCarList(); | 
|       } | 
|     }); | 
|   }, | 
|   | 
|   /** | 
|    * 绑定加数量事件 | 
|    */ | 
|   updateCarNumber(e) { | 
|     var _this = this; | 
|   | 
|     const type = e.currentTarget.dataset.type; | 
|     var id = e.currentTarget.dataset.id; | 
|   | 
|     let increaseAndDecrease = "1"; | 
|     if (type == "down") { | 
|       increaseAndDecrease = "2"; | 
|     } | 
|     util.request({ | 
|       method: "POST", | 
|       api: api.shoppingCart.updateCarNumberByCartId, | 
|       data: { | 
|         "cartId": id, | 
|         "increaseAndDecrease": increaseAndDecrease | 
|       }, | 
|       callback: function(data) { | 
|         _this.loadCarList(); | 
|         comReq.refreshUserCartCount(); | 
|       } | 
|     }); | 
|   }, | 
|   | 
|   | 
|   /** | 
|    *  结算 | 
|    */ | 
|   castAccount() { | 
|     var _this = this; | 
|     var ids = ''; | 
|     if (_this.data.selectCount == 0) { | 
|       wx.showToast({ | 
|         title: '请选择商品', | 
|         icon: 'success', | 
|         duration: 2000 | 
|       }) | 
|     } else { | 
|   | 
|   | 
|   | 
|       //判断是否绑定手机号 | 
|       if (util.isBlank(getApp().userInfo.nickName)) { | 
|         wx.navigateTo({ | 
|           url: '/pages/welcome/welcome?url=/pages/yuyue/khyuyue', | 
|         }) | 
|       } else if (util.isBlank(getApp().userInfo.phoneNumber)) { | 
|         wx.navigateTo({ | 
|           url: '/pages/phone/phone?url=/pages/yuyue/khyuyue', | 
|         }) | 
|       } | 
|        | 
|       wx.navigateTo({ | 
|         url: '/pages/service/shopOrder?model=2', | 
|       }) | 
|   | 
|     } | 
|   | 
|   }, | 
|   | 
|   // 进入商品详情 | 
|   goGoods(e) { | 
|     var id = e.currentTarget.dataset.id; | 
|     wx.navigateTo({ | 
|       url: '../details/details?id=' + id, //把id传到product页面 | 
|     }) | 
|   }, | 
|   | 
|   // 上拉加载 | 
|   onReachBottom: function() { | 
|   | 
|   }, | 
|   | 
|   //加载购物车列表 | 
|   loadCarList() { | 
|     var _this = this; | 
|     util.request({ | 
|       method: "POST", | 
|       data:{shopId:app.shopInfo.id}, | 
|       api: api.shoppingCart.findShoppingCart, | 
|       callback: function(data) { | 
|         if (data.mapInfo.cartCount == data.mapInfo.selectCount) { | 
|           _this.setData({ | 
|             "selectAllStatus": 1, | 
|           }); | 
|         } else { | 
|           _this.setData({ | 
|             "selectAllStatus": 2, | 
|           }); | 
|         } | 
|         _this.setData({ | 
|           "couponGroupList": data.rows, | 
|           "billTotal": data.mapInfo.billTotal, | 
|           "billCouponTotal": data.mapInfo.billCouponTotal, | 
|           "selectCount": data.mapInfo.selectCount, | 
|           "cartCount": data.mapInfo.cartCount, | 
|         }); | 
|       } | 
|     }); | 
|   | 
|   | 
|   }, | 
|   | 
|   | 
|   /** | 
|    * 凑单 | 
|    */ | 
|   coudan(e) { | 
|     var coupon = e.currentTarget.dataset.coupon; | 
|     console.log(coupon); | 
|     if (coupon) { | 
|       wx.navigateTo({ | 
|         url: '../shopTypeSecond/shopTypeSecond?content=' + coupon, | 
|       }) | 
|     } else { | 
|       console.log("没有优惠券"); | 
|       wx.switchTab({ | 
|         url: '../shopType/shopType', | 
|         success: function() { | 
|           console.log(1); | 
|         }, | 
|         fail: function(e) { | 
|           console.log(e); | 
|         } | 
|       }) | 
|     } | 
|   }, | 
|   | 
|   | 
|   //一键回到顶部 | 
|   goTap() { | 
|     util.goTap(); | 
|   }, | 
|   //获取滚动条当前位置 | 
|   onPageScroll: function(e) { | 
|     if (e.scrollTop > 400) { | 
|       this.setData({ | 
|         floorstatus: true | 
|       }); | 
|     } else { | 
|       this.setData({ | 
|         floorstatus: false | 
|       }); | 
|     } | 
|   }, | 
|   | 
|   | 
| }) |