diff --git a/apps/shopping/controllers/cart.js b/apps/shopping/controllers/cart.js index 7f7b186..995307d 100644 --- a/apps/shopping/controllers/cart.js +++ b/apps/shopping/controllers/cart.js @@ -113,5 +113,13 @@ exports.removeProduct = (req, res) => { // TODO res.json({ code: '0' - }) -} \ No newline at end of file + }); +}; + +// 收藏商品 +exports.sendToFavorite = (req, res) => { + // TODO + res.json({ + code: '0' + }); +} diff --git a/apps/shopping/router.js b/apps/shopping/router.js index f0b6d6b..67aa328 100644 --- a/apps/shopping/router.js +++ b/apps/shopping/router.js @@ -16,6 +16,7 @@ router.get('/cart', cartCtrl.index); router.get('/cart/product/check_inventory', cartCtrl.checkInventory); router.post('/cart/product/:productId/change_num', cartCtrl.changeProductNum); router.delete('/cart/product/:productId', cartCtrl.removeProduct); +router.post('/cart/product/:productId/send_to_favorite', cartCtrl.sendToFavorite); module.exports = router; diff --git a/public/js/shopping/cart.js b/public/js/shopping/cart.js index bdb67c5..a06adce 100644 --- a/public/js/shopping/cart.js +++ b/public/js/shopping/cart.js @@ -95,19 +95,41 @@ var Cart = { var dialog = new _confirm({ content: '您确定要从购物车中删除该商品吗?', cb: function() { - console.log('confirm:', productId) + console.log('confirm:', productId); Util.ajax({ url: '/shopping/cart/product/' + productId, type: 'DELETE', success: function(res) { - if(res.code === '0') { + if (res.code === '0') { dialog.close(); } }, - fail: function () { + fail: function() { // TODO } - }) + }); + } + }).show(); + }, + + // 移入收藏夹 + sendToFavorite: function(productId) { + var dialog = new _confirm({ + content: '确定要将该商品从购物车中移入收藏吗?<br/>移入收藏后该商品将不在购物车中显示', + cb: function() { + console.log('confirm:', productId); + Util.ajax({ + url: '/shopping/cart/product/' + productId + '/send_to_favorite', + type: 'POST', + success: function(res) { + if (res.code === '0') { + dialog.close(); + } + }, + fail: function() { + // TODO + } + }); } }).show(); } diff --git a/public/js/shopping/cart.page.js b/public/js/shopping/cart.page.js index ab6e78b..54ac319 100644 --- a/public/js/shopping/cart.page.js +++ b/public/js/shopping/cart.page.js @@ -82,10 +82,13 @@ $(function() { // 变动商品数量 Stepper.init(); - console.log($('.remove-item')) + // 删除商品 $('.remove-item').on('click', function() { - console.log(111) Cart.removePro($(this).attr('data-productId')); }); + // 移入收藏夹 + $('.send-to-favorite').on('click', function() { + Cart.sendToFavorite($(this).attr('data-productId')); + }); });