Authored by jinhu.tung

add removed products and send to favorite

@@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
9 {{> cart/empty-cart}} 9 {{> cart/empty-cart}}
10 {{/if}} 10 {{/if}}
11 </div> 11 </div>
  12 + <div id="removed_products"></div>
12 </div> 13 </div>
13 14
14 <script id="edit-color-size-tpl" type="text/html"> 15 <script id="edit-color-size-tpl" type="text/html">
@@ -322,3 +323,28 @@ @@ -322,3 +323,28 @@
322 </a> 323 </a>
323 </div> 324 </div>
324 </script> 325 </script>
  326 +
  327 +<script id="removed-products" type="text/html">
  328 + <div class="cart-removed-list">
  329 + <div class="info-bar">
  330 + <p class="info-text">已删除商品,您可以重新购买或移入收藏:</p>
  331 + </div>
  332 + <div class="removed-products">
  333 + <ul>
  334 + \{{#each removedProducts}}
  335 + <li class="removed-product">
  336 + <div class="product-name">
  337 + <a href="/product/pro_\{{productId}}_\{{goodsId}}/\{{cnAlphabet}}.html" target="_blank">\{{productName}}</a>
  338 + </div>
  339 + <div class="product-price">¥ \{{salesPrice}}</div>
  340 + <div class="bought-num">\{{buyNumber}}</div>
  341 + <div class="actions">
  342 + <span class="buy-again">重新购买</span>
  343 + <span class="send-to-favorite" data-product_info='{"goods_type": "\{{goodType}}", "buy_number": \{{buyNumber}}, "selected": "\{{selected}}", "product_sku": "\{{productSku}}", "promotion_id": 0}'>移入收藏夹</span>
  344 + </div>
  345 + </li>
  346 + \{{/each}}
  347 + </ul>
  348 + </div>
  349 + </div>
  350 +</script>
@@ -44,7 +44,7 @@ @@ -44,7 +44,7 @@
44 <li class="total-price-action"> 44 <li class="total-price-action">
45 <span class="price item-total-price">¥ {{round (multiple sales_price buy_number) 2}}</span> 45 <span class="price item-total-price">¥ {{round (multiple sales_price buy_number) 2}}</span>
46 <div class="actions"> 46 <div class="actions">
47 - <div class="remove-item action" data-product_id={{product_id}}><span class="iconfont">&#xe614;</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div> 47 + <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>
48 <div class="send-to-favorite action" data-product_id={{product_id}}>移入收藏夹</div> 48 <div class="send-to-favorite action" data-product_id={{product_id}}>移入收藏夹</div>
49 </div> 49 </div>
50 </li> 50 </li>
@@ -98,7 +98,7 @@ @@ -98,7 +98,7 @@
98 <li class="total-price-action"> 98 <li class="total-price-action">
99 <span class="price item-total-price">¥ {{round (multiple sales_price buy_number) 2}}</span> 99 <span class="price item-total-price">¥ {{round (multiple sales_price buy_number) 2}}</span>
100 <div class="actions"> 100 <div class="actions">
101 - <div class="remove-item action" data-product_id={{product_id}}><span class="iconfont">&#xe614;</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div> 101 + <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>
102 <div class="send-to-favorite action" data-product_id={{product_id}}>移入收藏夹</div> 102 <div class="send-to-favorite action" data-product_id={{product_id}}>移入收藏夹</div>
103 </div> 103 </div>
104 </li> 104 </li>
1 -<div class="cart-removed-list">  
2 - <div class="info-bar">  
3 - <p class="info-text">已删除商品,您可以重新购买或移入收藏:</p>  
4 - </div>  
5 - <div class="removed-products">  
6 - <ul>  
7 - <li class="removed-product">  
8 - <div class="product-name">TEEBACOO虎头字母短袖T恤</div>  
9 - <div class="product-price">¥ 373.00</div>  
10 - <div class="bought-num">2</div>  
11 - <div class="actions">  
12 - <span class="buy-again">重新购买</span>  
13 - <span class="send-to-favorite">移入收藏夹</span>  
14 - </div>  
15 - </li>  
16 - <li class="removed-product">  
17 - <div class="product-name">NIKIE AIR FORCE1</div>  
18 - <div class="product-price">¥ 373.00</div>  
19 - <div class="bought-num">2</div>  
20 - <div class="actions">  
21 - <span class="buy-again">重新购买</span>  
22 - <span class="send-to-favorite">移入收藏夹</span>  
23 - </div>  
24 - </li>  
25 - </ul>  
26 - </div>  
27 -</div>  
@@ -22,8 +22,14 @@ $(function() { @@ -22,8 +22,14 @@ $(function() {
22 Cart.toggleCheck.call(Cart, this); 22 Cart.toggleCheck.call(Cart, this);
23 }).delegate('.remove-item', 'click', function() { 23 }).delegate('.remove-item', 'click', function() {
24 // 删除商品 24 // 删除商品
25 - // 重构  
26 - Cart.removePro([$.parseJSON($(this).parents('ul').children().first().attr('data-product_info'))]); 25 + // 失效商品删除,不用显示在删除模块
  26 + var productExtraInfo = $(this).attr('data-product_extra_info'),
  27 + productExtraInfoArr = productExtraInfo ? [$.parseJSON(productExtraInfo)] : [];
  28 +
  29 + Cart.removePro(
  30 + [$.parseJSON($(this).parents('ul').children().first().attr('data-product_info'))],
  31 + productExtraInfoArr
  32 + );
27 }).delegate('#remove_selected', 'click', function(e) { 33 }).delegate('#remove_selected', 'click', function(e) {
28 // 删除多个商品 34 // 删除多个商品
29 // 重构 35 // 重构
@@ -92,6 +98,16 @@ $(function() { @@ -92,6 +98,16 @@ $(function() {
92 return false; 98 return false;
93 }); 99 });
94 100
  101 + $('#removed_products').delegate('.send-to-favorite', 'click', function() {
  102 + Cart.sendToFavorite([$.parseJSON($(this).attr('data-product_info'))], function() {
  103 + if ($('#removed_products .removed-product').length > 1) {
  104 + $(this).remove();
  105 + } else {
  106 + $('#removed_products').html('');
  107 + }
  108 + });
  109 + });
  110 +
95 // 变动商品数量 111 // 变动商品数量
96 Stepper.init(); 112 Stepper.init();
97 }); 113 });
@@ -13,6 +13,10 @@ var Util = require('./util'); @@ -13,6 +13,10 @@ var Util = require('./util');
13 var hbs = require('yoho-handlebars'); 13 var hbs = require('yoho-handlebars');
14 var Stepper = require('./stepper'); 14 var Stepper = require('./stepper');
15 15
  16 +// 删除商品信息
  17 +var removedProSkus = [];
  18 +var removedProsInfo = [];
  19 +
16 var Cart = { 20 var Cart = {
17 /* 21 /*
18 * 添加到购物车 22 * 添加到购物车
@@ -195,11 +199,13 @@ var Cart = { @@ -195,11 +199,13 @@ var Cart = {
195 * 删除商品 199 * 删除商品
196 * @function [removePro] 200 * @function [removePro]
197 * @params { Array } products 商品列表 201 * @params { Array } products 商品列表
  202 + * @params { Array } extraInfos 删除商品额外信息
198 */ 203 */
199 - removePro: function(products) { 204 + removePro: function(products, extraInfos) {
200 var dialog; 205 var dialog;
201 206
202 if (products.length) { 207 if (products.length) {
  208 + // Cart.showRemovedProducts(products, extraInfos);
203 dialog = new _confirm({ 209 dialog = new _confirm({
204 content: '您确定要从购物车中删除该商品吗?', 210 content: '您确定要从购物车中删除该商品吗?',
205 cb: function() { 211 cb: function() {
@@ -211,6 +217,9 @@ var Cart = { @@ -211,6 +217,9 @@ var Cart = {
211 success: function(res) { 217 success: function(res) {
212 Util.refreshCart(res, function() { 218 Util.refreshCart(res, function() {
213 Stepper.init(); 219 Stepper.init();
  220 +
  221 + // 显示或者更新删除商品模块
  222 + Cart.showRemovedProducts(products, extraInfos);
214 }); 223 });
215 } 224 }
216 }); 225 });
@@ -222,11 +231,68 @@ var Cart = { @@ -222,11 +231,68 @@ var Cart = {
222 }, 231 },
223 232
224 /* 233 /*
  234 + * 显示或者更新删除商品模块
  235 + * @function [removePro]
  236 + * @params { Array } products 已删除商品列表
  237 + */
  238 + showRemovedProducts: function(products, extraInfos) {
  239 + var productsLen = products.length,
  240 + index = 0,
  241 + currentPro,
  242 + currentExtraInfo,
  243 + currentSku;
  244 +
  245 + var currentRemovedLen = removedProsInfo.length;
  246 + var currentItemBuyNumber;
  247 +
  248 + var template;
  249 +
  250 + if (extraInfos.length) {
  251 + for (index; index < productsLen; index++) {
  252 + currentPro = products[index];
  253 + currentExtraInfo = extraInfos[index];
  254 + currentSku = currentPro.product_sku;
  255 +
  256 + if (removedProSkus.indexOf(currentPro.product_sku) === -1) {
  257 + // 当前删除商品不存在
  258 + removedProSkus.push(currentSku);
  259 + removedProsInfo.push({
  260 + productName: currentExtraInfo.productName,
  261 + salesPrice: currentExtraInfo.salesPrice,
  262 + buyNumber: currentPro.buy_number,
  263 + productSku: currentSku,
  264 + productId: currentExtraInfo.productId,
  265 + goodsId: currentExtraInfo.goodsId,
  266 + cnAlphabet: currentExtraInfo.cnAlphabet,
  267 + goodType: currentExtraInfo.goodType,
  268 + selected: currentExtraInfo.selected
  269 + });
  270 + } else {
  271 + // 当前删除商品是否已经存在,如果存在就累计数量
  272 + while (currentRemovedLen--) {
  273 + currentItemBuyNumber = removedProsInfo[currentRemovedLen].buyNumber;
  274 + if (removedProsInfo[currentRemovedLen].productSku === currentSku) {
  275 + removedProsInfo[currentRemovedLen].buyNumber = currentItemBuyNumber + currentPro.buy_number;
  276 + }
  277 + }
  278 + }
  279 + }
  280 + }
  281 +
  282 + // 刷新
  283 + template = hbs.compile($('#removed-products').html());
  284 + $('#removed_products').html(template({
  285 + removedProducts: removedProsInfo
  286 + }));
  287 + },
  288 +
  289 + /*
225 * 商品移入收藏夹 290 * 商品移入收藏夹
226 * @function [sendToFavorite] 291 * @function [sendToFavorite]
227 * @params { Array } products 商品列表 292 * @params { Array } products 商品列表
  293 + * @params { Function } callback 移入收藏夹成功后回调
228 */ 294 */
229 - sendToFavorite: function(products) { 295 + sendToFavorite: function(products, callback) {
230 var msg = '确定要将该商品从购物车中移入收藏吗?<br/>移入收藏后该商品将不在购物车中显示'; 296 var msg = '确定要将该商品从购物车中移入收藏吗?<br/>移入收藏后该商品将不在购物车中显示';
231 var dialog; 297 var dialog;
232 298
@@ -248,6 +314,9 @@ var Cart = { @@ -248,6 +314,9 @@ var Cart = {
248 success: function(res) { 314 success: function(res) {
249 Util.refreshCart(res, function() { 315 Util.refreshCart(res, function() {
250 Stepper.init(); 316 Stepper.init();
  317 + if (callback) {
  318 + return callback();
  319 + }
251 }); 320 });
252 } 321 }
253 }); 322 });