Authored by jinhu.tung

add removed products and send to favorite

... ... @@ -9,6 +9,7 @@
{{> cart/empty-cart}}
{{/if}}
</div>
<div id="removed_products"></div>
</div>
<script id="edit-color-size-tpl" type="text/html">
... ... @@ -322,3 +323,28 @@
</a>
</div>
</script>
<script id="removed-products" type="text/html">
<div class="cart-removed-list">
<div class="info-bar">
<p class="info-text">已删除商品,您可以重新购买或移入收藏:</p>
</div>
<div class="removed-products">
<ul>
\{{#each removedProducts}}
<li class="removed-product">
<div class="product-name">
<a href="/product/pro_\{{productId}}_\{{goodsId}}/\{{cnAlphabet}}.html" target="_blank">\{{productName}}</a>
</div>
<div class="product-price">¥ \{{salesPrice}}</div>
<div class="bought-num">\{{buyNumber}}</div>
<div class="actions">
<span class="buy-again">重新购买</span>
<span class="send-to-favorite" data-product_info='{"goods_type": "\{{goodType}}", "buy_number": \{{buyNumber}}, "selected": "\{{selected}}", "product_sku": "\{{productSku}}", "promotion_id": 0}'>移入收藏夹</span>
</div>
</li>
\{{/each}}
</ul>
</div>
</div>
</script>
... ...
... ... @@ -44,7 +44,7 @@
<li class="total-price-action">
<span class="price item-total-price">¥ {{round (multiple sales_price buy_number) 2}}</span>
<div class="actions">
<div class="remove-item action" data-product_id={{product_id}}><span class="iconfont">&#xe614;</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
<div class="remove-item action" data-product_extra_info='{"goodsId": "{{goods_id}}", "cnAlphabet": "{{cn_alphabet}}", "productId": "{{product_id}}", "salesPrice": "{{round sales_price 2}}", "productName": "{{product_name}}", "goodType":"advance", "selected": "{{selected}}"}'><span class="iconfont">&#xe614;</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
<div class="send-to-favorite action" data-product_id={{product_id}}>移入收藏夹</div>
</div>
</li>
... ... @@ -98,7 +98,7 @@
<li class="total-price-action">
<span class="price item-total-price">¥ {{round (multiple sales_price buy_number) 2}}</span>
<div class="actions">
<div class="remove-item action" data-product_id={{product_id}}><span class="iconfont">&#xe614;</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
<div class="remove-item action" data-product_extra_info='{"goodsId": "{{goods_id}}", "cnAlphabet": "{{cn_alphabet}}", "productId": "{{product_id}}", "salesPrice": "{{round sales_price 2}}", "productName": "{{product_name}}", "goodType":"ordinary", "selected": "{{selected}}"}'><span class="iconfont">&#xe614;</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
<div class="send-to-favorite action" data-product_id={{product_id}}>移入收藏夹</div>
</div>
</li>
... ...
<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
... ... @@ -22,8 +22,14 @@ $(function() {
Cart.toggleCheck.call(Cart, this);
}).delegate('.remove-item', 'click', function() {
// 删除商品
// 重构
Cart.removePro([$.parseJSON($(this).parents('ul').children().first().attr('data-product_info'))]);
// 失效商品删除,不用显示在删除模块
var productExtraInfo = $(this).attr('data-product_extra_info'),
productExtraInfoArr = productExtraInfo ? [$.parseJSON(productExtraInfo)] : [];
Cart.removePro(
[$.parseJSON($(this).parents('ul').children().first().attr('data-product_info'))],
productExtraInfoArr
);
}).delegate('#remove_selected', 'click', function(e) {
// 删除多个商品
// 重构
... ... @@ -92,6 +98,16 @@ $(function() {
return false;
});
$('#removed_products').delegate('.send-to-favorite', 'click', function() {
Cart.sendToFavorite([$.parseJSON($(this).attr('data-product_info'))], function() {
if ($('#removed_products .removed-product').length > 1) {
$(this).remove();
} else {
$('#removed_products').html('');
}
});
});
// 变动商品数量
Stepper.init();
});
... ...
... ... @@ -13,6 +13,10 @@ var Util = require('./util');
var hbs = require('yoho-handlebars');
var Stepper = require('./stepper');
// 删除商品信息
var removedProSkus = [];
var removedProsInfo = [];
var Cart = {
/*
* 添加到购物车
... ... @@ -195,11 +199,13 @@ var Cart = {
* 删除商品
* @function [removePro]
* @params { Array } products 商品列表
* @params { Array } extraInfos 删除商品额外信息
*/
removePro: function(products) {
removePro: function(products, extraInfos) {
var dialog;
if (products.length) {
// Cart.showRemovedProducts(products, extraInfos);
dialog = new _confirm({
content: '您确定要从购物车中删除该商品吗?',
cb: function() {
... ... @@ -211,6 +217,9 @@ var Cart = {
success: function(res) {
Util.refreshCart(res, function() {
Stepper.init();
// 显示或者更新删除商品模块
Cart.showRemovedProducts(products, extraInfos);
});
}
});
... ... @@ -222,11 +231,68 @@ var Cart = {
},
/*
* 显示或者更新删除商品模块
* @function [removePro]
* @params { Array } products 已删除商品列表
*/
showRemovedProducts: function(products, extraInfos) {
var productsLen = products.length,
index = 0,
currentPro,
currentExtraInfo,
currentSku;
var currentRemovedLen = removedProsInfo.length;
var currentItemBuyNumber;
var template;
if (extraInfos.length) {
for (index; index < productsLen; index++) {
currentPro = products[index];
currentExtraInfo = extraInfos[index];
currentSku = currentPro.product_sku;
if (removedProSkus.indexOf(currentPro.product_sku) === -1) {
// 当前删除商品不存在
removedProSkus.push(currentSku);
removedProsInfo.push({
productName: currentExtraInfo.productName,
salesPrice: currentExtraInfo.salesPrice,
buyNumber: currentPro.buy_number,
productSku: currentSku,
productId: currentExtraInfo.productId,
goodsId: currentExtraInfo.goodsId,
cnAlphabet: currentExtraInfo.cnAlphabet,
goodType: currentExtraInfo.goodType,
selected: currentExtraInfo.selected
});
} else {
// 当前删除商品是否已经存在,如果存在就累计数量
while (currentRemovedLen--) {
currentItemBuyNumber = removedProsInfo[currentRemovedLen].buyNumber;
if (removedProsInfo[currentRemovedLen].productSku === currentSku) {
removedProsInfo[currentRemovedLen].buyNumber = currentItemBuyNumber + currentPro.buy_number;
}
}
}
}
}
// 刷新
template = hbs.compile($('#removed-products').html());
$('#removed_products').html(template({
removedProducts: removedProsInfo
}));
},
/*
* 商品移入收藏夹
* @function [sendToFavorite]
* @params { Array } products 商品列表
* @params { Function } callback 移入收藏夹成功后回调
*/
sendToFavorite: function(products) {
sendToFavorite: function(products, callback) {
var msg = '确定要将该商品从购物车中移入收藏吗?<br/>移入收藏后该商品将不在购物车中显示';
var dialog;
... ... @@ -248,6 +314,9 @@ var Cart = {
success: function(res) {
Util.refreshCart(res, function() {
Stepper.init();
if (callback) {
return callback();
}
});
}
});
... ...