Authored by 梁志锋

尺码颜色选择

@@ -51,7 +51,7 @@ if ($('.cart-nav').length > 0) { @@ -51,7 +51,7 @@ if ($('.cart-nav').length > 0) {
51 } 51 }
52 52
53 $('.btn-balance').on('touchend', function() { 53 $('.btn-balance').on('touchend', function() {
54 - if($('.balance span').hasClass('icon-cb-checked')){ 54 + if ($('.balance span').hasClass('icon-cb-checked')) {
55 window.location.href = '/cart/index/orderEnsure?cartType=' + cartType; 55 window.location.href = '/cart/index/orderEnsure?cartType=' + cartType;
56 } else { 56 } else {
57 tip.show('请先勾选商品~'); 57 tip.show('请先勾选商品~');
@@ -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 i;
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 - //之前选中行 对应的尺码去掉勾选样式 136 + // 之前选中的尺码去掉勾选样式
  137 + if ($sizeChosed) {
139 $sizeChosed.removeClass('chosed'); 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 + var 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,7 +227,7 @@ $('.color-list').on('touchstart', '.block', function(e) { @@ -210,7 +227,7 @@ $('.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
@@ -219,29 +236,66 @@ $('.size-list').on('touchstart', '.block', function(e) { @@ -219,29 +236,66 @@ $('.size-list').on('touchstart', '.block', function(e) {
219 $that = $(e.target).closest('.chose-items'), 236 $that = $(e.target).closest('.chose-items'),
220 numArray, 237 numArray,
221 index, 238 index,
  239 + curSelectedSizeBlock,
  240 + $colorChosed,
  241 + selectedColorindex,
222 i; 242 i;
223 243
224 - var $siblingBlock = $this.closest('.block-list').siblings(':first'),  
225 - currentNumArray = ($this.data('numstr') + '').split('/'); 244 + var $siblingBlock = $this.closest('.block-list').siblings(':first');
226 245
227 $this.siblings('.chosed').removeClass('chosed'); 246 $this.siblings('.chosed').removeClass('chosed');
228 index = $this.index(); 247 index = $this.index();
229 248
  249 + $colorChosed = $siblingBlock.find('.chosed');
  250 + selectedColorindex = $colorChosed.index();
  251 + $curSizeRow = $sizeRowList.eq(index);
  252 +
  253 + // 当前尺码已经是选中状态,再点击时
230 if ($this.hasClass('chosed')) { 254 if ($this.hasClass('chosed')) {
231 255
232 //尺码原来已经是勾选时,要清空剩余件数的提示 256 //尺码原来已经是勾选时,要清空剩余件数的提示
233 $that.find('.num .left-num').html(''); 257 $that.find('.num .left-num').html('');
234 hasChooseSize = false; 258 hasChooseSize = false;
  259 +
  260 + // 去掉已经选中颜色的 数量为0的样式
  261 + if ($colorChosed) {
  262 + $colorChosed.removeClass('zero-stock').addClass('zero-stock');
  263 + }
  264 +
  265 + // 当前尺码不是选中状态,选中时
235 } else { 266 } else {
236 hasChooseSize = true; 267 hasChooseSize = true;
  268 +
  269 + var curGoodNum = $this.data('num');
  270 +
  271 + // 之前选中的尺码去掉勾选样式
  272 + if (preSelectedSizeBlock) {
  273 + $(preSelectedSizeBlock).removeClass('chosed');
  274 + }
  275 +
  276 + // 如果当前有尺码被选中,且数量等于0,则颜色块添加数量为0的样式, 否则显示剩余件数
  277 + if(curGoodNum > 0) {
  278 + $that.find('.num .left-num').html('剩余' + curGoodNum + '件');
  279 + } else {
  280 + $colorChosed.removeClass('zero-stock').addClass('zero-stock');
  281 + $that.find('.num .left-num').html('');
  282 + }
237 } 283 }
238 284
239 $this.toggleClass('chosed'); 285 $this.toggleClass('chosed');
240 curSizeIndex = index; 286 curSizeIndex = index;
241 287
  288 + // 设置按钮的样式和文字
242 $chosed = $('.chose-items').find('.chosed'); 289 $chosed = $('.chose-items').find('.chosed');
  290 + if (2 === $chosed.closest('.zero-stock').length) {
  291 + $('#chose-btn-sure').css('background-color', '#c0c0c0');
  292 + $('#chose-btn-sure').html('已售罄');
  293 + } else {
  294 + $('#chose-btn-sure').css('background-color', '#eb0313');
  295 + $('#chose-btn-sure').html('确定');
  296 + }
243 297
244 - if ($chosed.length === 0) { 298 + /**if ($chosed.length === 0) {
245 $this.closest('ul>li').each(function() { 299 $this.closest('ul>li').each(function() {
246 $(this).removeClass('zero-stock'); 300 $(this).removeClass('zero-stock');
247 if ('0' === $(this).data('num')) { 301 if ('0' === $(this).data('num')) {
@@ -280,13 +334,13 @@ $('.size-list').on('touchstart', '.block', function(e) { @@ -280,13 +334,13 @@ $('.size-list').on('touchstart', '.block', function(e) {
280 $('#chose-btn-sure').css('background-color', '#eb0313'); 334 $('#chose-btn-sure').css('background-color', '#eb0313');
281 $('#chose-btn-sure').html('确定'); 335 $('#chose-btn-sure').html('确定');
282 336
283 - /**$siblingBlock.find('ul>li').each(function() { 337 + $siblingBlock.find('ul>li').each(function() {
284 $(this).removeClass('zero-stock'); 338 $(this).removeClass('zero-stock');
285 if ('0' === $(this).data('num')) { 339 if ('0' === $(this).data('num')) {
286 $(this).addClass('zero-stock'); 340 $(this).addClass('zero-stock');
287 } 341 }
288 }); 342 });
289 - $that.find('.num .left-num').html('');*/ 343 + $that.find('.num .left-num').html('');
290 } else if ($chosed.length === 2) { 344 } else if ($chosed.length === 2) {
291 $siblingBlock.find('.block').removeClass('zero-stock'); 345 $siblingBlock.find('.block').removeClass('zero-stock');
292 for (i = 0; i < currentNumArray.length; i++) { 346 for (i = 0; i < currentNumArray.length; i++) {
@@ -303,7 +357,7 @@ $('.size-list').on('touchstart', '.block', function(e) { @@ -303,7 +357,7 @@ $('.size-list').on('touchstart', '.block', function(e) {
303 $('#chose-btn-sure').css('background-color', '#eb0313'); 357 $('#chose-btn-sure').css('background-color', '#eb0313');
304 $('#chose-btn-sure').html('确定'); 358 $('#chose-btn-sure').html('确定');
305 } 359 }
306 - } 360 + }**/
307 361
308 }); 362 });
309 363
@@ -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 <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 {{name}}
41 </li> 42 </li>
42 - </ul>  
43 {{/ size}} 43 {{/ size}}
  44 + </ul>
  45 +
44 {{/ sizes}} 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">