...
|
...
|
@@ -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();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
});
|
...
|
...
|
|