Authored by hf

Merge branch 'develop' of http://git.dev.yoho.cn/web/yohobuy into develop

@@ -13,35 +13,37 @@ var chosePanel = require('./chose-panel'); @@ -13,35 +13,37 @@ var chosePanel = require('./chose-panel');
13 var $cartContent = $('.cart-content'); 13 var $cartContent = $('.cart-content');
14 14
15 var navHammer, 15 var navHammer,
16 - cartType = 'ordinary'; 16 + cartType = $('#cartType').val();
17 17
18 require('./good'); 18 require('./good');
19 19
20 lazyLoad($('img.lazy')); 20 lazyLoad($('img.lazy'));
21 21
22 -navHammer = new Hammer(document.getElementsByClassName('cart-nav')[0]);  
23 -navHammer.on('tap', function(e) {  
24 - var $this = $(e.target).closest('li'); 22 +if ($('.cart-nav').length > 0) {
  23 + navHammer = new Hammer(document.getElementsByClassName('cart-nav')[0]);
  24 + navHammer.on('tap', function(e) {
  25 + var $this = $(e.target).closest('li');
25 26
26 - if ($this.hasClass('active')) {  
27 - return;  
28 - } 27 + if ($this.hasClass('active')) {
  28 + return;
  29 + }
29 30
30 - if (cartType === 'ordinary') {  
31 - cartType = 'advance';  
32 - } else {  
33 - cartType = 'ordinary';  
34 - } 31 + if (cartType === 'ordinary') {
  32 + cartType = 'advance';
  33 + } else {
  34 + cartType = 'ordinary';
  35 + }
35 36
36 - $this.siblings('.active').removeClass('active');  
37 - $this.addClass('active'); 37 + $this.siblings('.active').removeClass('active');
  38 + $this.addClass('active');
38 39
39 - //切换普通商品和预售商品购物车显示  
40 - $cartContent.toggleClass('hide'); 40 + //切换普通商品和预售商品购物车显示
  41 + $cartContent.toggleClass('hide');
41 42
42 - //trigger lazyload  
43 - $(window).trigger('scroll');  
44 -}); 43 + //trigger lazyload
  44 + $(window).trigger('scroll');
  45 + });
  46 +}
