Authored by 姜枫

handle merge

... ... @@ -50,15 +50,15 @@ const index = (req, res, next) => {
}).catch(next);
};
const getAddressList = (req, res) => {
addressModel.getAddressDataAsync('7566245', 20).then(result => {
const getAddressList = (req, res, next) => {
addressModel.getAddressDataAsync(req.user.uid, 20).then(result => {
if (result.data) {
let defaultAd = _.find(result.data, o => o.is_default === 'Y');
defaultAd && (defaultAd.focus = true);
}
res.send(result);
});
}).catch(next);
};
/**
... ...
... ... @@ -118,7 +118,7 @@ const local = {
countryName: areaName,
countryList: areaArr,
forgetPwd: helpers.urlFormat('/passport/back/index'),
fastReg: helpers.urlFormat('/passport/reg/index'),
fastReg: helpers.urlFormat('/passport/reg'),
weixinLogin: helpers.urlFormat('/passport/autosign/wechat'),
qqLogin: helpers.urlFormat('/passport/autosign/qq'),
weiboLogin: helpers.urlFormat('/passport/autosign/sina'),
... ...
... ... @@ -63,7 +63,7 @@ router.post('/autouserinfo/relateMobile', bind.relateMobile);
/**
* 注册页面路由
*/
router.get('/reg/index', reg.index);
router.get('/reg', reg.index);
router.post('/reg/checkmobile', reg.checkMobileMiddleware, reg.checkMobile);
router.post('/reg/piccaptcha', reg.checkCode, reg.picCaptcha);
router.post('/reg/msgcaptcha', reg.checkMobileMiddleware, reg.msgCaptcha);
... ...
... ... @@ -241,10 +241,11 @@ const index = (req, res, next) => {
// }
// };
Item.getProductItemData(req.params, req.user.uid).then(result => {
Item.getProductItemData(req.params, req.url, req.user.uid).then(result => {
if (_.isEmpty(result)) {
return next();
}
result.page = 'item';
res.display('item', result);
}).catch(next);
};
... ...
... ... @@ -360,6 +360,14 @@ const setProductData = base => {
}
}
// 分享相关,产品的链接
resData.share = {
weixinUrl: helpers.urlFormat(base.mainPath),
shareTitle: resData.name,
shareImg: resData.img,
shareDesc: base.phrase
};
return resData;
};
... ...
... ... @@ -40,7 +40,7 @@ const _getMultiResourceByBaseInfo = (base) => {
});
};
let getProductItemData = (params, uid) => {
let getProductItemData = (params, url, uid) => {
let pid = params[0];
// let gid = params[1];
... ... @@ -55,6 +55,7 @@ let getProductItemData = (params, uid) => {
}
result.uid = uid;
result.mainPath = url;
// 商品基本信息
data.goodInfo = itemFUN.setProductData(result);
... ...
... ... @@ -14,6 +14,7 @@ exports.index = (req, res) => {
const uid = req.user.uid || null;
cartModel.getCartData(shoppingKey, uid).then((result) => {
// console.log(JSON.stringify(result, '', 4))
if (result.code === 200) {
res.display('cart', _.merge({
module: 'shopping',
... ... @@ -31,64 +32,62 @@ exports.index = (req, res) => {
});
};
// 检查库存
exports.checkInventory = (req, res) => {
let chkResult,
invalidProIds = [],
productId = req.query.productId,
result = {};
if (productId === 'ALL') {
chkResult = false;
invalidProIds.push('286143');
} else {
if (req.query.productId === '286143') {
chkResult = false;
} else {
chkResult = true;
}
}
if (invalidProIds.length) {
_.merge(result, {
invalidProIds: invalidProIds
});
}
_.merge(result, {
valid: chkResult
});
res.json(result);
};
// 修改数量
exports.changeProductNum = (req, res) => {
const changeType = req.body.changeType;
const changeTo = req.body.changeTo;
// const changeTo = req.body.changeTo;
const uid = req.user.uid;
const shoppingKey = req.cookies._SPK;
const sku = req.body.sku;
const goodTpye = req.body.goodType;
if (changeType === 'INCREASE') {
// TODO
if (changeTo === '4') {
res.json({
code: '1000',
num: parseInt(changeTo, 10) - 1,
changed: false
});
} else {
res.json({
code: '0',
num: changeTo,
changed: true
});
}
cartModel.modifyProductNum({
increaseNum: 1, // 默认是1
uid,
shoppingKey,
sku,
goodTpye
}).then(result => {
console.log('changeProductNum-INCREASE-result:', result);
if (result.code === 200) {
cartModel.getCartData(shoppingKey, uid).then(cartData => {
res.json(_.merge(
cartModel.filterCartData(cartData, uid),
{code: cartData.code, message: result.message})
);
});
} else {
res.json(result);
}
});
// res.json({
// code: '1000',
// num: parseInt(changeTo, 10) - 1,
// changed: false
// });
} else if (changeType === 'DECREASE') {
// TODO
res.json({
code: '0',
num: changeTo,
changed: true
cartModel.modifyProductNum({
decreaseNum: 1, // 默认是1
uid,
shoppingKey,
sku,
goodTpye
}).then(result => {
console.log('changeProductNum-DECREASE-result:', result);
if (result.code === 200) {
cartModel.getCartData(shoppingKey, uid).then(cartData => {
res.json(_.merge(
cartModel.filterCartData(cartData, uid),
{code: cartData.code, message: result.message})
);
});
} else {
res.json(result);
}
});
}
};
... ... @@ -122,9 +121,23 @@ exports.removeProduct = (req, res) => {
// 收藏商品
exports.sendToFavorite = (req, res) => {
// TODO
res.json({
code: '0'
const params = {};
const uid = 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}));
});
};
... ... @@ -159,6 +172,7 @@ exports.addToCart = (req, res) => {
shoppingKey: req.cookies._SPK || null,
uid: req.user.uid
}).then((result) => {
res.cookie('_SPK', result.data.shopping_key);
res.json(result);
});
};
... ... @@ -194,39 +208,5 @@ exports.toggleSelectGoods = (req, res) => {
});
};
// 购物车商品选择与取消选择
exports.modifyProductNum = (req, res) => {
const uid = req.user.uid;
const shoppingKey = req.cookies._SPK;
const changeType = req.body.changeType;
const changeNum = req.body.changeNum;
const sku = req.body.sku;
let params = {
uid,
shoppingKey,
sku
};
if (changeType === 'INCREASE') {
_.merge(params, {
increaseNum: changeNum
});
} else if (changeType === 'DECREASE') {
_.merge(params, {
decreaseNum: changeNum
});
} else {
// TODO
// CHANGE
}
cartModel.modifyProductNum(params).then(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);
};
... ... @@ -271,7 +265,7 @@ const filterCartData = (result, uid) => {
* @param { Number } increaseNum 增加的数目
* @param { Number } decreaseNum 减少的数目
* @param { String } shoppingKey 未登录用户唯一识别码
* @return { Array } 接口返回数据
* @return { Array } 接口返回单个商品的增减数据
*/
const modifyProductNum = (options) => {
const increaseNum = options.increaseNum;
... ... @@ -279,6 +273,7 @@ const modifyProductNum = (options) => {
const uid = options.uid;
const shoppingKey = options.shoppingKey;
const sku = options.sku;
const goodType = options.goodType;
let params = {
product_sku: options.sku
... ... @@ -310,13 +305,22 @@ const modifyProductNum = (options) => {
});
}
if (sku) {
_.merge(params, {
product_sku: sku
});
}
_.merge(params, {
product_sku: sku
});
return getCartData(shoppingKey, uid).then(function(result) {
console.log('getCartData--pre-callback-result:', result);
console.log('modifyProductNum---params:', params);
if (goodType === 'advance') {
// 检查库存量
} else if (goodType === 'ordinary') {
// 检查库存量
}
return api.get('', params);
});
return api.get('', params);
};
module.exports = {
... ...
... ... @@ -42,7 +42,7 @@ const index = uid => {
// format goods link
theGoods.link = helper.urlFormat(
`/product/pro_${theGoods.product_id}_${theGoods.goods_id}_${theGoods.cn_alphabet}.html`);
`/product/pro_${theGoods.product_id}_${theGoods.goods_id}/${theGoods.cn_alphabet}.html`);
theGoods.last_price = parseFloat(theGoods.last_price, 10).toFixed(2);
... ...
... ... @@ -15,10 +15,9 @@ const order = require(`${cRoot}/order`); // 下单
// 购物车
router.get('/cart', cartCtrl.index);
router.get('/cart/product/check_inventory', cartCtrl.checkInventory);
router.post('/cart/product/:productId/change_num', cartCtrl.changeProductNum);
router.post('/cart/product/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);
... ...
... ... @@ -7,8 +7,7 @@
{{^}}
{{> cart/empty-cart}}
{{/if}}
{{!-- <button id="add_to_cart1">添加到购物车 980874 number 1</button>
<button id="add_to_cart2">添加到购物车 980870 number 2</button> --}}
{{!-- <button id="add_to_cart1">添加到购物车 1413600 number 1</button> --}}
</div>
</div>
<script id="edit-color-size-tpl" type="text/html">
... ...
... ... @@ -40,11 +40,13 @@
<input type="hidden" name="product_ids[]"/>
</li>
<li>
<img src="\{{image goods_images 100 134}}" alt="\{{product_name}}">
<a href="/product/pro_\{{goods_id}}_\{{product_id}}/\{{cn_alphabet}}.html">
<img src="\{{image goods_images 100 134}}" alt="\{{product_name}}">
</a>
</li>
<li class="pro-info">
\{{!-- <div class="brand-name">\{{brand_name}}</div> --}}
<div class="pro-name">\{{product_name}}</div>
<div class="pro-name"><a href="/product/pro_\{{goods_id}}_\{{product_id}}/\{{cn_alphabet}}.html">\{{product_name}}</a></div>
<div class="size">
\{{#if size_name}}
<span>尺寸: \{{size_name}}</span>
... ... @@ -101,11 +103,13 @@
<input type="hidden" name="product_ids[]"/>
</li>
<li>
<img src="\{{image goods_images 100 134}}" alt="\{{product_name}}">
<a href="/product/pro_\{{goods_id}}_\{{product_id}}/\{{cn_alphabet}}.html">
<img src="\{{image goods_images 100 134}}" alt="\{{product_name}}">
</a>
</li>
<li class="pro-info">
\{{!-- <div class="brand-name">\{{brandName}}</div> --}}
<div class="pro-name">\{{product_name}}</div>
<div class="pro-name"><a href="/product/pro_\{{goods_id}}_\{{product_id}}/\{{cn_alphabet}}.html">\{{product_name}}</a></div>
<div class="color-size editable" data-product_id=\{{product_id}} id="edit_\{{product_id}}">
\{{#if color_name}}
<span class="mr20">颜色: \{{color_name}}</span>
... ... @@ -154,13 +158,20 @@
<span class="iconfont warning">&#xe625;</span>
</li>
<li>
<img src="\{{image defaultImages 100 134}}" alt="\{{productName}}">
<a href="/product/pro_\{{goods_id}}_\{{product_id}}/\{{cn_alphabet}}.html">
<img src="\{{image goods_images 100 134}}" alt="\{{product_name}}">
</a>
</li>
<li class="pro-info">
<div class="brand-name">\{{brandName}}</div>
<div class="pro-name">\{{productName}}</div>
<div class="size">尺寸: USB</div>
<div class="published-at">上市期: 2016年8月</div>
<div class="pro-name"><a href="/product/pro_\{{goods_id}}_\{{product_id}}/\{{cn_alphabet}}.html">\{{product_name}}</a></div>
<div>
\{{#if color_name}}
<span class="mr20">颜色: \{{color_name}}</span>
\{{/if}}
\{{#if size_name}}
<span>尺寸: \{{size_name}}</span>
\{{/if}}
</div>
</li>
<li class="price-num">
<span class="price sale-price">¥\{{salesPrice}}</span>
... ...
... ... @@ -17,11 +17,13 @@
<input type="hidden" name="product_ids[]"/>
</li>
<li>
<img src="{{image goods_images 100 134}}" alt="{{product_name}}">
<a href="/product/pro_{{goods_id}}_{{product_id}}/{{cn_alphabet}}.html">
<img src="{{image goods_images 100 134}}" alt="{{product_name}}">
</a>
</li>
<li class="pro-info">
{{!-- <div class="brand-name">{{brand_name}}</div> --}}
<div class="pro-name">{{product_name}}</div>
<div class="pro-name"><a href="/product/pro_{{goods_id}}_{{product_id}}/{{cn_alphabet}}.html">{{product_name}}</a></div>
<div class="size">
{{#if size_name}}
<span>尺寸: {{size_name}}</span>
... ... @@ -68,11 +70,13 @@
<input type="hidden" name="product_ids[]"/>
</li>
<li>
<img src="{{image goods_images 100 134}}" alt="{{product_name}}">
<a href="/product/pro_{{goods_id}}_{{product_id}}/{{cn_alphabet}}.html">
<img src="{{image goods_images 100 134}}" alt="{{product_name}}">
</a>
</li>
<li class="pro-info">
{{!-- <div class="brand-name">{{brandName}}</div> --}}
<div class="pro-name">{{product_name}}</div>
<div class="pro-name"><a href="/product/pro_{{goods_id}}_{{product_id}}/{{cn_alphabet}}.html">{{product_name}}</a></div>
<div class="color-size editable" data-product_id={{product_id}} id="edit_{{product_id}}">
{{#if color_name}}
<span class="mr20">颜色: {{color_name}}</span>
... ... @@ -111,13 +115,20 @@
<span class="iconfont warning">&#xe625;</span>
</li>
<li>
<img src="{{image defaultImages 100 134}}" alt="{{productName}}">
<a href="/product/pro_{{goods_id}}_{{product_id}}/{{cn_alphabet}}.html">
<img src="{{image goods_images 100 134}}" alt="{{product_name}}">
</a>
</li>
<li class="pro-info">
<div class="brand-name">{{brandName}}</div>
<div class="pro-name">{{productName}}</div>
<div class="size">尺寸: USB</div>
<div class="published-at">上市期: 2016年8月</div>
<div class="pro-name"><a href="/product/pro_{{goods_id}}_{{product_id}}/{{cn_alphabet}}.html">{{product_name}}</a></div>
<div>
{{#if color_name}}
<span class="mr20">颜色: {{color_name}}</span>
{{/if}}
{{#if size_name}}
<span>尺寸: {{size_name}}</span>
{{/if}}
</div>
</li>
<li class="price-num">
<span class="price sale-price">¥{{salesPrice}}</span>
... ...
<div class="stepper" data-productId={{productId}}>
<div class="stepper" data-productType={{goods_type}}>
<div class="minus action">
<span class="iconfont">&#xe621;</span>
</div>
... ...
... ... @@ -28,6 +28,10 @@ module.exports = () => {
}
if (!isHead) {
// 登录状态
if (req.user.uid) {
data.userName = req.user.username;
}
res.render(path, data);
} else {
header.requestHeaderData('boys').then(result => {
... ...
... ... @@ -40,10 +40,12 @@
</div>
</li>
<li class="tag-bag">
<span class="tools-icon icon-bag">
<b class="bag-num">1</b>
</span>
购物袋
<a href="{{../siteUrl}}/shopping/cart">
<span class="tools-icon icon-bag">
<b class="bag-num"></b>
</span>
购物袋
</a>
<div class="mini-bag-box sub-wrapper">
<div class="bag-content">
购物袋空空的哦,去看看心仪的商品吧~
... ...
... ... @@ -54,7 +54,7 @@
<span class="iconfont">&#xe605;</span>
<div class="search-wrapper">
<div class="search-input">
<form id="search-form" action="/product/list/query">
<form id="search-form" action="{{../siteUrl}}/product/query">
<span class="iconfont left">&#xe605;</span>
<input type="text" name="query" id="search-key" class="search-key" placeholder="search"autocomplete="off">
<span class="iconfont right clear-input">&#xe608;</span>
... ...
... ... @@ -2,14 +2,16 @@
<div class="center-content">
<div class="main-logo"></div>
<ul class="header-tools right clearfix">
{{#if userName}}
Hi~
<a href="{{siteUrl}}/me">{{userName}}</a>
<a href="{{siteUrl}}/passport/logout">[退出]</a>
{{^}}
<a href="{{siteUrl}}/passport/login">登录</a> |
<a href="{{siteUrl}}/passport/reg">注册</a>
{{/if}}
<li>
{{#if userName}}
Hi~
<a href="{{siteUrl}}/me">{{userName}}</a>
<a href="{{siteUrl}}/passport/logout">[退出]</a>
{{^}}
<a href="{{siteUrl}}/passport/login">登录</a> |
<a href="{{siteUrl}}/passport/reg">注册</a>
{{/if}}
</li>
<li><a href="{{siteUrl}}">首页</a></li>
<li><a href="{{siteUrl}}/help">帮助中心</a></li>
<li>客服电话<span>400-9889-9646</span></li>
... ...
... ... @@ -30,6 +30,7 @@ var thumbsLoaded = [],
id = $main.data('id');
require('../common/header');
require('../plugins/share');
lazyload($('img.lazy'));
... ... @@ -103,8 +104,6 @@ $thumbWrap.each(function() {
}
});
// $thumbWrap.parent().animate({visibility: 'visible'});
$thumbWrap.parent().removeClass('hide');
// 展示图
... ... @@ -161,7 +160,7 @@ $('.size-list').on('click', 'li', function() {
$this.addClass('cur');
}
});
// 加入购物袋
$addToBag.click(function() {
var sku = getBuyProduct();
... ... @@ -181,7 +180,12 @@ $addToBag.click(function() {
});
}
});
// 继续购物
$('#keep-shopping').click(function() {
$balanceWrapper.slideUp(SLIDETIME);
$tradeWrapper.slideDown(SLIDETIME);
});
// 商品收藏
$('#collect-product').click(function() {
var $this = $(this),
param = {
... ... @@ -204,5 +208,4 @@ $('#collect-product').click(function() {
location.href = data.data.refer;
}
});
});
... ...
... ... @@ -14,17 +14,49 @@ $(function() {
Cart.toggleCheck.call(Cart, this);
}).delegate('.remove-item', 'click', function() {
// 删除商品
Cart.removePro($(this).parents('ul').children().first().attr('data-product_info'));
// 重构
Cart.removePro([$.parseJSON($(this).parents('ul').children().first().attr('data-product_info'))]);
}).delegate('#remove_selected', '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.removePro(selectedProducts);
}).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';
}
});
... ... @@ -54,7 +86,7 @@ $(function() {
// TODO=>
// $('#add_to_cart1').on('click', function() {
// Cart.addToCart({
// productSku: '870896',
// productSku: '1413600',
// buyNumber: 1
// });
// });
... ...
... ... @@ -11,7 +11,6 @@ var _confirm = Dialog.Confirm;
var _alert = Dialog.Alert;
var Util = require('./util');
var hbs = require('yoho-handlebars');
var common = require('../../common');
var Stepper = require('./stepper');
var Cart = {
... ... @@ -23,22 +22,16 @@ var Cart = {
* @params { Function } callback 购买结果回调
*/
addToCart: function(params, callback) {
// TODO
// common.setCookie('uid', '20000058');
Util.ajax({
url: '/shopping/cart/add',
type: 'POST',
data: params,
success: function(res) {
if (res.code === 200) {
common.setCookie('_SPK', res.data.shopping_key);
if (callback) {
return callback(res);
}
}
},
fail: function() {
// TODO
}
});
},
... ... @@ -206,38 +199,39 @@ var Cart = {
dialog.close();
Util.ajax({
url: '/shopping/cart/product/remove',
data: {skuList: JSON.stringify([$.parseJSON(products)])},
data: {skuList: JSON.stringify(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);
}
});
}
... ...
... ... @@ -6,24 +6,28 @@
*/
var Util = require('./util');
var $ = require('yoho-jquery');
var Stepper = {
// 减少商品数量
decrease: function(productId, currNum, callback) {
decrease: function(goodType, sku, currNum) {
if (parseInt(currNum, 10) <= 1) {
return callback(1);
// return callback(1);
} else {
Util.ajax({
url: '/shopping/cart/product/' + productId + '/change_num',
url: '/shopping/cart/product/change_num',
type: 'POST',
data: {
changeType: 'DECREASE',
changeTo: parseInt(currNum, 10) - 1
sku: sku,
goodType: goodType
// changeTo: parseInt(currNum, 10) - 1
},
success: function(res) {
if (res.code === '0') {
return callback(res.num, res.changed);
}
Util.refreshCart(res, function() {
Stepper.init();
});
}
});
}
... ... @@ -31,21 +35,26 @@ var Stepper = {
},
// 增加商品数量
increase: function(productId, currNum, callback) {
increase: function(goodType, sku) {
Util.ajax({
url: '/shopping/cart/product/' + productId + '/change_num',
url: '/shopping/cart/product/change_num',
type: 'POST',
data: {
changeType: 'INCREASE',
changeTo: parseInt(currNum, 10) + 1
sku: sku,
goodType: goodType
// changeTo: parseInt(currNum, 10) + 1
},
success: function(res) {
if (res.code === '0') {
return callback(res.num, res.changed);
} else {
return callback(res.num, res.changed, res.code === '1000');
}
// if (res.code === '0') {
// return callback(res.num, res.changed);
// } else {
// return callback(res.num, res.changed, res.code === '1000');
// }
Util.refreshCart(res, function() {
Stepper.init();
});
}
});
},
... ... @@ -53,7 +62,8 @@ var Stepper = {
init: function() {
var _this = this,
$target,
productId;
sku,
goodType;
var steppers = $('.stepper'),
$input,
... ... @@ -77,8 +87,9 @@ var Stepper = {
plus = $input.parent().next();
if (!$target.hasClass('disable')) {
productId = $target.parent().attr('data-productId');
_this.decrease(productId, currNum, function(num, changed) {
sku = $.parseJSON($target.parents('ul').children().first().attr('data-product_info')).product_sku;
goodType = $target.parent().attr('data-producttype');
_this.decrease(goodType, sku, currNum, function(num, changed) {
if (num === 1) {
$input.val(1);
$target.addClass('disable');
... ... @@ -103,8 +114,9 @@ var Stepper = {
minus = $input.parent().prev();
if (!$target.hasClass('disable')) {
productId = $target.parent().attr('data-productId');
_this.increase(productId, currNum, function(num, changed, overflow) {
sku = $.parseJSON($target.parents('ul').children().first().attr('data-product_info')).product_sku;
goodType = $target.parent().attr('data-producttype');
_this.increase(goodType, sku, currNum, function(num, changed, overflow) {
if (overflow) {
$target.addClass('disable');
}
... ...
... ... @@ -6,6 +6,7 @@
*/
var dialog = require('../../plugins/dialog');
var _alert = dialog.Alert;
var hbs = require('yoho-handlebars');
var Util = {
ajax: function(options) {
... ... @@ -15,8 +16,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) {
... ... @@ -25,6 +28,45 @@ var Util = {
new _alert('网络异常,稍后请重试').show();
}
});
},
/*
* 根据服务端JSON,刷新购物车信息
* @function [refreshCart]
*/
refreshCart: function(data, callback) {
var template;
hbs.registerHelper('multiple', function(num1, num2) {
num1 = typeof num1 === 'number' ? num1 : parseFloat(num1, 10);
num2 = typeof num2 === 'number' ? num2 : parseFloat(num2, 10);
if (num1 && num2) {
return num1 * num2;
} else {
console.error('multiplication needs two number parameters');
}
});
hbs.registerHelper('isEqual', function(v1, v2, options) {
if (v1 === v2) {
return options.fn(this);
}
return options.inverse(this);
});
hbs.registerHelper('image', function(url, width, height, mode) {
mode = parseInt(mode, 10) ? mode : 2;
url = url || '';
return url.replace(/{width}/g, width).replace(/{height}/g, height).replace(/{mode}/g, mode);
});
template = hbs.compile($('#cart-content-tpl').html());
$('#cart_content').html(template(data));
if (callback) {
return callback();
}
}
};
... ...
... ... @@ -258,7 +258,7 @@ function newAddress(isInit) {
var address;
address = addressDialogFactory({
init: isInit
init: isInit ? true : false
});
if (isInit) {
... ... @@ -276,7 +276,12 @@ $('.address-all').click(function() {
});
// 新增地址
$('.new-address').click(newAddress);
$('.new-address').click(function() {
// not $('.address-all).click(newAddress);
// because newAddress get a param, this type written will cause disaccord param of newAddress
newAddress();
});
$('.address-list').on('click', '.address', function() {
... ...
... ... @@ -73,6 +73,11 @@ $hoverColor: #379ed6;
width: 234px;
word-wrap: break-word;
margin-bottom: 13px;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
line-height: 1.3em;
overflow: hidden;
}
.size {
... ... @@ -137,17 +142,22 @@ $hoverColor: #379ed6;
width: 168px;
position: relative;
.iconfont {
display: none;
}
&:hover {
cursor: pointer;
border: 1px dashed #3a9ed6;
}
.iconfont {
position: absolute;
right: 5px;
top: 3px;
font-size: 16px;
font-weight: normal !important;
.iconfont {
position: absolute;
right: 5px;
top: 3px;
font-size: 16px;
font-weight: normal !important;
display: inline-block !important;
}
}
.sizes-list {
width: 195px;
... ...
... ... @@ -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;
... ...