Showing
7 changed files
with
66 additions
and
41 deletions
@@ -11,7 +11,7 @@ const _ = require('lodash'); | @@ -11,7 +11,7 @@ const _ = require('lodash'); | ||
11 | 11 | ||
12 | exports.index = (req, res) => { | 12 | exports.index = (req, res) => { |
13 | const shoppingKey = req.cookies._SPK || null; | 13 | const shoppingKey = req.cookies._SPK || null; |
14 | - const uid = req.user.uid || null; | 14 | + const uid = '14555212'; // req.user.uid || null; |
15 | 15 | ||
16 | cartModel.getCartData(shoppingKey, uid).then((result) => { | 16 | cartModel.getCartData(shoppingKey, uid).then((result) => { |
17 | if (result.code === 200) { | 17 | if (result.code === 200) { |
@@ -96,7 +96,7 @@ exports.changeProductNum = (req, res) => { | @@ -96,7 +96,7 @@ exports.changeProductNum = (req, res) => { | ||
96 | // 删除商品 | 96 | // 删除商品 |
97 | exports.removeProduct = (req, res) => { | 97 | exports.removeProduct = (req, res) => { |
98 | const params = {}; | 98 | const params = {}; |
99 | - const uid = req.user.uid; | 99 | + const uid = '14555212';// req.user.uid; |
100 | const shoppingKey = req.cookies._SPK; | 100 | const shoppingKey = req.cookies._SPK; |
101 | const productSkuList = req.body.skuList; | 101 | const productSkuList = req.body.skuList; |
102 | 102 | ||
@@ -122,9 +122,23 @@ exports.removeProduct = (req, res) => { | @@ -122,9 +122,23 @@ exports.removeProduct = (req, res) => { | ||
122 | 122 | ||
123 | // 收藏商品 | 123 | // 收藏商品 |
124 | exports.sendToFavorite = (req, res) => { | 124 | exports.sendToFavorite = (req, res) => { |
125 | - // TODO | ||
126 | - res.json({ | ||
127 | - code: '0' | 125 | + const params = {}; |
126 | + const uid = '14555212';// req.user.uid; | ||
127 | + const productSkuList = req.body.skuList; | ||
128 | + | ||
129 | + if (uid) { | ||
130 | + _.merge(params, {uid}); | ||
131 | + } | ||
132 | + | ||
133 | + if (productSkuList) { | ||
134 | + _.merge(params, {product_sku_list: productSkuList}); | ||
135 | + } | ||
136 | + | ||
137 | + console.log('transferToFavorite---params:', params); | ||
138 | + | ||
139 | + cartModel.transferToFavorite(params).then(result => { | ||
140 | + console.log('transferToFavorite-result:', result); | ||
141 | + res.json(_.merge(cartModel.filterCartData(result, uid), {code: result.code, message: result.message})); | ||
128 | }); | 142 | }); |
129 | }; | 143 | }; |
130 | 144 |
@@ -112,16 +112,10 @@ const getCartData = (shoppingKey, uid) => { | @@ -112,16 +112,10 @@ const getCartData = (shoppingKey, uid) => { | ||
112 | * @param { Boolean } hasPromotion 是否有促销ID, 默认值是false | 112 | * @param { Boolean } hasPromotion 是否有促销ID, 默认值是false |
113 | * @return { Array } | 113 | * @return { Array } |
114 | */ | 114 | */ |
115 | -const transferToFavorite = (uid, sku, hasPromotion) => { | ||
116 | - let method = hasPromotion ? 'app.Shopping.addfavoriteAndCart' : 'app.Shopping.addfavorite'; | ||
117 | - | ||
118 | - let params = { method }; | ||
119 | - | ||
120 | - _.merge(params, { | ||
121 | - product_sku_list: sku, | ||
122 | - uid // 用户必须登录吗 TODO | ||
123 | - }); | 115 | +const transferToFavorite = (params) => { |
116 | + let method = 'app.Shopping.addfavoriteAndCart'; | ||
124 | 117 | ||
118 | + _.merge(params, {method}); | ||
125 | return api.get('', params); | 119 | return api.get('', params); |
126 | }; | 120 | }; |
127 | 121 |
@@ -18,7 +18,7 @@ router.get('/cart', cartCtrl.index); | @@ -18,7 +18,7 @@ router.get('/cart', cartCtrl.index); | ||
18 | router.get('/cart/product/check_inventory', cartCtrl.checkInventory); | 18 | router.get('/cart/product/check_inventory', cartCtrl.checkInventory); |
19 | router.post('/cart/product/:productId/change_num', cartCtrl.changeProductNum); | 19 | router.post('/cart/product/:productId/change_num', cartCtrl.changeProductNum); |
20 | router.delete('/cart/product/remove', cartCtrl.removeProduct); | 20 | router.delete('/cart/product/remove', cartCtrl.removeProduct); |
21 | -router.post('/cart/product/:productId/send_to_favorite', cartCtrl.sendToFavorite); | 21 | +router.post('/cart/product/send_to_favorite', cartCtrl.sendToFavorite); |
22 | router.get('/cart/product/:productId/edit', cartCtrl.editProduct); | 22 | router.get('/cart/product/:productId/edit', cartCtrl.editProduct); |
23 | router.post('/cart/add', cartCtrl.addToCart); | 23 | router.post('/cart/add', cartCtrl.addToCart); |
24 | router.post('/cart/toggleSelectGoods', cartCtrl.toggleSelectGoods); | 24 | router.post('/cart/toggleSelectGoods', cartCtrl.toggleSelectGoods); |
@@ -17,14 +17,28 @@ $(function() { | @@ -17,14 +17,28 @@ $(function() { | ||
17 | Cart.removePro($(this).parents('ul').children().first().attr('data-product_info')); | 17 | Cart.removePro($(this).parents('ul').children().first().attr('data-product_info')); |
18 | }).delegate('.send-to-favorite', 'click', function() { | 18 | }).delegate('.send-to-favorite', 'click', function() { |
19 | // 移入收藏夹 | 19 | // 移入收藏夹 |
20 | - Cart.sendToFavorite($(this).attr('data-productId')); | 20 | + Cart.sendToFavorite([$.parseJSON($(this).parents('ul').children().first().attr('data-product_info'))]); |
21 | + }).delegate('#send_favorite', 'click', function(e) { | ||
22 | + // 将多个商品移入收藏夹 | ||
23 | + // 选择的商品 | ||
24 | + var selectedProducts = [], | ||
25 | + product; | ||
26 | + | ||
27 | + e.preventDefault(); | ||
28 | + $('#cart_content').find('li.chk').each(function() { | ||
29 | + product = $(this); | ||
30 | + if (product.find('label.chk-group').length) { | ||
31 | + selectedProducts.push($.parseJSON(product.attr('data-product_info'))); | ||
32 | + } | ||
33 | + }); | ||
34 | + Cart.sendToFavorite(selectedProducts); | ||
21 | }).delegate('.editable', 'click', function() { | 35 | }).delegate('.editable', 'click', function() { |
22 | // 编辑商品颜色和属性 | 36 | // 编辑商品颜色和属性 |
23 | Cart.editColorOrSize($(this).attr('data-productId')); | 37 | Cart.editColorOrSize($(this).attr('data-productId')); |
24 | }).delegate('#checkout_btn', 'click', function(e) { | 38 | }).delegate('#checkout_btn', 'click', function(e) { |
25 | e.preventDefault(); | 39 | e.preventDefault(); |
26 | - if(!$(this).hasClass('disable')) { | ||
27 | - window.location.href = "/shopping/order"; | 40 | + if (!$(this).hasClass('disable')) { |
41 | + window.location.href = '/shopping/order'; | ||
28 | } | 42 | } |
29 | }); | 43 | }); |
30 | 44 |
@@ -209,35 +209,36 @@ var Cart = { | @@ -209,35 +209,36 @@ var Cart = { | ||
209 | data: {skuList: JSON.stringify([$.parseJSON(products)])}, | 209 | data: {skuList: JSON.stringify([$.parseJSON(products)])}, |
210 | type: 'DELETE', | 210 | type: 'DELETE', |
211 | success: function(res) { | 211 | success: function(res) { |
212 | - if (res.code === 200) { | ||
213 | - Cart.refreshCart(res); | ||
214 | - } else { | ||
215 | - _alert(res.message); | ||
216 | - } | ||
217 | - }, | ||
218 | - fail: function() { | ||
219 | - // TODO | 212 | + Cart.refreshCart(res); |
220 | } | 213 | } |
221 | }); | 214 | }); |
222 | } | 215 | } |
223 | }).show(); | 216 | }).show(); |
224 | }, | 217 | }, |
225 | 218 | ||
226 | - // 移入收藏夹 | ||
227 | - sendToFavorite: function(productId) { | ||
228 | - var dialog = new _confirm({ | ||
229 | - content: '确定要将该商品从购物车中移入收藏吗?<br/>移入收藏后该商品将不在购物车中显示', | 219 | + /* |
220 | + * 删除商品 | ||
221 | + * @function [removePro] | ||
222 | + * @params { Array } products 商品列表 | ||
223 | + */ | ||
224 | + sendToFavorite: function(products) { | ||
225 | + var msg = '确定要将该商品从购物车中移入收藏吗?<br/>移入收藏后该商品将不在购物车中显示'; | ||
226 | + var dialog; | ||
227 | + | ||
228 | + if (products.length > 1) { | ||
229 | + msg = '确定要将已选中的商品从购物车中移入收藏吗?<br/>移入收藏后已选中的商品将不在购物车中显示'; | ||
230 | + } | ||
231 | + | ||
232 | + dialog = new _confirm({ | ||
233 | + content: msg, | ||
230 | cb: function() { | 234 | cb: function() { |
235 | + dialog.close(); | ||
231 | Util.ajax({ | 236 | Util.ajax({ |
232 | - url: '/shopping/cart/product/' + productId + '/send_to_favorite', | 237 | + url: '/shopping/cart/product/send_to_favorite', |
233 | type: 'POST', | 238 | type: 'POST', |
239 | + data: {skuList: JSON.stringify(products)}, | ||
234 | success: function(res) { | 240 | success: function(res) { |
235 | - if (res.code === '0') { | ||
236 | - dialog.close(); | ||
237 | - } | ||
238 | - }, | ||
239 | - fail: function() { | ||
240 | - // TODO | 241 | + Cart.refreshCart(res); |
241 | } | 242 | } |
242 | }); | 243 | }); |
243 | } | 244 | } |
@@ -15,8 +15,10 @@ var Util = { | @@ -15,8 +15,10 @@ var Util = { | ||
15 | data: options.data || {}, | 15 | data: options.data || {}, |
16 | dataType: 'json' | 16 | dataType: 'json' |
17 | }).done(function(res) { | 17 | }).done(function(res) { |
18 | - if (options.success) { | 18 | + if (options.success && res.code === 200) { |
19 | options.success(res); | 19 | options.success(res); |
20 | + } else { | ||
21 | + new _alert(res.message).show(); | ||
20 | } | 22 | } |
21 | }).fail(function() { | 23 | }).fail(function() { |
22 | if (options.fail) { | 24 | if (options.fail) { |
@@ -60,11 +60,11 @@ | @@ -60,11 +60,11 @@ | ||
60 | 60 | ||
61 | .checkout-total { | 61 | .checkout-total { |
62 | position: relative; | 62 | position: relative; |
63 | - display: inline-block; | 63 | + float: right; |
64 | font-size: 14px; | 64 | font-size: 14px; |
65 | color: #1b1b1b; | 65 | color: #1b1b1b; |
66 | font-weight: bold; | 66 | font-weight: bold; |
67 | - width: 358px; | 67 | + width: 350px; |
68 | 68 | ||
69 | div { | 69 | div { |
70 | display: inline-block; | 70 | display: inline-block; |
@@ -90,7 +90,7 @@ | @@ -90,7 +90,7 @@ | ||
90 | .checkout { | 90 | .checkout { |
91 | margin-top: 40px; | 91 | margin-top: 40px; |
92 | float: right; | 92 | float: right; |
93 | - margin-right: 200px; | 93 | + margin-right: 192px; |
94 | 94 | ||
95 | .btn { | 95 | .btn { |
96 | padding: 14px 59px; | 96 | padding: 14px 59px; |
-
Please register or login to post a comment