Authored by jinhu.tung

send to favorites

... ... @@ -11,7 +11,7 @@ const _ = require('lodash');
exports.index = (req, res) => {
const shoppingKey = req.cookies._SPK || null;
const uid = req.user.uid || null;
const uid = '14555212'; // req.user.uid || null;
cartModel.getCartData(shoppingKey, uid).then((result) => {
if (result.code === 200) {
... ... @@ -96,7 +96,7 @@ exports.changeProductNum = (req, res) => {
// 删除商品
exports.removeProduct = (req, res) => {
const params = {};
const uid = req.user.uid;
const uid = '14555212';// req.user.uid;
const shoppingKey = req.cookies._SPK;
const productSkuList = req.body.skuList;
... ... @@ -122,9 +122,23 @@ exports.removeProduct = (req, res) => {
// 收藏商品
exports.sendToFavorite = (req, res) => {
// TODO
res.json({
code: '0'
const params = {};
const uid = '14555212';// req.user.uid;
const productSkuList = req.body.skuList;
if (uid) {
_.merge(params, {uid});
}
if (productSkuList) {
_.merge(params, {product_sku_list: productSkuList});
}
console.log('transferToFavorite---params:', params);
cartModel.transferToFavorite(params).then(result => {
console.log('transferToFavorite-result:', result);
res.json(_.merge(cartModel.filterCartData(result, uid), {code: result.code, message: result.message}));
});
};
... ...
... ... @@ -112,16 +112,10 @@ const getCartData = (shoppingKey, uid) => {
* @param { Boolean } hasPromotion 是否有促销ID, 默认值是false
* @return { Array }
*/
const transferToFavorite = (uid, sku, hasPromotion) => {
let method = hasPromotion ? 'app.Shopping.addfavoriteAndCart' : 'app.Shopping.addfavorite';
let params = { method };
_.merge(params, {
product_sku_list: sku,
uid // 用户必须登录吗 TODO
});
const transferToFavorite = (params) => {
let method = 'app.Shopping.addfavoriteAndCart';
_.merge(params, {method});
return api.get('', params);
};
... ...
... ... @@ -18,7 +18,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/remove', cartCtrl.removeProduct);
router.post('/cart/product/:productId/send_to_favorite', cartCtrl.sendToFavorite);
router.post('/cart/product/send_to_favorite', cartCtrl.sendToFavorite);
router.get('/cart/product/:productId/edit', cartCtrl.editProduct);
router.post('/cart/add', cartCtrl.addToCart);
router.post('/cart/toggleSelectGoods', cartCtrl.toggleSelectGoods);
... ...
... ... @@ -17,14 +17,28 @@ $(function() {
Cart.removePro($(this).parents('ul').children().first().attr('data-product_info'));
}).delegate('.send-to-favorite', 'click', function() {
// 移入收藏夹
Cart.sendToFavorite($(this).attr('data-productId'));
Cart.sendToFavorite([$.parseJSON($(this).parents('ul').children().first().attr('data-product_info'))]);
}).delegate('#send_favorite', 'click', function(e) {
// 将多个商品移入收藏夹
// 选择的商品
var selectedProducts = [],
product;
e.preventDefault();
$('#cart_content').find('li.chk').each(function() {
product = $(this);
if (product.find('label.chk-group').length) {
selectedProducts.push($.parseJSON(product.attr('data-product_info')));
}
});
Cart.sendToFavorite(selectedProducts);
}).delegate('.editable', 'click', function() {
// 编辑商品颜色和属性
Cart.editColorOrSize($(this).attr('data-productId'));
}).delegate('#checkout_btn', 'click', function(e) {
e.preventDefault();
if(!$(this).hasClass('disable')) {
window.location.href = "/shopping/order";
if (!$(this).hasClass('disable')) {
window.location.href = '/shopping/order';
}
});
... ...
... ... @@ -209,35 +209,36 @@ var Cart = {
data: {skuList: JSON.stringify([$.parseJSON(products)])},
type: 'DELETE',
success: function(res) {
if (res.code === 200) {
Cart.refreshCart(res);
} else {
_alert(res.message);
}
},
fail: function() {
// TODO
Cart.refreshCart(res);
}
});
}
}).show();
},
// 移入收藏夹
sendToFavorite: function(productId) {
var dialog = new _confirm({
content: '确定要将该商品从购物车中移入收藏吗?<br/>移入收藏后该商品将不在购物车中显示',
/*
* 删除商品
* @function [removePro]
* @params { Array } products 商品列表
*/
sendToFavorite: function(products) {
var msg = '确定要将该商品从购物车中移入收藏吗?<br/>移入收藏后该商品将不在购物车中显示';
var dialog;
if (products.length > 1) {
msg = '确定要将已选中的商品从购物车中移入收藏吗?<br/>移入收藏后已选中的商品将不在购物车中显示';
}
dialog = new _confirm({
content: msg,
cb: function() {
dialog.close();
Util.ajax({
url: '/shopping/cart/product/' + productId + '/send_to_favorite',
url: '/shopping/cart/product/send_to_favorite',
type: 'POST',
data: {skuList: JSON.stringify(products)},
success: function(res) {
if (res.code === '0') {
dialog.close();
}
},
fail: function() {
// TODO
Cart.refreshCart(res);
}
});
}
... ...
... ... @@ -15,8 +15,10 @@ var Util = {
data: options.data || {},
dataType: 'json'
}).done(function(res) {
if (options.success) {
if (options.success && res.code === 200) {
options.success(res);
} else {
new _alert(res.message).show();
}
}).fail(function() {
if (options.fail) {
... ...
... ... @@ -60,11 +60,11 @@
.checkout-total {
position: relative;
display: inline-block;
float: right;
font-size: 14px;
color: #1b1b1b;
font-weight: bold;
width: 358px;
width: 350px;
div {
display: inline-block;
... ... @@ -90,7 +90,7 @@
.checkout {
margin-top: 40px;
float: right;
margin-right: 200px;
margin-right: 192px;
.btn {
padding: 14px 59px;
... ...