Commit 7f73d341137437c661737fb6ca280ba448a49cee
Merge branch 'work-1.1_20191010' of http://git.vipzhuang.cn/wxd/MShopWeApp into work-1.1_20191010
Showing
2 changed files
with
80 additions
and
36 deletions
pages/cart/cart/cart.js
| @@ -12,10 +12,14 @@ Page({ | @@ -12,10 +12,14 @@ Page({ | ||
| 12 | iurl: t.globalData.setting.imghost, | 12 | iurl: t.globalData.setting.imghost, |
| 13 | requestData: null, | 13 | requestData: null, |
| 14 | checkAllToggle: 0, | 14 | checkAllToggle: 0, |
| 15 | - total_fee: 0, | 15 | + total_fee: 0, //结算金额 |
| 16 | + total_num: 0, //结算数量 | ||
| 17 | + all_num:0, //购物车中所有商品数量 | ||
| 16 | allsto: null, | 18 | allsto: null, |
| 17 | imgUrl: t.globalData.setting.imghost, | 19 | imgUrl: t.globalData.setting.imghost, |
| 18 | is_has_flash:0, //是否又秒杀活动 | 20 | is_has_flash:0, //是否又秒杀活动 |
| 21 | + is_edit:0, //是否编辑 | ||
| 22 | + is_load:0, //是否已加载 | ||
| 19 | }, | 23 | }, |
| 20 | onLoad: function() { | 24 | onLoad: function() { |
| 21 | wx.setNavigationBarTitle({title: "购物车", }) | 25 | wx.setNavigationBarTitle({title: "购物车", }) |
| @@ -73,16 +77,14 @@ Page({ | @@ -73,16 +77,14 @@ Page({ | ||
| 73 | pageSize: 600 | 77 | pageSize: 600 |
| 74 | }, | 78 | }, |
| 75 | success: function(su) { | 79 | success: function(su) { |
| 76 | - console.log("333"); | ||
| 77 | - console.log(th.data.allsto); | ||
| 78 | - | ||
| 79 | //按门店分类的数组 | 80 | //按门店分类的数组 |
| 80 | - var arr = new Array(); | ||
| 81 | - var carr = su.data.data.pageData; | 81 | + var arr = new Array(),carr = su.data.data.pageData; |
| 82 | + var all_num=0; | ||
| 83 | + | ||
| 82 | for (var i = 0; i < carr.length; i++) { | 84 | for (var i = 0; i < carr.length; i++) { |
| 83 | var item = carr[i]; | 85 | var item = carr[i]; |
| 86 | + all_num+=item.goods_num; | ||
| 84 | item.original_img = oo.imghost + item.original_img; | 87 | item.original_img = oo.imghost + item.original_img; |
| 85 | - | ||
| 86 | item.selected = 0; | 88 | item.selected = 0; |
| 87 | 89 | ||
| 88 | var pcid = item.pick_id; | 90 | var pcid = item.pick_id; |
| @@ -124,7 +126,7 @@ Page({ | @@ -124,7 +126,7 @@ Page({ | ||
| 124 | console.log(arr); | 126 | console.log(arr); |
| 125 | 127 | ||
| 126 | th.setData({ | 128 | th.setData({ |
| 127 | - requestData: arr, | 129 | + requestData: arr,all_num:all_num,is_load:1,is_edit:0 |
| 128 | }), | 130 | }), |
| 129 | th.doCheckAll(), wx.stopPullDownRefresh(); | 131 | th.doCheckAll(), wx.stopPullDownRefresh(); |
| 130 | } | 132 | } |
| @@ -207,7 +209,7 @@ Page({ | @@ -207,7 +209,7 @@ Page({ | ||
| 207 | checkAll: function() { | 209 | checkAll: function() { |
| 208 | var e = this, | 210 | var e = this, |
| 209 | dda = e.data.requestData, | 211 | dda = e.data.requestData, |
| 210 | - tfeel = 0, | 212 | + tfeel = 0,t_num=0, |
| 211 | text_arr = ""; | 213 | text_arr = ""; |
| 212 | for (var i = 0; i < dda.length; i++) { | 214 | for (var i = 0; i < dda.length; i++) { |
| 213 | var item = dda[i].goods; | 215 | var item = dda[i].goods; |
| @@ -232,8 +234,10 @@ Page({ | @@ -232,8 +234,10 @@ Page({ | ||
| 232 | e.setData({ | 234 | e.setData({ |
| 233 | [txt]: !e.data.checkAllToggle, | 235 | [txt]: !e.data.checkAllToggle, |
| 234 | }) | 236 | }) |
| 235 | - if (!e.data.checkAllToggle) | 237 | + if (!e.data.checkAllToggle) { |
| 236 | tfeel += item[j].goods_num * item[j].goods_price; | 238 | tfeel += item[j].goods_num * item[j].goods_price; |
| 239 | + t_num += item[j].goods_num; | ||
| 240 | + } | ||
| 237 | } | 241 | } |
| 238 | } | 242 | } |
| 239 | 243 | ||
| @@ -243,13 +247,11 @@ Page({ | @@ -243,13 +247,11 @@ Page({ | ||
| 243 | content: text_arr + '不能与门店中其他商品一起结算,配送方式不一致' | 247 | content: text_arr + '不能与门店中其他商品一起结算,配送方式不一致' |
| 244 | }); | 248 | }); |
| 245 | return false; | 249 | return false; |
| 246 | - e.setData({ | ||
| 247 | - total_fee: tfeel.toFixed(2), | ||
| 248 | - }); | ||
| 249 | } else { | 250 | } else { |
| 250 | e.setData({ | 251 | e.setData({ |
| 251 | checkAllToggle: !e.data.checkAllToggle, | 252 | checkAllToggle: !e.data.checkAllToggle, |
| 252 | total_fee: tfeel.toFixed(2), | 253 | total_fee: tfeel.toFixed(2), |
| 254 | + total_num:t_num, | ||
| 253 | }); | 255 | }); |
| 254 | } | 256 | } |
| 255 | }, | 257 | }, |
| @@ -258,15 +260,11 @@ Page({ | @@ -258,15 +260,11 @@ Page({ | ||
| 258 | check_th_all_item: function(ele) { | 260 | check_th_all_item: function(ele) { |
| 259 | var e = this, | 261 | var e = this, |
| 260 | pitems = ele.currentTarget.dataset.pitems, | 262 | pitems = ele.currentTarget.dataset.pitems, |
| 261 | - item = this.data.requestData[pitems].goods; | ||
| 262 | - var sele = this.data.requestData[pitems].selected; | 263 | + item = this.data.requestData[pitems].goods, |
| 264 | + sele = this.data.requestData[pitems].selected; | ||
| 263 | 265 | ||
| 264 | - var isok = 1, | ||
| 265 | - fir = 0, | ||
| 266 | - iarr = item; | 266 | + var isok = 1,fir = 0,iarr = item; |
| 267 | if (!sele && item.length > 0) { | 267 | if (!sele && item.length > 0) { |
| 268 | - | ||
| 269 | - console.log(item); | ||
| 270 | for (var i = 0; i < iarr.length; i++) { | 268 | for (var i = 0; i < iarr.length; i++) { |
| 271 | if (iarr[i].distr_type != 0) { | 269 | if (iarr[i].distr_type != 0) { |
| 272 | if (fir == 0) { | 270 | if (fir == 0) { |
| @@ -346,30 +344,34 @@ Page({ | @@ -346,30 +344,34 @@ Page({ | ||
| 346 | //----------检查是否全选--------- | 344 | //----------检查是否全选--------- |
| 347 | doCheckAll: function() { | 345 | doCheckAll: function() { |
| 348 | var th = this, | 346 | var th = this, |
| 349 | - tfeel = 0, | 347 | + tfeel = 0,t_num=0, |
| 350 | ischeck = 1, | 348 | ischeck = 1, |
| 351 | - car = this.data.requestData; | 349 | + car = this.data.requestData,all_num=0; |
| 350 | + | ||
| 352 | for (var a = 0; a < car.length; a++) { | 351 | for (var a = 0; a < car.length; a++) { |
| 353 | - var item = car[a].goods; | ||
| 354 | - var is_s_sele = 1; | 352 | + var item = car[a].goods,is_s_sele = 1; |
| 355 | for (var c = 0; c < item.length; c++) { | 353 | for (var c = 0; c < item.length; c++) { |
| 354 | + all_num+=item[c].goods_num; | ||
| 356 | if (item[c].selected == 0) { | 355 | if (item[c].selected == 0) { |
| 357 | ischeck = 0; | 356 | ischeck = 0; |
| 358 | is_s_sele = 0; | 357 | is_s_sele = 0; |
| 359 | } else { | 358 | } else { |
| 360 | tfeel += item[c].goods_num * item[c].goods_price; | 359 | tfeel += item[c].goods_num * item[c].goods_price; |
| 360 | + t_num+= item[c].goods_num; | ||
| 361 | } | 361 | } |
| 362 | } | 362 | } |
| 363 | 363 | ||
| 364 | var txt = "requestData[" + a + "].selected"; | 364 | var txt = "requestData[" + a + "].selected"; |
| 365 | th.setData({ | 365 | th.setData({ |
| 366 | - [txt]: Number(is_s_sele), | 366 | + [txt]: Number(is_s_sele) |
| 367 | }); | 367 | }); |
| 368 | 368 | ||
| 369 | } | 369 | } |
| 370 | this.setData({ | 370 | this.setData({ |
| 371 | checkAllToggle: ischeck, | 371 | checkAllToggle: ischeck, |
| 372 | - total_fee: tfeel.toFixed(2), | 372 | + total_fee: tfeel.toFixed(2) |
| 373 | + ,all_num:all_num, | ||
| 374 | + total_num:t_num | ||
| 373 | }); | 375 | }); |
| 374 | }, | 376 | }, |
| 375 | 377 | ||
| @@ -704,7 +706,43 @@ Page({ | @@ -704,7 +706,43 @@ Page({ | ||
| 704 | radio_chick: function(checked, num) { | 706 | radio_chick: function(checked, num) { |
| 705 | var th = this; | 707 | var th = this; |
| 706 | var requestData = th.data.requestData; | 708 | var requestData = th.data.requestData; |
| 709 | + }, | ||
| 710 | + | ||
| 711 | + //点击编辑后的效果 | ||
| 712 | + edit_cart:function (e) { | ||
| 713 | + var type=parseFloat(e.currentTarget.dataset.type); | ||
| 714 | + this.setData({is_edit:type}); | ||
| 715 | + }, | ||
| 716 | + | ||
| 717 | + //--多个删除购物车商品--- | ||
| 718 | + check_del:function () { | ||
| 719 | + var glist = ""; //用逗号隔开的 | ||
| 720 | + var user_id = getApp().globalData.user_id; | ||
| 721 | + var th = this; | ||
| 707 | 722 | ||
| 723 | + var ab = 0; //选中 | ||
| 724 | + for (var i = 0; i < this.data.requestData.length; i++) { | ||
| 725 | + var i_arr = this.data.requestData[i].goods; | ||
| 726 | + for (var j = 0; j < i_arr.length; j++) { | ||
| 727 | + if (i_arr[j].selected) { | ||
| 728 | + glist += i_arr[j].i_arr[j].id + ","; | ||
| 729 | + ab = 1; | ||
| 730 | + } | ||
| 731 | + } | ||
| 732 | + } | ||
| 733 | + | ||
| 734 | + if (ab == 0) { | ||
| 735 | + t.my_warnning("未选择商品", 0, th);return false; | ||
| 736 | + } | ||
| 737 | + | ||
| 738 | + glist = glist.substring(0, glist.length - 1); | ||
| 739 | + //要删除购物车中的商品 | ||
| 740 | + var url = '/api/weshop/cart/del/' + oo.stoid + '/' + glist; | ||
| 741 | + getApp().request.delete(url, { | ||
| 742 | + success: function(t) { | ||
| 743 | + th.getCardList(); | ||
| 744 | + } | ||
| 745 | + }); | ||
| 708 | 746 | ||
| 709 | } | 747 | } |
| 710 | 748 |
pages/cart/cart/cart.wxml
| @@ -8,12 +8,13 @@ | @@ -8,12 +8,13 @@ | ||
| 8 | <!-- 购物车商品框架 --> | 8 | <!-- 购物车商品框架 --> |
| 9 | <view class="login-in"> | 9 | <view class="login-in"> |
| 10 | <!-- 编辑 --> | 10 | <!-- 编辑 --> |
| 11 | - <view class="padding flex-vertical-between fs26 Storenum"> | 11 | + <view class="padding flex-vertical-between fs30 Storenum"> |
| 12 | <view class="flex"> | 12 | <view class="flex"> |
| 13 | <view>商品数量:</view> | 13 | <view>商品数量:</view> |
| 14 | - <view class="goods_num">{{requestData.length}}</view> | 14 | + <view class="goods_num">{{all_num}}</view> |
| 15 | </view> | 15 | </view> |
| 16 | - <view>编辑</view> | 16 | + <view wx:if="{{is_edit==0}}" bindtap="edit_cart" data-type="1">编辑</view> |
| 17 | + <view wx:else bindtap="edit_cart" data-type="0">完成</view> | ||
| 17 | </view> | 18 | </view> |
| 18 | <block wx:for="{{requestData}}" wx:key="{{index}}" wx:for-index="pidx"> | 19 | <block wx:for="{{requestData}}" wx:key="{{index}}" wx:for-index="pidx"> |
| 19 | <!-- 门店底下的商品 --> | 20 | <!-- 门店底下的商品 --> |
| @@ -23,7 +24,7 @@ | @@ -23,7 +24,7 @@ | ||
| 23 | checked="{{checkAllToggle||item.selected}}" data-pitems="{{pidx}}"></radio> | 24 | checked="{{checkAllToggle||item.selected}}" data-pitems="{{pidx}}"></radio> |
| 24 | <view class="flex-center"> | 25 | <view class="flex-center"> |
| 25 | <image src="{{iurl}}miniapp/images/stores/store.png"></image> | 26 | <image src="{{iurl}}miniapp/images/stores/store.png"></image> |
| 26 | - <view class="shmd fs24">{{item.pname}}</view> | 27 | + <view class="shmd fs28" >{{item.pname}}</view> |
| 27 | </view> | 28 | </view> |
| 28 | </view> | 29 | </view> |
| 29 | <view class="order-item padding" data-item="{{idx}}" wx:for="{{item.goods}}" wx:for-item="items" wx:for-index="idx" wx:key="{{index}}"> | 30 | <view class="order-item padding" data-item="{{idx}}" wx:for="{{item.goods}}" wx:for-item="items" wx:for-index="idx" wx:key="{{index}}"> |
| @@ -39,8 +40,10 @@ | @@ -39,8 +40,10 @@ | ||
| 39 | <view class="goods-cont"> | 40 | <view class="goods-cont"> |
| 40 | <view class="goods-name"> | 41 | <view class="goods-name"> |
| 41 | <navigator class="ellipsis-2 fs24" url="/pages/goods/goodsInfo/goodsInfo?goods_id={{items.goods_id}}">{{items.goods_name}}</navigator> | 42 | <navigator class="ellipsis-2 fs24" url="/pages/goods/goodsInfo/goodsInfo?goods_id={{items.goods_id}}">{{items.goods_name}}</navigator> |
| 42 | - <view class="Specifications flex-center">{{items.goods_color+items.goods_spec.length | ||
| 43 | - <1? '规格1': ''}}{{items.goods_color}}{{items.goods_color.length>0?"/":''}}{{items.goods_spec}}</view> | 43 | + |
| 44 | + <view class="Specifications flex-center" wx:if="{{items.goods_color || items.goods_spec}}"> | ||
| 45 | + {{items.goods_color}}{{items.goods_color?"/":''}}{{items.goods_spec}}</view> | ||
| 46 | + <view class="Specifications flex-center" wx:else>规格1</view> | ||
| 44 | </view> | 47 | </view> |
| 45 | 48 | ||
| 46 | <view class="flex alend jc_sb"> | 49 | <view class="flex alend jc_sb"> |
| @@ -66,7 +69,9 @@ | @@ -66,7 +69,9 @@ | ||
| 66 | <radio bindtap="checkAll" color="red" checked="{{checkAllToggle}}"></radio> | 69 | <radio bindtap="checkAll" color="red" checked="{{checkAllToggle}}"></radio> |
| 67 | <view class="all fs30">全选</view> | 70 | <view class="all fs30">全选</view> |
| 68 | </view> | 71 | </view> |
| 69 | - <view class="consumer"> | 72 | + |
| 73 | + <!-- 显示金额的多少 --> | ||
| 74 | + <view class="consumer" wx:if="{{is_edit==0}}"> | ||
| 70 | <view class="fs30 baseline"> | 75 | <view class="fs30 baseline"> |
| 71 | <view class="total">合计:</view> | 76 | <view class="total">合计:</view> |
| 72 | <text class="co-red">¥{{total_fee}}</text> | 77 | <text class="co-red">¥{{total_fee}}</text> |
| @@ -77,12 +82,13 @@ | @@ -77,12 +82,13 @@ | ||
| 77 | </view> | 82 | </view> |
| 78 | </view> | 83 | </view> |
| 79 | <view> | 84 | <view> |
| 80 | - <button wx:if="{{true}}" bindtap="checkout" class="pay-btn">结算(2)</button> | ||
| 81 | - <button wx:if="{{false}}" bindtap="checkout" class="pay-btn">删除</button> | 85 | + |
| 86 | + <button wx:if="{{is_edit}}" bindtap="check_del" class="pay-btn">删除</button> | ||
| 87 | + <button wx:else bindtap="checkout" class="pay-btn">结算({{total_num}})</button> | ||
| 82 | </view> | 88 | </view> |
| 83 | </view> | 89 | </view> |
| 84 | </view> | 90 | </view> |
| 85 | -<view class="no-data" wx:if="{{!requestData||requestData.length==0}}"> | 91 | +<view class="no-data" wx:if="{{(!requestData|| requestData.length==0) && is_load}}"> |
| 86 | <image class="cart-image" src="{{imgUrl}}/miniapp/images/cart-null.png"></image> | 92 | <image class="cart-image" src="{{imgUrl}}/miniapp/images/cart-null.png"></image> |
| 87 | <view class="no-data-title">购物车暂无商品</view> | 93 | <view class="no-data-title">购物车暂无商品</view> |
| 88 | <navigator class="lookat" openType="switchTab" url="/pages/index/index/index"> 去逛逛 </navigator> | 94 | <navigator class="lookat" openType="switchTab" url="/pages/index/index/index"> 去逛逛 </navigator> |