Authored by Rock Zhang

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

@@ -20,6 +20,10 @@ require('./good'); @@ -20,6 +20,10 @@ require('./good');
20 20
21 lazyLoad($('img.lazy')); 21 lazyLoad($('img.lazy'));
22 22
  23 +if ('advance' === cartType) {
  24 + $cartContent.toggleClass('hide');
  25 +}
  26 +
23 if ($('.cart-nav').length > 0) { 27 if ($('.cart-nav').length > 0) {
24 navHammer = new Hammer(document.getElementsByClassName('cart-nav')[0]); 28 navHammer = new Hammer(document.getElementsByClassName('cart-nav')[0]);
25 navHammer.on('tap', function(e) { 29 navHammer.on('tap', function(e) {
@@ -47,11 +51,11 @@ if ($('.cart-nav').length > 0) { @@ -47,11 +51,11 @@ if ($('.cart-nav').length > 0) {
47 } 51 }
48 52
49 $('.btn-balance').on('touchend', function() { 53 $('.btn-balance').on('touchend', function() {
50 - if($('.balance span').hasClass('icon-cb-checked')){  
51 - window.location.href = '/cart/index/orderEnsure?cartType=' + cartType;  
52 - } else {  
53 - tip.show('请先勾选商品~');  
54 - } 54 + if ($('.balance span').hasClass('icon-cb-checked')) {
  55 + window.location.href = '/cart/index/orderEnsure?cartType=' + cartType;
  56 + } else {
  57 + tip.show('请先勾选商品~');
  58 + }
55 }); 59 });
56 60
57 $('.chose').on('touchend', function() { 61 $('.chose').on('touchend', function() {
@@ -21,13 +21,13 @@ var panelTmpl, @@ -21,13 +21,13 @@ var panelTmpl,
21 re = /\d+/, 21 re = /\d+/,
22 leftNum, 22 leftNum,
23 $sizeList, 23 $sizeList,
24 - colorIndex,  
25 confirming, 24 confirming,
26 hasChooseColor = false, 25 hasChooseColor = false,
27 hasChooseSize = false, 26 hasChooseSize = false,
28 curColorIndex, 27 curColorIndex,
29 curSizeIndex, 28 curSizeIndex,
30 $curSizeRow, 29 $curSizeRow,
  30 + $curSizeBlock = null,
31 $sizeRowList = $('.size-list ul'); 31 $sizeRowList = $('.size-list ul');
32 32
33 // 读取模板 33 // 读取模板
@@ -98,15 +98,13 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { @@ -98,15 +98,13 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
98 $('.color-list').on('touchstart', '.block', function(e) { 98 $('.color-list').on('touchstart', '.block', function(e) {
99 var $this = $(this), 99 var $this = $(this),
100 $that = $(e.target).closest('.chose-items'), 100 $that = $(e.target).closest('.chose-items'),
101 - numArray,  
102 index, 101 index,
103 curSelectedSizeBlock, 102 curSelectedSizeBlock,
104 $sizeChosed, 103 $sizeChosed,
105 scindex, 104 scindex,
106 - i; 105 + curGoodNum;
107 106
108 - var $siblingBlock = $this.closest('.block-list').siblings(':first'),  
109 - currentNumArray = ($this.data('numstr') + '').split('/'); 107 + var $siblingBlock = $this.closest('.block-list').siblings(':first');
110 108
111 $this.siblings('.chosed').removeClass('chosed'); 109 $this.siblings('.chosed').removeClass('chosed');
112 index = $this.index(); 110 index = $this.index();
@@ -132,26 +130,45 @@ $('.color-list').on('touchstart', '.block', function(e) { @@ -132,26 +130,45 @@ $('.color-list').on('touchstart', '.block', function(e) {
132 } 130 }
133 131
134 //把当前选中颜色对应的尺码那一行显示出来 132 //把当前选中颜色对应的尺码那一行显示出来
135 - //$sizeRowList.addClass('hide');  
136 - //$curSizeRow.toggleClass('hide'); 133 + $sizeRowList.addClass('hide');
  134 + $curSizeRow.toggleClass('hide');
137 135
138 - //之前选中行 对应的尺码去掉勾选样式  
139 - $sizeChosed.removeClass('chosed'); 136 + // 之前选中的尺码去掉勾选样式
  137 + if ($sizeChosed) {
  138 + $sizeChosed.removeClass('chosed');
  139 + }
140 140
141 - // 当前选中颜色对应的尺码行,其对应的尺码加上 (前提是要判断下这个尺码是否存在) 141 + // 当前选中颜色对应的尺码行,其对应的尺码加上勾选样式 (前提是要判断下这个尺码是否存在)
142 curSelectedSizeBlock = $curSizeRow.children().get(scindex); 142 curSelectedSizeBlock = $curSizeRow.children().get(scindex);
143 if (curSelectedSizeBlock) { 143 if (curSelectedSizeBlock) {
  144 + curGoodNum = $(curSelectedSizeBlock).data('num');
144 $(curSelectedSizeBlock).addClass('chosed'); 145 $(curSelectedSizeBlock).addClass('chosed');
  146 +
  147 + //如果当前有尺码被选中,且数量等于0,则颜色块添加数量为0的样式
  148 + if (curGoodNum > 0) {
  149 + $that.find('.num .left-num').html('剩余' + curGoodNum + '件');
  150 + } else {
  151 + $(curSelectedSizeBlock).removeClass('zero-stock').addClass('zero-stock');
  152 + $that.find('.num .left-num').html('');
  153 + }
145 } 154 }
146 } 155 }
147 156
  157 + // 当前颜色块 切换勾选样式
148 $this.toggleClass('chosed'); 158 $this.toggleClass('chosed');
149 curColorIndex = index; 159 curColorIndex = index;
150 160
  161 + // 设置按钮的样式和文字
151 $chosed = $('.chose-items').find('.chosed'); 162 $chosed = $('.chose-items').find('.chosed');
  163 + if (2 === $chosed.closest('.zero-stock').length) {
  164 + $('#chose-btn-sure').css('background-color', '#c0c0c0');
  165 + $('#chose-btn-sure').html('已售罄');
  166 + } else {
  167 + $('#chose-btn-sure').css('background-color', '#eb0313');
  168 + $('#chose-btn-sure').html('确定');
  169 + }
152 170
153 -  
154 - if ($chosed.length === 0) { 171 + /**if ($chosed.length === 0) {
155 $this.closest('ul>li').each(function() { 172 $this.closest('ul>li').each(function() {
156 $(this).removeClass('zero-stock'); 173 $(this).removeClass('zero-stock');
157 if ('0' === $(this).data('num')) { 174 if ('0' === $(this).data('num')) {
@@ -210,38 +227,74 @@ $('.color-list').on('touchstart', '.block', function(e) { @@ -210,38 +227,74 @@ $('.color-list').on('touchstart', '.block', function(e) {
210 $('#chose-btn-sure').css('background-color', '#eb0313'); 227 $('#chose-btn-sure').css('background-color', '#eb0313');
211 $('#chose-btn-sure').html('确定'); 228 $('#chose-btn-sure').html('确定');
212 } 229 }
213 - } 230 + }**/
214 231
215 }); 232 });
216 233
217 $('.size-list').on('touchstart', '.block', function(e) { 234 $('.size-list').on('touchstart', '.block', function(e) {
218 var $this = $(this), 235 var $this = $(this),
219 $that = $(e.target).closest('.chose-items'), 236 $that = $(e.target).closest('.chose-items'),
220 - numArray,  
221 index, 237 index,
222 - i; 238 + $colorChosed,
  239 + selectedColorindex,
  240 + curGoodNum;
223 241
224 - var $siblingBlock = $this.closest('.block-list').siblings(':first'),  
225 - currentNumArray = ($this.data('numstr') + '').split('/'); 242 + var $siblingBlock = $this.closest('.block-list').siblings(':first');
226 243
227 $this.siblings('.chosed').removeClass('chosed'); 244 $this.siblings('.chosed').removeClass('chosed');
228 index = $this.index(); 245 index = $this.index();
229 246
  247 + $colorChosed = $siblingBlock.find('.chosed');
  248 + selectedColorindex = $colorChosed.index();
  249 + $curSizeRow = $sizeRowList.eq(index);
  250 +
  251 + // 当前尺码已经是选中状态,再点击时
230 if ($this.hasClass('chosed')) { 252 if ($this.hasClass('chosed')) {
231 253
232 //尺码原来已经是勾选时,要清空剩余件数的提示 254 //尺码原来已经是勾选时,要清空剩余件数的提示
233 $that.find('.num .left-num').html(''); 255 $that.find('.num .left-num').html('');
234 hasChooseSize = false; 256 hasChooseSize = false;
  257 +
  258 + // 去掉已经选中颜色的 数量为0的样式
  259 + if ($colorChosed) {
  260 + $colorChosed.removeClass('zero-stock').addClass('zero-stock');
  261 + }
  262 +
  263 + // 当前尺码不是选中状态,选中时
235 } else { 264 } else {
236 hasChooseSize = true; 265 hasChooseSize = true;
  266 +
  267 + curGoodNum = $this.data('num');
  268 +
  269 + // 之前选中的尺码去掉勾选样式
  270 + if ($curSizeBlock) {
  271 + $curSizeBlock.removeClass('chosed');
  272 + }
  273 +
  274 + // 如果当前有尺码被选中,且数量等于0,则颜色块添加数量为0的样式, 否则显示剩余件数
  275 + if (curGoodNum > 0) {
  276 + $that.find('.num .left-num').html('剩余' + curGoodNum + '件');
  277 + } else {
  278 + $colorChosed.removeClass('zero-stock').addClass('zero-stock');
  279 + $that.find('.num .left-num').html('');
  280 + }
237 } 281 }
238 282
239 $this.toggleClass('chosed'); 283 $this.toggleClass('chosed');
240 curSizeIndex = index; 284 curSizeIndex = index;
  285 + $curSizeBlock = $this;
241 286
  287 + // 设置按钮的样式和文字
242 $chosed = $('.chose-items').find('.chosed'); 288 $chosed = $('.chose-items').find('.chosed');
  289 + if (2 === $chosed.closest('.zero-stock').length) {
  290 + $('#chose-btn-sure').css('background-color', '#c0c0c0');
  291 + $('#chose-btn-sure').html('已售罄');
  292 + } else {
  293 + $('#chose-btn-sure').css('background-color', '#eb0313');
  294 + $('#chose-btn-sure').html('确定');
  295 + }
243 296
244 - if ($chosed.length === 0) { 297 + /**if ($chosed.length === 0) {
245 $this.closest('ul>li').each(function() { 298 $this.closest('ul>li').each(function() {
246 $(this).removeClass('zero-stock'); 299 $(this).removeClass('zero-stock');
247 if ('0' === $(this).data('num')) { 300 if ('0' === $(this).data('num')) {
@@ -280,13 +333,13 @@ $('.size-list').on('touchstart', '.block', function(e) { @@ -280,13 +333,13 @@ $('.size-list').on('touchstart', '.block', function(e) {
280 $('#chose-btn-sure').css('background-color', '#eb0313'); 333 $('#chose-btn-sure').css('background-color', '#eb0313');
281 $('#chose-btn-sure').html('确定'); 334 $('#chose-btn-sure').html('确定');
282 335
283 - /**$siblingBlock.find('ul>li').each(function() { 336 + $siblingBlock.find('ul>li').each(function() {
284 $(this).removeClass('zero-stock'); 337 $(this).removeClass('zero-stock');
285 if ('0' === $(this).data('num')) { 338 if ('0' === $(this).data('num')) {
286 $(this).addClass('zero-stock'); 339 $(this).addClass('zero-stock');
287 } 340 }
288 }); 341 });
289 - $that.find('.num .left-num').html('');*/ 342 + $that.find('.num .left-num').html('');
290 } else if ($chosed.length === 2) { 343 } else if ($chosed.length === 2) {
291 $siblingBlock.find('.block').removeClass('zero-stock'); 344 $siblingBlock.find('.block').removeClass('zero-stock');
292 for (i = 0; i < currentNumArray.length; i++) { 345 for (i = 0; i < currentNumArray.length; i++) {
@@ -303,7 +356,7 @@ $('.size-list').on('touchstart', '.block', function(e) { @@ -303,7 +356,7 @@ $('.size-list').on('touchstart', '.block', function(e) {
303 $('#chose-btn-sure').css('background-color', '#eb0313'); 356 $('#chose-btn-sure').css('background-color', '#eb0313');
304 $('#chose-btn-sure').html('确定'); 357 $('#chose-btn-sure').html('确定');
305 } 358 }
306 - } 359 + }**/
307 360
308 }); 361 });
309 362
@@ -34,15 +34,18 @@ @@ -34,15 +34,18 @@
34 <div class="size-list block-list"> 34 <div class="size-list block-list">
35 <span>尺码</span> 35 <span>尺码</span>
36 {{# sizes}} 36 {{# sizes}}
  37 +
  38 + <ul class="size-row clearfix hide">
37 {{# size}} 39 {{# size}}
38 - <ul class="size-row clearfix" data-type="size" >  
39 - <li class="block {{#if chosed}}chosed{{/if}} {{#unless sizeNum}}zero-stock{{/unless}}" data-id={{id}} data-colorid="{{colorId}}" data-num="{{sizeNum}}" data-numstr="{{colorNumStr}}" data-skuid="{{skuId}}" data-goodid="{{goodsId}}">  
40 - {{name}}  
41 - </li>  
42 - </ul>  
43 - {{/ size}}  
44 - {{/ sizes}} 40 + <li class="block {{#if chosed}}chosed{{/if}} {{#unless sizeNum}}zero-stock{{/unless}}" data-id={{id}} data-colorid="{{colorId}}" data-num="{{sizeNum}}" data-numstr="{{colorNumStr}}" data-skuid="{{skuId}}" data-goodid="{{goodsId}}">
  41 + {{name}}
  42 + </li>
  43 + {{/ size}}
  44 + </ul>
  45 +
  46 + {{/ sizes}}
45 </div> 47 </div>
  48 + <p>
46 <div class="num"> 49 <div class="num">
47 <span>数量</span> 50 <span>数量</span>
48 <div class="clearfix"> 51 <div class="clearfix">