Showing
18 changed files
with
548 additions
and
81 deletions
app/components/cart/bundle/head.js
0 → 100644
1 | +Component({ | ||
2 | + properties: { | ||
3 | + item: { | ||
4 | + type: Object, | ||
5 | + value: {}, | ||
6 | + observer: '_itemChange' | ||
7 | + }, | ||
8 | + index: { | ||
9 | + type: Number, | ||
10 | + value: 0 | ||
11 | + }, | ||
12 | + isEditing: { | ||
13 | + type: Boolean, | ||
14 | + value: false, | ||
15 | + observer: '_editChange' | ||
16 | + }, | ||
17 | + }, | ||
18 | + methods: { | ||
19 | + _itemChange(item) { | ||
20 | + if (item) { | ||
21 | + this.selected = item.selected; | ||
22 | + } | ||
23 | + }, | ||
24 | + _editChange(isEdit) { | ||
25 | + let item = {...this.data.item}; | ||
26 | + | ||
27 | + if (!isEdit && this.selected) { | ||
28 | + item.selected = this.selected; | ||
29 | + | ||
30 | + this.setData({item: item}); | ||
31 | + } | ||
32 | + }, | ||
33 | + chooseBundleAction() { | ||
34 | + let item = {...this.data.item}; | ||
35 | + | ||
36 | + if (this.data.isEditing) { | ||
37 | + item.selected = item.selected === 'Y' ? 'N' : 'Y'; | ||
38 | + | ||
39 | + this.triggerEvent('removeGoodsListInEdit', item); | ||
40 | + this.setData({item}); | ||
41 | + } else { | ||
42 | + this.triggerEvent('chooseGoodsBundle', item); | ||
43 | + } | ||
44 | + }, | ||
45 | + editBundleNum(e) { | ||
46 | + this.triggerEvent('editBundleNum', e.detail); | ||
47 | + } | ||
48 | + } | ||
49 | +}); |
app/components/cart/bundle/head.json
0 → 100644
app/components/cart/bundle/head.wxml
0 → 100644
1 | +<view class="bundle-head" wx:if="{{item.pool_type === 3 && item.pool_batch_no}}"> | ||
2 | + <view class='bundle-title'> | ||
3 | + <view class="choose-btn" bindtap="chooseBundleAction"> | ||
4 | + <text class="iconfont icon-duihao-fill" wx:if="{{item.selected === 'Y'}}"></text> | ||
5 | + <text class="iconfont icon-round" wx:else></text> | ||
6 | + </view> | ||
7 | + <view class="bundle-tag">优惠套装</view> | ||
8 | + <view class="bundle-name">{{item.pool_title}}</view> | ||
9 | + <view class='bundle-buy-num' wx:if="{{!isEditing}}">x {{item.pool_buy_number}}</view> | ||
10 | + </view> | ||
11 | + <view class="edit-wrap" wx:if="{{isEditing}}"> | ||
12 | + <view class="bundle-edit-title">优惠数量</view> | ||
13 | + <view class="bundle-edit-num"> | ||
14 | + <cart-edit goods="{{item}}" type="{{'bundle'}}" bind:editGoodsNum="editBundleNum"></cart-edit> | ||
15 | + </view> | ||
16 | + <view class='bundle-buy-num'>x {{item.pool_buy_number}}</view> | ||
17 | + </view> | ||
18 | +</view> |
app/components/cart/bundle/head.wxss
0 → 100644
1 | +@import "../../../iconfont.wxss"; | ||
2 | + | ||
3 | +.bundle-title { | ||
4 | + height: 80rpx; | ||
5 | + line-height: 80rpx; | ||
6 | + border-bottom: 1rpx solid #f0f0f0; | ||
7 | + font-size: 0; | ||
8 | +} | ||
9 | + | ||
10 | +.bundle-title > view { | ||
11 | + display: inline-block; | ||
12 | + font-size: 24rpx; | ||
13 | +} | ||
14 | + | ||
15 | +.bundle-title .choose-btn { | ||
16 | + width: 90rpx; | ||
17 | + text-align: center; | ||
18 | +} | ||
19 | + | ||
20 | +.bundle-title .iconfont { | ||
21 | + font-size: 40rpx; | ||
22 | +} | ||
23 | + | ||
24 | +.bundle-title .bundle-tag { | ||
25 | + line-height: 1; | ||
26 | + padding: 5rpx 7rpx; | ||
27 | + border-radius: 4rpx; | ||
28 | + background-color: #d0021b; | ||
29 | + color: #fff; | ||
30 | + margin-right: 10rpx; | ||
31 | +} | ||
32 | + | ||
33 | +.bundle-buy-num { | ||
34 | + position: absolute; | ||
35 | + right: 30rpx; | ||
36 | + font-size: 26rpx; | ||
37 | + color: #b0b0b0; | ||
38 | +} | ||
39 | + | ||
40 | +.edit-wrap { | ||
41 | + padding: 16rpx 90rpx; | ||
42 | + padding-right: 0; | ||
43 | + border-bottom: 1rpx solid #f0f0f0; | ||
44 | + font-size: 0; | ||
45 | + margin-top: -4rpx; | ||
46 | + background-color: #fff; | ||
47 | +} | ||
48 | + | ||
49 | +.edit-wrap > view { | ||
50 | + display: inline-block; | ||
51 | + font-size: 26rpx; | ||
52 | + line-height: 80rpx; | ||
53 | + vertical-align: middle; | ||
54 | +} | ||
55 | + | ||
56 | +.edit-wrap .bundle-edit-title { | ||
57 | + width: 170rpx; | ||
58 | +} |
@@ -17,10 +17,13 @@ Component({ | @@ -17,10 +17,13 @@ Component({ | ||
17 | } | 17 | } |
18 | 18 | ||
19 | if (this.data.type === 'bundle') { | 19 | if (this.data.type === 'bundle') { |
20 | - goods.min_buy_number = 1; | 20 | + goods.min_buy_number = goods.min_buy_number || 1; |
21 | goods.buy_number = goods.pool_buy_number; | 21 | goods.buy_number = goods.pool_buy_number; |
22 | goods.storage_number = goods.pool_storage_number; | 22 | goods.storage_number = goods.pool_storage_number; |
23 | } else { | 23 | } else { |
24 | + if (goods.batch_no && goods.bundle_activity_id) { | ||
25 | + goods.noNumEdit = true; | ||
26 | + } | ||
24 | 27 | ||
25 | goods.colorSize = `颜色:${goods.factory_goods_name} 尺码:${goods.size_name}`; | 28 | goods.colorSize = `颜色:${goods.factory_goods_name} 尺码:${goods.size_name}`; |
26 | } | 29 | } |
@@ -36,8 +39,50 @@ Component({ | @@ -36,8 +39,50 @@ Component({ | ||
36 | 39 | ||
37 | this.setData({goods}); | 40 | this.setData({goods}); |
38 | }, | 41 | }, |
39 | - itemTapped() { | ||
40 | - this.triggerEvent('itemTapped', this.data.item); | 42 | + showToast(title) { |
43 | + wx.showToast({ | ||
44 | + title: title, | ||
45 | + icon: 'none', | ||
46 | + duration: 1000 | ||
47 | + }); | ||
48 | + }, | ||
49 | + editGoodsNum(e) { | ||
50 | + let info = {...this.data.goods}; | ||
51 | + let increment = -1; | ||
52 | + let buyNum; | ||
53 | + | ||
54 | + if (e.target.dataset.type === 'plus') { | ||
55 | + info.isAdd = true; | ||
56 | + increment = -increment; | ||
57 | + } | ||
58 | + | ||
59 | + if (this.data.type === 'bundle') { | ||
60 | + info.pool_buy_number -= -increment; | ||
61 | + buyNum = info.pool_buy_number; | ||
62 | + } else { | ||
63 | + info.buy_number -= -increment; | ||
64 | + buyNum = info.buy_number; | ||
65 | + } | ||
66 | + | ||
67 | + if (buyNum - info.storage_number > 0) { | ||
68 | + return this.showToast('对不起,没有更多库存了'); | ||
69 | + } else if (buyNum - info.min_buy_number < 0) { | ||
70 | + if (info.min_buy_number > 1) { | ||
71 | + return this.showToast(`最低${info.min_buy_number}件起`); | ||
72 | + } | ||
73 | + return; | ||
74 | + } | ||
75 | +console.log(info); | ||
76 | + this.triggerEvent('editGoodsNum', info); | ||
77 | + }, | ||
78 | + editTabAction(e) { | ||
79 | + if (this.editTimer) { | ||
80 | + clearTimeout(this.editTimer); | ||
81 | + } | ||
82 | + | ||
83 | + this.editTimer = setTimeout(() => { | ||
84 | + this.editGoodsNum(e); | ||
85 | + }, 200); | ||
41 | } | 86 | } |
42 | } | 87 | } |
43 | }); | 88 | }); |
1 | <view class="goods-edit-wrap"> | 1 | <view class="goods-edit-wrap"> |
2 | - <view class="num-edit"> | ||
3 | - <view class="cut-btn opt-btn {{goods.cutBtnHide ? 'disable' : ''}}"></view> | 2 | + <view class="num-edit" wx:if="{{!goods.noNumEdit}}"> |
3 | + <view class="cut-btn opt-btn {{goods.cutBtnHide ? 'disable' : ''}}" data-type="cut" bindtap="editTabAction"></view> | ||
4 | <view class="buy-num"> | 4 | <view class="buy-num"> |
5 | <text>{{goods.buy_number}}</text> | 5 | <text>{{goods.buy_number}}</text> |
6 | </view> | 6 | </view> |
7 | - <view class="plus-btn opt-btn {{goods.plusBtnHide ? 'disable' : ''}}"></view> | 7 | + <view class="plus-btn opt-btn {{goods.plusBtnHide ? 'disable' : ''}}" data-type="plus" bindtap="editTabAction"></view> |
8 | </view> | 8 | </view> |
9 | <view class="color-size" wx:if="{{goods.colorSize}}"> | 9 | <view class="color-size" wx:if="{{goods.colorSize}}"> |
10 | <text class="color-size-text">{{goods.colorSize}}</text> | 10 | <text class="color-size-text">{{goods.colorSize}}</text> |
@@ -13,7 +13,8 @@ Component({ | @@ -13,7 +13,8 @@ Component({ | ||
13 | }, | 13 | }, |
14 | isEditing: { | 14 | isEditing: { |
15 | type: Boolean, | 15 | type: Boolean, |
16 | - value: false | 16 | + value: false, |
17 | + observer: '_editChange' | ||
17 | }, | 18 | }, |
18 | isInvalid: { | 19 | isInvalid: { |
19 | type: Boolean, | 20 | type: Boolean, |
@@ -23,6 +24,7 @@ Component({ | @@ -23,6 +24,7 @@ Component({ | ||
23 | methods: { | 24 | methods: { |
24 | _itemChange(item) { | 25 | _itemChange(item) { |
25 | if (item) { | 26 | if (item) { |
27 | + this.selected = item.selected; | ||
26 | item.mark_price = item.sales_price; | 28 | item.mark_price = item.sales_price; |
27 | 29 | ||
28 | switch (item.goods_type) { | 30 | switch (item.goods_type) { |
@@ -58,8 +60,33 @@ Component({ | @@ -58,8 +60,33 @@ Component({ | ||
58 | this.setData({item}); | 60 | this.setData({item}); |
59 | } | 61 | } |
60 | }, | 62 | }, |
61 | - itemTapped() { | ||
62 | - this.triggerEvent('itemTapped', this.data.item); | 63 | + _editChange(isEdit) { |
64 | + let item = {...this.data.item}; | ||
65 | + | ||
66 | + if (isEdit) { | ||
67 | + if (item.selected === 'Y') { | ||
68 | + this.triggerEvent('removeGoodsListInEdit', item); | ||
69 | + } | ||
70 | + } else if (this.selected) { | ||
71 | + item.selected = this.selected; | ||
72 | + | ||
73 | + this.setData({item: item}); | ||
74 | + } | ||
75 | + }, | ||
76 | + chooseItemAction() { | ||
77 | + let item = {...this.data.item}; | ||
78 | + | ||
79 | + if (this.data.isEditing) { | ||
80 | + item.selected = item.selected === 'Y' ? 'N' : 'Y'; | ||
81 | + | ||
82 | + this.triggerEvent('removeGoodsListInEdit', item); | ||
83 | + this.setData({item}); | ||
84 | + } else { | ||
85 | + this.triggerEvent('chooseGoodsItem', item); | ||
86 | + } | ||
87 | + }, | ||
88 | + editGoodsNum(e) { | ||
89 | + this.triggerEvent('editGoodsNum', e.detail); | ||
63 | } | 90 | } |
64 | } | 91 | } |
65 | }); | 92 | }); |
1 | <wxs src="../../../wxs/helper.wxs" module="helper" /> | 1 | <wxs src="../../../wxs/helper.wxs" module="helper" /> |
2 | 2 | ||
3 | -<view class="goods-item" bindtap="itemTapped"> | ||
4 | - <view class="choose-btn"> | 3 | +<view class="goods-item"> |
4 | + <view class="choose-btn" bindtap="chooseItemAction"> | ||
5 | <block wx:if="{{item.goods_type !== 'gift' && !item.batch_no && !item.bundle_activity_id && !isInvalid}}"> | 5 | <block wx:if="{{item.goods_type !== 'gift' && !item.batch_no && !item.bundle_activity_id && !isInvalid}}"> |
6 | <text class="iconfont icon-duihao-fill" wx:if="{{item.selected === 'Y'}}"></text> | 6 | <text class="iconfont icon-duihao-fill" wx:if="{{item.selected === 'Y'}}"></text> |
7 | <text class="iconfont icon-round" wx:else></text> | 7 | <text class="iconfont icon-round" wx:else></text> |
@@ -44,7 +44,7 @@ | @@ -44,7 +44,7 @@ | ||
44 | </view> | 44 | </view> |
45 | <view class="info-edit" wx:if="{{isEditing}}"> | 45 | <view class="info-edit" wx:if="{{isEditing}}"> |
46 | <view class="edit-block"> | 46 | <view class="edit-block"> |
47 | - <cart-edit goods="{{item}}"></cart-edit> | 47 | + <cart-edit goods="{{item}}" bind:editGoodsNum="editGoodsNum"></cart-edit> |
48 | <view class="price"> | 48 | <view class="price"> |
49 | <text class="sale-price">¥ {{helper.round(item.sales_price)}}</text> | 49 | <text class="sale-price">¥ {{helper.round(item.sales_price)}}</text> |
50 | <text wx:if="{{item.mark_price}}" class="mark-price">¥ {{helper.round(item.mark_price)}}</text> | 50 | <text wx:if="{{item.mark_price}}" class="mark-price">¥ {{helper.round(item.mark_price)}}</text> |
1 | 1 | ||
2 | function AllGoodsSelect() { | 2 | function AllGoodsSelect() { |
3 | + let index = 0; | ||
3 | let isSelectAll = true; | 4 | let isSelectAll = true; |
5 | + let lowStorage = false; | ||
6 | + let goodsList = []; | ||
4 | 7 | ||
5 | this.check = function(list) { | 8 | this.check = function(list) { |
6 | (list || []).map(item => { | 9 | (list || []).map(item => { |
7 | - if (!item.bLackStorage && item.goods_type !== 'gift' && item.selected !== 'Y') { | 10 | + goodsList.push(item); |
11 | + | ||
12 | + // 购物车商品唯一key | ||
13 | + item.indexKey = `${item.product_sku}_${index++}`; | ||
14 | + | ||
15 | + if (item.buy_number - item.storage_number > 0 ) { | ||
16 | + lowStorage = true; | ||
17 | + } else if (item.goods_type !== 'gift' && item.selected !== 'Y') { | ||
8 | isSelectAll = false; | 18 | isSelectAll = false; |
9 | } | 19 | } |
10 | }); | 20 | }); |
11 | }; | 21 | }; |
12 | 22 | ||
13 | - this.val = function() { | 23 | + this.isSelectAll = function() { |
14 | return isSelectAll; | 24 | return isSelectAll; |
15 | }; | 25 | }; |
16 | 26 | ||
27 | + this.hasLowStorage = function() { | ||
28 | + return lowStorage; | ||
29 | + } | ||
30 | + | ||
31 | + this.getAllGoodsList = function() { | ||
32 | + return goodsList; | ||
33 | + } | ||
34 | + | ||
17 | return this; | 35 | return this; |
18 | } | 36 | } |
19 | 37 | ||
@@ -123,7 +141,7 @@ function _processGiftList(list, isGift) { | @@ -123,7 +141,7 @@ function _processGiftList(list, isGift) { | ||
123 | * @param params | 141 | * @param params |
124 | * @returns {*} | 142 | * @returns {*} |
125 | */ | 143 | */ |
126 | -const formatOrdinaryCartData = (data) => { | 144 | +const formatOrdinaryCartData = (data, needAllGoods) => { |
127 | data = data || {}; | 145 | data = data || {}; |
128 | data = data.ordinary_cart_data || {}; | 146 | data = data.ordinary_cart_data || {}; |
129 | 147 | ||
@@ -172,7 +190,7 @@ const formatOrdinaryCartData = (data) => { | @@ -172,7 +190,7 @@ const formatOrdinaryCartData = (data) => { | ||
172 | let goodsList = data.goods_list; | 190 | let goodsList = data.goods_list; |
173 | if (goodsList && goodsList.length) { | 191 | if (goodsList && goodsList.length) { |
174 | isEmptyCart = false; | 192 | isEmptyCart = false; |
175 | - allGoodsSelect.check(item.goods_list); | 193 | + allGoodsSelect.check(goodsList); |
176 | ordinaryCart.goodsList = goodsList; | 194 | ordinaryCart.goodsList = goodsList; |
177 | } | 195 | } |
178 | 196 | ||
@@ -194,8 +212,11 @@ const formatOrdinaryCartData = (data) => { | @@ -194,8 +212,11 @@ const formatOrdinaryCartData = (data) => { | ||
194 | isEmptyCart = false; | 212 | isEmptyCart = false; |
195 | } | 213 | } |
196 | 214 | ||
197 | - ordinaryCart.isValidGoodsSelectAll = allGoodsSelect.val(); | ||
198 | ordinaryCart.shoppingCartData = data.shopping_cart_data; | 215 | ordinaryCart.shoppingCartData = data.shopping_cart_data; |
216 | + ordinaryCart.isSelectAll = allGoodsSelect.isSelectAll(); | ||
217 | + ordinaryCart.hasLowStorage = allGoodsSelect.hasLowStorage(); | ||
218 | + | ||
219 | + needAllGoods && (ordinaryCart.allGoodsList = allGoodsSelect.getAllGoodsList()); | ||
199 | 220 | ||
200 | if (data.promotion_info && data.promotion_info.length) { | 221 | if (data.promotion_info && data.promotion_info.length) { |
201 | ordinaryCart.promotionInfo = data.promotion_info; | 222 | ordinaryCart.promotionInfo = data.promotion_info; |
@@ -208,6 +229,40 @@ console.log(ordinaryCart); | @@ -208,6 +229,40 @@ console.log(ordinaryCart); | ||
208 | }; | 229 | }; |
209 | } | 230 | } |
210 | 231 | ||
232 | +const changeGoodsListData = (list, selected, buyNum) => { | ||
233 | + let glist = []; | ||
234 | + | ||
235 | + if (['Y', 'N'].indexOf(selected) < 0) { | ||
236 | + selected = false; | ||
237 | + } | ||
238 | + | ||
239 | + (list || []).map(item => { | ||
240 | + if (!item.lowStorage && item.goods_type !== 'gift') { | ||
241 | + glist.push({ | ||
242 | + buy_number: item.buy_number || 0, | ||
243 | + goods_type: item.goods_type || '', | ||
244 | + product_sku: item.product_sku || '', | ||
245 | + promotion_id: item.promotion_id || 0, | ||
246 | + selected: selected || item.selected, | ||
247 | + activity_id: item.bundle_activity_id || 0, | ||
248 | + batch_no: item.batch_no || 0, | ||
249 | + }); | ||
250 | + } | ||
251 | + }); | ||
252 | + | ||
253 | + return glist; | ||
254 | +} | ||
255 | + | ||
256 | +const changeGoodsBundleData = (bundle, selected, buyNum) => { | ||
257 | + if (!bundle || !bundle.goods_list.length) { | ||
258 | + return []; | ||
259 | + } | ||
260 | + | ||
261 | + return changeGoodsListData(bundle.goods_list, selected, buyNum); | ||
262 | +} | ||
263 | + | ||
211 | export default { | 264 | export default { |
212 | - formatOrdinaryCartData | 265 | + formatOrdinaryCartData, |
266 | + changeGoodsListData, | ||
267 | + changeGoodsBundleData | ||
213 | }; | 268 | }; |
@@ -13,5 +13,70 @@ export default { | @@ -13,5 +13,70 @@ export default { | ||
13 | method: 'app.Shopping.queryCart' | 13 | method: 'app.Shopping.queryCart' |
14 | }, params) | 14 | }, params) |
15 | }); | 15 | }); |
16 | + }, | ||
17 | + /** | ||
18 | + * 选中/取消选中并查询购物车 | ||
19 | + * @param params | ||
20 | + * @returns {*} | ||
21 | + */ | ||
22 | + selectAndQueryCart(params) { | ||
23 | + return api.get({ | ||
24 | + url: '', | ||
25 | + data: Object.assign({ | ||
26 | + method: 'app.Shopping.selectedAndQryCart', | ||
27 | + is_support_mlp: 'Y', | ||
28 | + shopping_key: '' | ||
29 | + }, params) | ||
30 | + }); | ||
31 | + }, | ||
32 | + /** | ||
33 | + * 编辑购物车商品数量 | ||
34 | + * @param params | ||
35 | + * @param isAdd | ||
36 | + * @returns {*} | ||
37 | + */ | ||
38 | + editCartGoodsNum(params, isAdd) { | ||
39 | + if (isAdd) { | ||
40 | + Object.assign(params, { | ||
41 | + method: 'app.Shopping.increase', | ||
42 | + increase_number: 1, | ||
43 | + shopping_key: '' | ||
44 | + }); | ||
45 | + } else { | ||
46 | + Object.assign(params, { | ||
47 | + method: 'app.Shopping.decrease', | ||
48 | + decrease_number: 1, | ||
49 | + shopping_key: '' | ||
50 | + }); | ||
51 | + } | ||
52 | + | ||
53 | + return api.get({ | ||
54 | + url: '', | ||
55 | + data: params | ||
56 | + }); | ||
57 | + }, | ||
58 | + /** | ||
59 | + * 编辑购物车套餐数量 | ||
60 | + * @param params | ||
61 | + * @param isAdd | ||
62 | + * @returns {*} | ||
63 | + */ | ||
64 | + editCartBundleNum(params, isAdd) { | ||
65 | + if (isAdd) { | ||
66 | + Object.assign(params, { | ||
67 | + method: 'app.Shopping.incrBundle', | ||
68 | + increase_number: 1, | ||
69 | + }); | ||
70 | + } else { | ||
71 | + Object.assign(params, { | ||
72 | + method: 'app.Shopping.decrBundle', | ||
73 | + decrease_number: 1, | ||
74 | + }); | ||
75 | + } | ||
76 | + | ||
77 | + return api.get({ | ||
78 | + url: '', | ||
79 | + data: params | ||
80 | + }); | ||
16 | } | 81 | } |
17 | }; | 82 | }; |
1 | +import wx from '../../utils/wx'; | ||
1 | import cartModel from '../../models/cart/cart'; | 2 | import cartModel from '../../models/cart/cart'; |
2 | import cartHandle from '../../models/cart/cart-handle'; | 3 | import cartHandle from '../../models/cart/cart-handle'; |
3 | 4 | ||
4 | const app = getApp(); | 5 | const app = getApp(); |
5 | const router = global.router; | 6 | const router = global.router; |
6 | 7 | ||
8 | +const reverseSelected = { | ||
9 | + Y: 'N', | ||
10 | + N: 'Y' | ||
11 | +}; | ||
12 | + | ||
7 | Page({ | 13 | Page({ |
8 | data: { | 14 | data: { |
9 | isEditing: false | 15 | isEditing: false |
@@ -15,21 +21,207 @@ Page({ | @@ -15,21 +21,207 @@ Page({ | ||
15 | this.getCartData(); | 21 | this.getCartData(); |
16 | 22 | ||
17 | }, | 23 | }, |
24 | + onHide: function () { | ||
25 | + if (this.data.isEditing) { | ||
26 | + this.editCartStatus({clearEditing: true}); | ||
27 | + } | ||
28 | + }, | ||
29 | + showToast(title) { | ||
30 | + wx.showToast({ | ||
31 | + title: title, | ||
32 | + icon: 'none', | ||
33 | + duration: 2000 | ||
34 | + }); | ||
35 | + }, | ||
36 | + showModal(title) { | ||
37 | + return wx.showModal({ | ||
38 | + title: '', | ||
39 | + content: title, | ||
40 | + cancelText: '取消', | ||
41 | + confirmText: '确认', | ||
42 | + confirmColor: '#d0021b' | ||
43 | + }); | ||
44 | + }, | ||
18 | goShopping() { | 45 | goShopping() { |
19 | router.go('home'); | 46 | router.go('home'); |
20 | }, | 47 | }, |
48 | + handleOrdinaryCartData(data) { | ||
49 | + let resData = cartHandle.formatOrdinaryCartData(data, true); | ||
50 | + | ||
51 | + this._allGoodsList = resData.allGoodsList; | ||
52 | + delete resData.allGoodsList; | ||
53 | + this.setData(resData); | ||
54 | + | ||
55 | + return resData; | ||
56 | + }, | ||
21 | getCartData() { | 57 | getCartData() { |
22 | - cartModel.getCartData({uid: app.getUid()}) | ||
23 | - .then(res => { | 58 | + cartModel.getCartData({uid: app.getUid()}).then(res => { |
59 | + if (res.code === 200 && res.data) { | ||
60 | + return this.handleOrdinaryCartData(res.data); | ||
61 | + } else { | ||
62 | + return Promise.reject(); | ||
63 | + } | ||
64 | + }).catch(() => {}); | ||
65 | + }, | ||
66 | + editCartStatus(e) { | ||
67 | + let isEditing = !this.data.isEditing; | ||
68 | + | ||
69 | + if (e.clearEditing) { | ||
70 | + isEditing = false; | ||
71 | + } | ||
72 | + | ||
73 | + this._removeGoodsList = {}; | ||
74 | + this.setData({isEditing}); | ||
75 | + }, | ||
76 | + editCart(list, selected, buyNum) { | ||
77 | + list = cartHandle.changeGoodsListData(list, selected, buyNum); | ||
78 | + | ||
79 | + if (!list.length) { | ||
80 | + return Promise.resolve({}); | ||
81 | + } | ||
82 | + | ||
83 | + return cartModel.selectAndQueryCart({ | ||
84 | + product_sku_list: JSON.stringify(list), | ||
85 | + uid: app.getUid() | ||
86 | + }).then(res => { | ||
24 | if (res.code === 200 && res.data) { | 87 | if (res.code === 200 && res.data) { |
25 | - this.setData(cartHandle.formatOrdinaryCartData(res.data)); | 88 | + return this.handleOrdinaryCartData(res.data); |
26 | } else { | 89 | } else { |
27 | return Promise.reject(); | 90 | return Promise.reject(); |
28 | } | 91 | } |
92 | + }).catch(() => {}); | ||
93 | + }, | ||
94 | + removeCartGoods(list) { | ||
95 | + list = cartHandle.changeGoodsListData(list); | ||
96 | + | ||
97 | + if (!list.length) { | ||
98 | + return Promise.resolve({}); | ||
99 | + } | ||
100 | + | ||
101 | + return cartModel.removeAndQueryCart({ | ||
102 | + product_sku_list: JSON.stringify(list), | ||
103 | + uid: app.getUid() | ||
104 | + }).then(res => { | ||
105 | + if (res && res.code === 200) { | ||
106 | + return this.handleOrdinaryCartData(res.data); | ||
107 | + } | ||
108 | + }); | ||
109 | + }, | ||
110 | + chooseGoodsItem(e) { | ||
111 | + let item = e.detail; | ||
112 | + | ||
113 | + if (item.selected !== 'Y' && item.buy_number - item.storage_number > 0) { | ||
114 | + return this.showToast('您勾选的商品库存不足'); | ||
115 | + } | ||
116 | + | ||
117 | + item.selected = reverseSelected[item.selected] || 'Y'; | ||
118 | + this.editCart([item]); | ||
119 | + }, | ||
120 | + chooseGoodsBundle(e) { | ||
121 | + let bundle = e.detail; | ||
122 | + | ||
123 | + if (bundle.selected !== 'Y' && bundle.pool_buy_number - bundle.pool_storage_number > 0) { | ||
124 | + return this.showToast('您勾选的商品库存不足'); | ||
125 | + } | ||
126 | + | ||
127 | + let selected = reverseSelected[bundle.selected] || 'Y'; | ||
128 | + this.editCart(bundle.goods_list, selected); | ||
129 | + }, | ||
130 | + editGoodsNum(e) { | ||
131 | + let goods = e.detail; | ||
132 | + | ||
133 | + if (goods) { | ||
134 | + return cartModel.editCartGoodsNum({ | ||
135 | + product_sku: goods.product_sku, | ||
136 | + uid: app.getUid() | ||
137 | + }, goods.isAdd).then(res => { | ||
138 | + if (res && res.code === 200) { | ||
139 | + this.editCart([goods], 'Y'); | ||
140 | + } | ||
29 | }) | 141 | }) |
30 | - .catch(() => {}); | 142 | + } |
31 | }, | 143 | }, |
32 | - editCartAction() { | ||
33 | - this.setData({isEditing: !this.data.isEditing}); | 144 | + editBundleNum(e) { |
145 | + let bundle = e.detail; | ||
146 | + | ||
147 | + if (bundle) { | ||
148 | + return cartModel.editCartBundleNum({ | ||
149 | + activity_id: bundle.pool_id, | ||
150 | + batch_no: bundle.pool_batch_no, | ||
151 | + uid: app.getUid() | ||
152 | + }, bundle.isAdd).then(res => { | ||
153 | + if (res && res.code === 200) { | ||
154 | + this.editCart(bundle.goods_list, 'Y'); | ||
155 | + } | ||
156 | + }) | ||
157 | + } | ||
158 | + }, | ||
159 | + removeGoodsListInEdit(e) { | ||
160 | + let info = e.detail; | ||
161 | + | ||
162 | + if (info.goods_list) { | ||
163 | + let list = info.goods_list || []; | ||
164 | + | ||
165 | + list.map(item => { | ||
166 | + this._removeGoodsList[item.indexKey] = info.selected === 'Y' ? item : false; | ||
167 | + }); | ||
168 | + } else { | ||
169 | + this._removeGoodsList[info.indexKey] = info.selected === 'Y' ? info : false; | ||
170 | + } | ||
171 | + }, | ||
172 | + mutilRemoveGoods() { | ||
173 | + let removeList = []; | ||
174 | + | ||
175 | + this._removeGoodsList = this._removeGoodsList || []; | ||
176 | + | ||
177 | + for (let i in this._removeGoodsList) { | ||
178 | + if (this._removeGoodsList.hasOwnProperty(i) && this._removeGoodsList[i]) { | ||
179 | + removeList.push(this._removeGoodsList[i]); | ||
180 | + }; | ||
181 | + } | ||
182 | + | ||
183 | + if (!removeList.length) { | ||
184 | + return this.showToast('请勾选您要删除的商品'); | ||
185 | + } | ||
186 | + | ||
187 | + this.showModal('是否删除选中的全部商品?').then(res => { | ||
188 | + if (!res.confirm) { | ||
189 | + return; | ||
190 | + } | ||
191 | + | ||
192 | + return this.removeCartGoods(removeList); | ||
193 | + }); | ||
194 | + }, | ||
195 | + cleanInvalidGoods() { | ||
196 | + this.showModal('是否确认清空所有失效商品?').then(res => { | ||
197 | + if (!res.confirm) { | ||
198 | + return; | ||
199 | + } | ||
200 | + | ||
201 | + let invalidGoods = this.data.invalidGoodsList; | ||
202 | + let invalidList = []; | ||
203 | + | ||
204 | + if (invalidGoods && invalidGoods.length) { | ||
205 | + invalidGoods.map(list => { | ||
206 | + invalidList.push.apply(invalidList, list); | ||
207 | + }) | ||
208 | + } | ||
209 | + | ||
210 | + return this.removeCartGoods(invalidList); | ||
211 | + }); | ||
212 | + }, | ||
213 | + selectAllGoods() { | ||
214 | + let isSelectAll = this.data.isSelectAll; | ||
215 | + | ||
216 | + if (this.data.isEditing) { | ||
217 | + // TODO; | ||
218 | + return; | ||
219 | + } | ||
220 | + | ||
221 | + this.editCart(this._allGoodsList, isSelectAll ? 'N' : 'Y').then(res => { | ||
222 | + if (!isSelectAll && res && res.hasLowStorage) { | ||
223 | + this.showToast('您全选的商品中存在库存不足商品,已帮您自动取消勾选成功'); | ||
224 | + } | ||
225 | + }); | ||
34 | } | 226 | } |
35 | }); | 227 | }); |
@@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
2 | "navigationBarTitleText": "购物车", | 2 | "navigationBarTitleText": "购物车", |
3 | "usingComponents": { | 3 | "usingComponents": { |
4 | "cart-item": "/components/cart/item/item", | 4 | "cart-item": "/components/cart/item/item", |
5 | - "cart-edit": "/components/cart/edit/edit" | 5 | + "cart-edit": "/components/cart/edit/edit", |
6 | + "cart-bundle-head": "/components/cart/bundle/head" | ||
6 | } | 7 | } |
7 | } | 8 | } |
@@ -24,7 +24,7 @@ | @@ -24,7 +24,7 @@ | ||
24 | <text class="iconfont icon-top" bindtap='tapPriceDownTipsAction'></text> | 24 | <text class="iconfont icon-top" bindtap='tapPriceDownTipsAction'></text> |
25 | </view> | 25 | </view> |
26 | <view wx:else class="shipping-cost-tips">{{shippingCostTips}}</view> | 26 | <view wx:else class="shipping-cost-tips">{{shippingCostTips}}</view> |
27 | - <view class="edit-cart-btn" bindtap="editCartAction">{{isEditing ? '完成' : '编辑商品'}}</view> | 27 | + <view class="edit-cart-btn" bindtap="editCartStatus">{{isEditing ? '完成' : '编辑商品'}}</view> |
28 | </view> | 28 | </view> |
29 | </view> | 29 | </view> |
30 | 30 | ||
@@ -58,13 +58,13 @@ | @@ -58,13 +58,13 @@ | ||
58 | 58 | ||
59 | <view class="footer-wrap"> | 59 | <view class="footer-wrap"> |
60 | <view class="footer-fixed"> | 60 | <view class="footer-fixed"> |
61 | - <view class="select-all-btn"> | 61 | + <view class="select-all-btn" bindtap="selectAllGoods"> |
62 | <text class="iconfont icon-duihao-fill" wx:if="{{isSelectAll}}"></text> | 62 | <text class="iconfont icon-duihao-fill" wx:if="{{isSelectAll}}"></text> |
63 | <text class="iconfont icon-round" wx:else></text> | 63 | <text class="iconfont icon-round" wx:else></text> |
64 | <text>全选</text> | 64 | <text>全选</text> |
65 | </view> | 65 | </view> |
66 | <view class="settlement-block"> | 66 | <view class="settlement-block"> |
67 | - <view class="delete-btn footer-option-btn" bindtap="delChoosedAction" wx:if="{{isEditing}}"> | 67 | + <view class="delete-btn footer-option-btn" bindtap="mutilRemoveGoods" wx:if="{{isEditing}}"> |
68 | <text>删除</text> | 68 | <text>删除</text> |
69 | </view> | 69 | </view> |
70 | <block wx:else> | 70 | <block wx:else> |
1 | <template name="cartGoodsList"> | 1 | <template name="cartGoodsList"> |
2 | <block wx:if="{{goodsList.length}}"> | 2 | <block wx:if="{{goodsList.length}}"> |
3 | <block wx:for="{{goodsList}}" wx:key="unique"> | 3 | <block wx:for="{{goodsList}}" wx:key="unique"> |
4 | - <cart-item item="{{item}}" index="{{index}}" isEditing="{{isEditing}}" isInvalid="{{isInvalid}}"></cart-item> | 4 | + <cart-item item="{{item}}" index="{{index}}" isEditing="{{isEditing}}" isInvalid="{{isInvalid}}" bind:chooseGoodsItem="chooseGoodsItem" bind:removeGoodsListInEdit="removeGoodsListInEdit" bind:editGoodsNum="editGoodsNum"></cart-item> |
5 | </block> | 5 | </block> |
6 | </block> | 6 | </block> |
7 | </template> | 7 | </template> |
@@ -17,24 +17,7 @@ | @@ -17,24 +17,7 @@ | ||
17 | </block> | 17 | </block> |
18 | </block> | 18 | </block> |
19 | 19 | ||
20 | - <view class="bundle-goods" wx:if="{{item.pool_type === 3 && item.pool_batch_no}}"> | ||
21 | - <view class='bundle-title'> | ||
22 | - <view class="choose-btn"> | ||
23 | - <text class="iconfont icon-duihao-fill" wx:if="{{item.selected === 'Y'}}"></text> | ||
24 | - <text class="iconfont icon-round" wx:else></text> | ||
25 | - </view> | ||
26 | - <view class="bundle-tag">优惠套装</view> | ||
27 | - <view class="bundle-name">{{item.pool_title}}</view> | ||
28 | - <view class='bundle-buy-num' wx:if="{{!isEditing}}">x {{item.pool_buy_number}}</view> | ||
29 | - </view> | ||
30 | - <view class="edit-wrap" wx:if="{{isEditing}}"> | ||
31 | - <view class="bundle-edit-title">优惠数量</view> | ||
32 | - <view class="bundle-edit-num"> | ||
33 | - <cart-edit goods="{{item}}" type="{{'bundle'}}"></cart-edit> | ||
34 | - </view> | ||
35 | - <view class='bundle-buy-num'>x {{item.pool_buy_number}}</view> | ||
36 | - </view> | ||
37 | - </view> | 20 | + <cart-bundle-head item="{{item}}" index="{{index}}" isEditing="{{isEditing}}" bind:chooseGoodsBundle="chooseGoodsBundle" bind:removeGoodsListInEdit="removeGoodsListInEdit" bind:editBundleNum="editBundleNum"></cart-bundle-head> |
38 | 21 | ||
39 | <template is="cartGoodsList" data="{{goodsList: item.goods_list, isEditing}}"/> | 22 | <template is="cartGoodsList" data="{{goodsList: item.goods_list, isEditing}}"/> |
40 | 23 |
@@ -8,39 +8,6 @@ | @@ -8,39 +8,6 @@ | ||
8 | border-bottom: 1rpx solid #f0f0f0; | 8 | border-bottom: 1rpx solid #f0f0f0; |
9 | } | 9 | } |
10 | 10 | ||
11 | -.goods-pool-list .bundle-title { | ||
12 | - height: 80rpx; | ||
13 | - line-height: 80rpx; | ||
14 | - border-bottom: 1rpx solid #f0f0f0; | ||
15 | - font-size: 0; | ||
16 | -} | ||
17 | - | ||
18 | -.goods-pool-list .bundle-title > view { | ||
19 | - display: inline-block; | ||
20 | - font-size: 24rpx; | ||
21 | -} | ||
22 | - | ||
23 | -.goods-pool-list .bundle-title .choose-btn { | ||
24 | - width: 90rpx; | ||
25 | - text-align: center; | ||
26 | -} | ||
27 | - | ||
28 | -.goods-pool-list .bundle-title .bundle-tag { | ||
29 | - line-height: 1; | ||
30 | - padding: 5rpx 7rpx; | ||
31 | - border-radius: 4rpx; | ||
32 | - background-color: #d0021b; | ||
33 | - color: #fff; | ||
34 | - margin-right: 10rpx; | ||
35 | -} | ||
36 | - | ||
37 | -.goods-pool-list .bundle-goods .bundle-buy-num { | ||
38 | - position: absolute; | ||
39 | - right: 30rpx; | ||
40 | - font-size: 26rpx; | ||
41 | - color: #b0b0b0; | ||
42 | -} | ||
43 | - | ||
44 | .goods-pool-list .edit-wrap { | 11 | .goods-pool-list .edit-wrap { |
45 | padding: 16rpx 90rpx; | 12 | padding: 16rpx 90rpx; |
46 | padding-right: 0; | 13 | padding-right: 0; |
@@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
5 | <template is="cartGoodsList" data="{{goodsList: invalidGoodsList, isInvalid: true}}"/> | 5 | <template is="cartGoodsList" data="{{goodsList: invalidGoodsList, isInvalid: true}}"/> |
6 | 6 | ||
7 | <view class="clean-invalid-wrap"> | 7 | <view class="clean-invalid-wrap"> |
8 | - <text class="clean-invalid-btn" bindtap="cleanInvalidAction">清空无效商品</text> | 8 | + <text class="clean-invalid-btn" bindtap="cleanInvalidGoods">清空无效商品</text> |
9 | </view> | 9 | </view> |
10 | 10 | ||
11 | <view class="split-line"></view> | 11 | <view class="split-line"></view> |
-
Please register or login to post a comment