45 47
46 $('.btn-balance').on('touchend', function() { 48 $('.btn-balance').on('touchend', function() {
47 window.location.href = '/cart/index/orderEnsure?cartType=' + cartType; 49 window.location.href = '/cart/index/orderEnsure?cartType=' + cartType;
@@ -13,9 +13,9 @@ var dialog = require('../me/dialog'), @@ -13,9 +13,9 @@ var dialog = require('../me/dialog'),
13 tip = require('../plugin/tip'); 13 tip = require('../plugin/tip');
14 14
15 var $names, 15 var $names,
16 - $selectAllBtn = $('.balance .iconfont');  
17 -  
18 -var requesting = false; 16 + $selectAllBtn = $('.balance .iconfont'),
  17 + cartType = $('#cartType').val(),
  18 + requesting = false;
19 19
20 ellipsis.init(); 20 ellipsis.init();
21 21
@@ -29,20 +29,6 @@ if ($names.length > 0) { @@ -29,20 +29,6 @@ if ($names.length > 0) {
29 $names[0].mlellipsis(2); 29 $names[0].mlellipsis(2);
30 } 30 }
31 31
32 -//获取当前购物车类型  
33 -function getCartType() {  
34 - var $navItem = $('.cart-nav ').find('li'),  
35 - type = 'ordinary';  
36 -  
37 - if ($navItem.eq(0).hasClass('active')) {  
38 - type = 'ordinary';  
39 - } else {  
40 - type = 'advance';  
41 - }  
42 -  
43 - return type;  
44 -}  
45 -  
46 //TIP:事件委托在.cart-goods,商品列表的容器统一需要有.cart-goods 32 //TIP:事件委托在.cart-goods,商品列表的容器统一需要有.cart-goods
47 $('.cart-goods').on('touchstart', '.checkbox', function() { 33 $('.cart-goods').on('touchstart', '.checkbox', function() {
48 var $this = $(this), 34 var $this = $(this),
@@ -95,13 +81,24 @@ $('.cart-goods').on('touchstart', '.checkbox', function() { @@ -95,13 +81,24 @@ $('.cart-goods').on('touchstart', '.checkbox', function() {
95 }, 81 },
96 success: function(data) { 82 success: function(data) {
97 if (data) { 83 if (data) {
98 - $('#good-totalprice').html('¥' + data.commonCart.price);  
99 - $('#good-activityPrice').html('¥' + data.commonCart.activityPrice);  
100 - $('#good-total').html('总计:¥' + data.commonCart.sumPrice + ' (' + data.commonCart.count + '件)');  
101 - if (data.commonCart.isAllSelected) {  
102 - $('.balance span').removeClass('icon-checkbox').addClass('icon-cb-checked'); 84 + if (cartType === 'ordinary') {
  85 + $('#good-totalprice').html('¥' + data.commonCart.price);
  86 + $('#good-activityPrice').html('¥' + data.commonCart.activityPrice);
  87 + $('#good-total').html('总计:¥' + data.commonCart.sumPrice + ' (' + data.commonCart.count + '件)');
  88 + if (data.commonCart.isAllSelected) {
  89 + $('.balance span').removeClass('icon-checkbox').addClass('icon-cb-checked');
  90 + } else {
  91 + $('.balance span').removeClass('icon-cb-checked').addClass('icon-checkbox');
  92 + }
103 } else { 93 } else {
104 - $('.balance span').removeClass('icon-cb-checked').addClass('icon-checkbox'); 94 + $('#good-totalprice').html('¥' + data.preSellCart.price);
  95 + $('#good-activityPrice').html('¥' + data.preSellCart.activityPrice);
  96 + $('#good-total').html('总计:¥' + data.preSellCart.sumPrice + ' (' + data.preSellCart.count + '件)');
  97 + if (data.preSellCart.isAllSelected) {
  98 + $('.balance span').removeClass('icon-checkbox').addClass('icon-cb-checked');
  99 + } else {
  100 + $('.balance span').removeClass('icon-cb-checked').addClass('icon-checkbox');
  101 + }
105 } 102 }
106 } 103 }
107 }, 104 },
@@ -115,26 +112,6 @@ $('.cart-goods').on('touchstart', '.checkbox', function() { @@ -115,26 +112,6 @@ $('.cart-goods').on('touchstart', '.checkbox', function() {
115 }).fail(function() { 112 }).fail(function() {
116 tip.show('网络错误'); 113 tip.show('网络错误');
117 }); 114 });
118 -}).on('touchstart', '.icon-edit', function() {  
119 -  
120 - //var $this = $(this);  
121 - //  
122 - //var $cartgood = $this.closest('.shopping-cart-good');  
123 - //  
124 - ////var id = $this.closest('.shopping-cart-good').data('id');  
125 - //  
126 - //var $viewGood = $cartgood.find('.deps');  
127 - // $editGoot = $cartgood.find('.calculate-num');  
128 - //  
129 - //if ($viewGood.hasClass('show')) {  
130 - // $viewGood.removeClass('show').addClass('hide');  
131 - // $editGoot.removeClass('hide').addClass('show');  
132 - //} else {  
133 - // $viewGood.removeClass('hide').addClass('show');  
134 - // $editGoot.removeClass('show').addClass('hide');  
135 - //}  
136 -  
137 -  
138 }).on('touchstart', '.icon-del', function(e) { 115 }).on('touchstart', '.icon-del', function(e) {
139 var $this = $(this); 116 var $this = $(this);
140 117
@@ -274,7 +251,7 @@ function willBeSelected($this) { @@ -274,7 +251,7 @@ function willBeSelected($this) {
274 //全选按钮点击事件 251 //全选按钮点击事件
275 $selectAllBtn.on('touchend', function() { 252 $selectAllBtn.on('touchend', function() {
276 var $this = $(this); 253 var $this = $(this);
277 - bottomCheckBoxHandeler(willBeSelected($this), getCartType(), didUpdateAllGoodsCheckStatus); 254 + bottomCheckBoxHandeler(willBeSelected($this), cartType, didUpdateAllGoodsCheckStatus);
278 }); 255 });
279 256
280 $('.down').on('touchend', function() { 257 $('.down').on('touchend', function() {
@@ -58,8 +58,7 @@ @@ -58,8 +58,7 @@
58 </div> 58 </div>
59 {{/if}} 59 {{/if}}
60 60
61 -  
62 - 61 + <input id="cartType" type="hidden" value="{{cartType}}">
63 {{/ shoppingCart}} 62 {{/ shoppingCart}}
64 63
65 {{> cart/chose-panel}} 64 {{> cart/chose-panel}}