Authored by 梁志锋

购物车尺码颜色选择

@@ -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 // 读取模板
@@ -102,7 +102,7 @@ $('.color-list').on('touchstart', '.block', function(e) { @@ -102,7 +102,7 @@ $('.color-list').on('touchstart', '.block', function(e) {
102 curSelectedSizeBlock, 102 curSelectedSizeBlock,
103 $sizeChosed, 103 $sizeChosed,
104 scindex, 104 scindex,
105 - i; 105 + curGoodNum;
106 106
107 var $siblingBlock = $this.closest('.block-list').siblings(':first'); 107 var $siblingBlock = $this.closest('.block-list').siblings(':first');
108 108
@@ -141,11 +141,11 @@ $('.color-list').on('touchstart', '.block', function(e) { @@ -141,11 +141,11 @@ $('.color-list').on('touchstart', '.block', function(e) {
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 + curGoodNum = $(curSelectedSizeBlock).data('num');
145 $(curSelectedSizeBlock).addClass('chosed'); 145 $(curSelectedSizeBlock).addClass('chosed');
146 146
147 //如果当前有尺码被选中,且数量等于0,则颜色块添加数量为0的样式 147 //如果当前有尺码被选中,且数量等于0,则颜色块添加数量为0的样式
148 - if(curGoodNum > 0) { 148 + if (curGoodNum > 0) {
149 $that.find('.num .left-num').html('剩余' + curGoodNum + '件'); 149 $that.find('.num .left-num').html('剩余' + curGoodNum + '件');
150 } else { 150 } else {
151 $(curSelectedSizeBlock).removeClass('zero-stock').addClass('zero-stock'); 151 $(curSelectedSizeBlock).removeClass('zero-stock').addClass('zero-stock');
@@ -234,12 +234,10 @@ $('.color-list').on('touchstart', '.block', function(e) { @@ -234,12 +234,10 @@ $('.color-list').on('touchstart', '.block', function(e) {
234 $('.size-list').on('touchstart', '.block', function(e) { 234 $('.size-list').on('touchstart', '.block', function(e) {
235 var $this = $(this), 235 var $this = $(this),
236 $that = $(e.target).closest('.chose-items'), 236 $that = $(e.target).closest('.chose-items'),
237 - numArray,  
238 index, 237 index,
239 - curSelectedSizeBlock,  
240 $colorChosed, 238 $colorChosed,
241 selectedColorindex, 239 selectedColorindex,
242 - i; 240 + curGoodNum;
243 241
244 var $siblingBlock = $this.closest('.block-list').siblings(':first'); 242 var $siblingBlock = $this.closest('.block-list').siblings(':first');
245 243
@@ -266,15 +264,15 @@ $('.size-list').on('touchstart', '.block', function(e) { @@ -266,15 +264,15 @@ $('.size-list').on('touchstart', '.block', function(e) {
266 } else { 264 } else {
267 hasChooseSize = true; 265 hasChooseSize = true;
268 266
269 - var curGoodNum = $this.data('num'); 267 + curGoodNum = $this.data('num');
270 268
271 // 之前选中的尺码去掉勾选样式 269 // 之前选中的尺码去掉勾选样式
272 - if (preSelectedSizeBlock) {  
273 - $(preSelectedSizeBlock).removeClass('chosed'); 270 + if ($curSizeBlock) {
  271 + $curSizeBlock.removeClass('chosed');
274 } 272 }
275 273
276 // 如果当前有尺码被选中,且数量等于0,则颜色块添加数量为0的样式, 否则显示剩余件数 274 // 如果当前有尺码被选中,且数量等于0,则颜色块添加数量为0的样式, 否则显示剩余件数
277 - if(curGoodNum > 0) { 275 + if (curGoodNum > 0) {
278 $that.find('.num .left-num').html('剩余' + curGoodNum + '件'); 276 $that.find('.num .left-num').html('剩余' + curGoodNum + '件');
279 } else { 277 } else {
280 $colorChosed.removeClass('zero-stock').addClass('zero-stock'); 278 $colorChosed.removeClass('zero-stock').addClass('zero-stock');
@@ -284,6 +282,7 @@ $('.size-list').on('touchstart', '.block', function(e) { @@ -284,6 +282,7 @@ $('.size-list').on('touchstart', '.block', function(e) {
284 282
285 $this.toggleClass('chosed'); 283 $this.toggleClass('chosed');
286 curSizeIndex = index; 284 curSizeIndex = index;
  285 + $curSizeBlock = $this;
287 286
288 // 设置按钮的样式和文字 287 // 设置按钮的样式和文字
289 $chosed = $('.chose-items').find('.chosed'); 288 $chosed = $('.chose-items').find('.chosed');