935090232@qq.com
2021-01-09 2e3c12ca3a7241f498c32121cb1572502c998d0d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
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
      });
    }
  },
 
 
})