Authored by htoooth

Merge remote-tracking branch 'origin/release/1.0' into release/1.0

... ... @@ -9,12 +9,12 @@
const cartModel = require('../models/cart');
const _ = require('lodash');
// 购物车首页
exports.index = (req, res, next) => {
const shoppingKey = req.cookies._SPK || null;
const uid = req.user.uid || null;
cartModel.getCartData(shoppingKey, uid).then((result) => {
// console.log('Cart current Data:', JSON.stringify(result, '', 4))
if (result.code === 200) {
res.display('cart', _.merge({
module: 'shopping',
... ... @@ -32,11 +32,9 @@ exports.index = (req, res, next) => {
};
// 修改数量
// 通过stepper修改购物车商品数量
exports.changeProductNum = (req, res, next) => {
const changeType = req.body.changeType;
// const changeTo = req.body.changeTo;
const uid = req.user.uid;
const shoppingKey = req.cookies._SPK;
const sku = req.body.sku;
... ... @@ -50,7 +48,6 @@ exports.changeProductNum = (req, res, next) => {
sku,
goodTpye
}).then(result => {
// console.log('changeProductNum-INCREASE-result:', result);
if (result.code === 200) {
cartModel.getCartData(shoppingKey, uid).then(cartData => {
res.json(_.merge(
... ... @@ -62,7 +59,6 @@ exports.changeProductNum = (req, res, next) => {
res.json(result);
}
}).catch(next);
} else if (changeType === 'DECREASE') {
cartModel.modifyProductNum({
decreaseNum: 1, // 默认是1
... ... @@ -71,7 +67,6 @@ exports.changeProductNum = (req, res, next) => {
sku,
goodTpye
}).then(result => {
// console.log('changeProductNum-DECREASE-result:', JSON.stringify(result));
if (result.code === 200) {
cartModel.getCartData(shoppingKey, uid).then(cartData => {
res.json(_.merge(
... ... @@ -105,10 +100,7 @@ exports.removeProduct = (req, res, next) => {
_.merge(params, {product_sku_list: productSkuList});
}
// console.log('remove---params:', params);
cartModel.removeGoods(params).then(result => {
// console.log('remove-result:', result);
res.json(_.merge(cartModel.filterCartData(result, uid), {code: result.code, message: result.message}));
}).catch(next);
};
... ... @@ -127,34 +119,12 @@ exports.sendToFavorite = (req, res, next) => {
_.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}));
}).catch(next);
};
// 编辑商品颜色和尺寸
exports.editProduct = (req, res) => {
res.json({
code: '0',
defaultColor: '蓝',
defaultSize: 'M',
defaultImg: 'http://img10.static.yhbimg.com/goodsimg/2015/10/21/02/0128dc014524ccf208b4f6f7760c9b9cf2.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
colors: [{
color: '蓝',
rgb: '#1b3c78',
pic: 'http://img10.static.yhbimg.com/goodsimg/2015/10/21/02/0128dc014524ccf208b4f6f7760c9b9cf2.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80'
}, {
color: '黑',
rgb: '#000',
pic: 'http://img12.static.yhbimg.com/goodsimg/2015/10/21/05/024f60a070ab61981c139684f147d41f17.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80'
}],
sizes: ['S', 'M', 'L', 'XL', 'XXL', 'XXXL']
});
};
// 添加商品到购物车
exports.addToCart = (req, res, next) => {
const productSku = req.body.productSku;
... ... @@ -195,21 +165,18 @@ exports.toggleSelectGoods = (req, res, next) => {
_.merge(params, {product_sku_list: productSkuList});
}
console.log('toggleSelectGoods---params:', params);
cartModel.toggleSelectGoods(params).then(result => {
res.json(_.merge(cartModel.filterCartData(result, uid), {code: result.code, message: result.message}));
}).catch(next);
};
// 去结算检查库存
// 点击去结算时检查库存
exports.checkStorage = (req, res, next) => {
const shoppingKey = req.cookies._SPK || null;
const uid = req.user.uid || null;
cartModel.getCartData(shoppingKey, uid).then((result) => {
// console.log('Cart current Data:', JSON.stringify(result, '', 4))
res.json(_.merge(cartModel.filterCartData(result, uid), {code: result.code, message: result.message}));
}).catch(next);
};
... ... @@ -222,10 +189,7 @@ exports.modifyProduct = (req, res, next) => {
// swapData => [{"buy_number":"1","selected":"Y","new_product_sku":"735172","old_product_sku":"735171"}]
const swapData = req.body.swapData;
// console.log("swap data....", {swapData, shoppingKey, uid})
cartModel.modifyProduct({swapData, shoppingKey, uid}).then((result) => {
// console.log('swap result...:', JSON.stringify(result, '', 4))
if (result.code === 200) {
cartModel.getCartData(shoppingKey, uid).then(cartData => {
res.json(_.merge(
... ... @@ -238,5 +202,3 @@ exports.modifyProduct = (req, res, next) => {
}
}).catch(next);
};
... ...
... ... @@ -83,8 +83,6 @@ const addToCart = (options) => {
* }
*/
const getCartData = (shoppingKey, uid) => {
// console.log('SPK:', shoppingKey);
// console.log('uid:', uid);
let params = {
method: 'app.Shopping.cart'
};
... ... @@ -168,7 +166,6 @@ const toggleSelectGoods = (params) => {
});
});
*/
return api.get('', params);
};
... ... @@ -248,8 +245,6 @@ const filterCartData = (result, uid) => {
// 预售商品
if (result.data && result.data.advance_cart_data) {
advancedCartData = result.data.advance_cart_data;
// console.log('---------------advance------:', advancedCartData.goods_list.length);
totalAdvanceMoney = advancedCartData.shopping_cart_data.last_order_amount;
advancedGoods = _.concat(advancedGoods, advancedCartData.goods_list);
invalidGoods = _.concat(invalidGoods, advancedCartData.off_shelves_goods_list);
... ... @@ -274,8 +269,6 @@ const filterCartData = (result, uid) => {
// 普通商品
if (result.data && result.data.ordinary_cart_data) {
ordinaryCartData = result.data.ordinary_cart_data;
// console.log('---------------ordinary------:', ordinaryCartData.goods_list.length);
totalOrdinaryMoney = ordinaryCartData.shopping_cart_data.last_order_amount;
ordinaryGoods = _.concat(ordinaryGoods, ordinaryCartData.goods_list);
invalidGoods = _.concat(invalidGoods, ordinaryCartData.off_shelves_goods_list);
... ... @@ -298,9 +291,6 @@ const filterCartData = (result, uid) => {
});
}
// console.log('ordinaryGoods:', ordinaryGoods);
return _.merge(resData, {
hasGoods: advancedGoods.length || ordinaryGoods.length || invalidGoods.length,
preSalePros: advancedGoods.length ? _.groupBy(advancedGoods, 'brand_id') : [],
... ... @@ -314,7 +304,7 @@ const filterCartData = (result, uid) => {
};
/**
* 增减购物车商品数量
* 修改购物车商品数量
* @function modifyProductNum
* @param { Number } uid 用户ID
* @param { String } sku 商品SKU
... ... @@ -372,9 +362,6 @@ const modifyProductNum = (options) => {
});
return getCartData(shoppingKey, uid).then(function(result) {
// console.log('getCartData--pre-callback-result:', JSON.stringify(result, '', 4));
// console.log('modifyProductNum---params:', params);
if (goodType === 'advance') {
// 检查库存量
// 同步
... ... @@ -456,6 +443,14 @@ const modifyProductNum = (options) => {
});
};
/**
* 修改商品颜色和尺寸
* @function modifyProduct
* @param { Number } uid 用户ID
* @param { String } swapData 商品修改信息
* @param { String } shoppingKey 未登录用户唯一识别码
* @return { Object } 接口返回单个商品修改结果
*/
const modifyProduct = (options) => {
let params = {
method: 'app.Shopping.swap'
... ...
... ... @@ -19,7 +19,6 @@ router.get('/cart', cartCtrl.index);
router.post('/cart/product/change_num', cartCtrl.changeProductNum);
router.delete('/cart/product/remove', cartCtrl.removeProduct);
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);
router.get('/cart/checkStorage', cartCtrl.checkStorage);
... ...
... ... @@ -9,7 +9,6 @@
{{> cart/empty-cart}}
{{/if}}
</div>
{{!-- <button id="add_to_cart1">添加到购物车 1413600 number 1</button> --}}
</div>
<script id="edit-color-size-tpl" type="text/html">
... ...
<div class="cart-removed-list">
<div class="info-bar">
<p class="info-text">已删除商品,您可以重新购买或移入收藏:</p>
</div>
<div class="removed-products">
<ul>
<li class="removed-product">
<div class="product-name">TEEBACOO虎头字母短袖T恤</div>
<div class="product-price">¥ 373.00</div>
<div class="bought-num">2</div>
<div class="actions">
<span class="buy-again">重新购买</span>
<span class="send-to-favorite">移入收藏夹</span>
</div>
</li>
<li class="removed-product">
<div class="product-name">NIKIE AIR FORCE1</div>
<div class="product-price">¥ 373.00</div>
<div class="bought-num">2</div>
<div class="actions">
<span class="buy-again">重新购买</span>
<span class="send-to-favorite">移入收藏夹</span>
</div>
</li>
</ul>
</div>
</div>
\ No newline at end of file
... ...
/**
* [购物流程] 购物袋
* @author: jinhu.dong<jinhu.dong@yoho.cn>
* @date: 2016/7/1
*/
var $ = require('yoho-jquery');
var Cart = require('./cart/cart');
var Stepper = require('./cart/stepper');
$(function() {
var $this;
var editable = true;
// 关闭info-bar
$('.info-bar .close').on('click', function() {
... ... @@ -54,16 +61,25 @@ $(function() {
}).delegate('.editable', 'click', function() {
$this = $(this);
// 编辑商品颜色和属性
Cart.editColorOrSize(
$this.attr('data-productId'),
$this.attr('data-productSkn'),
$this.find('.default-color').text(),
$this.find('.default-size').text());
if (editable) {
editable = false;
$('body').on('click', function() {
$('.edit-color-size').remove();
});
// 编辑商品颜色和属性
Cart.editColorOrSize(
$this.attr('data-productId'),
$this.attr('data-productSkn'),
$this.find('.default-color').text(),
$this.find('.default-size').text(), function() {
editable = true;
});
$('body').off('click').on('click', function() {
if ($('.edit-color-size').length) {
$('.edit-color-size').remove();
editable = true;
}
});
}
}).delegate('#checkout_btn', 'click', function(e) {
e.preventDefault();
if ($('.chk-group').length) {
... ...
... ... @@ -67,6 +67,7 @@ var Cart = {
/*
* 取消全选
* @function [toggleCheckAllPros]
* @params { Boolean } checked 选择,取消选择
*/
toggleCheckAllPros: function(checked) {
var data = [],
... ... @@ -93,6 +94,7 @@ var Cart = {
/*
* 根据服务端JSON,刷新购物车信息
* @function [refreshCart]
* @params { Object } data 最新购物车数据
*/
refreshCart: function(data) {
var template;
... ... @@ -103,8 +105,6 @@ var Cart = {
if (num1 && num2) {
return num1 * num2;
} else {
console.error('multiplication needs two number parameters');
}
});
... ... @@ -130,6 +130,7 @@ var Cart = {
/*
* 选择与取消选择
* @function [toggleSelectGoods]
* @params { Array } data 选择与取消选择商品信息
*/
toggleSelectGoods: function(data) {
$.ajax({
... ... @@ -152,7 +153,8 @@ var Cart = {
/*
* 单选每一个商品判断是否需要全选
* @function [toggleCheckAll]
* @function [toggleCheck]
* @params { Object } target 单个商品
*/
toggleCheck: function(target) {
var $this = $(target),
... ... @@ -220,8 +222,8 @@ var Cart = {
},
/*
* 删除商品
* @function [removePro]
* 商品移入收藏夹
* @function [sendToFavorite]
* @params { Array } products 商品列表
*/
sendToFavorite: function(products) {
... ... @@ -254,8 +256,16 @@ var Cart = {
}
},
// 编辑商品的颜色和尺寸
editColorOrSize: function(productId, skn, defaultColor, defaultSize) {
/*
* 修改商品颜色和尺寸
* @function [editColorOrSize]
* @params { String } productId 商品ID
* @params { String } skn 商品skn
* @params { String } defaultColor 商品默认颜色
* @params { String } defaultSize 商品默认尺寸
* @params { Function } setEditable 编辑商品回调
*/
editColorOrSize: function(productId, skn, defaultColor, defaultSize, setEditable) {
var template;
var index = 0;
var colors;
... ... @@ -321,10 +331,8 @@ var Cart = {
});
// helpers end
template = hbs.compile($('#edit-color-size-tpl').html());
editTarget.append(
template({
colors: filterSet,
... ... @@ -352,12 +360,14 @@ var Cart = {
success: function(newCartData) {
editTarget.find('.edit-color-size').remove();
Util.refreshCart(newCartData);
setEditable();
}
});
return false;
}).delegate('#cancel', 'click', function(e) {
e.preventDefault();
editTarget.find('.edit-color-size').remove();
setEditable();
return false;
}).delegate('.edit-color-size', 'click', function(e) {
e.preventDefault();
... ... @@ -390,6 +400,11 @@ var Cart = {
},
/*
* 点击结算时检查商品库存
* @function [checkStorage]
* @params { Function } callback 检查完回调函数
*/
checkStorage: function(callback) {
Util.ajax({
url: '/shopping/cart/checkStorage',
... ...
... ... @@ -9,7 +9,13 @@ var Util = require('./util');
var $ = require('yoho-jquery');
var Stepper = {
// 减少商品数量
/*
* 减少商品数量
* @function [decrease]
* @params { String } goodType 商品类型
* @params { String } sku 商品sku
* @params { String } currNum 商品当前购买数量
*/
decrease: function(goodType, sku, currNum) {
if (parseInt(currNum, 10) <= 1) {
// return callback(1);
... ... @@ -32,7 +38,12 @@ var Stepper = {
},
// 增加商品数量
/*
* 增加商品数量
* @function [increase]
* @params { String } goodType 商品类型
* @params { String } sku 商品sku
*/
increase: function(goodType, sku) {
Util.ajax({
url: '/shopping/cart/product/change_num',
... ... @@ -50,6 +61,10 @@ var Stepper = {
});
},
/*
* 初始化
* @function [init]
*/
init: function() {
var _this = this,
$target,
... ... @@ -123,4 +138,3 @@ var Stepper = {
};
module.exports = Stepper;
... ...
... ... @@ -9,6 +9,12 @@ var _alert = dialog.Alert;
var hbs = require('yoho-handlebars');
var Util = {
/*
* ajax请求封装
* @function [ajax]
* @params { Object } options ajax请求参数
*/
ajax: function(options) {
$.ajax({
type: options.type || 'GET',
... ... @@ -33,6 +39,8 @@ var Util = {
/*
* 根据服务端JSON,刷新购物车信息
* @function [refreshCart]
* @params { Object } data 最新购物车数据
* @params { Function } callback 购物车刷新后回调
*/
refreshCart: function(data, callback) {
var template;
... ... @@ -49,8 +57,6 @@ var Util = {
if (num1 && num2) {
return num1 * num2;
} else {
console.error('multiplication needs two number parameters');
}
});
... ...
... ... @@ -7,6 +7,7 @@
@import "tooltip"; /* 提示 */
@import "edit-color-size"; /* 编辑颜色和属性 */
@import "statement"; /* 结算模块 */
@import "removed-products"; /* 删除商品模块 */
/* 支付流程-订单结算 */
@import "order";
... ...
.blk-cart-page {
.cart-removed-list {
.info-bar {
background: #fff;
margin-bottom: 12px;
}
}
.removed-product {
padding: 9px 30px;
background: #f0f0f0;
margin-bottom: 20px;
position: relative;
font-size: 14px;
div {
display: inline-block;
}
.actions {
position: absolute;
right: 30px;
}
.buy-again {
margin-right: 20px;
}
span {
&:hover {
cursor: pointer;
color: #379ed6;
}
}
}
.product-name {
width: 549px;
}
.product-price {
width: 150px;
}
.bought-num {
width: 100px;
text-align: center;
}
}
... ...