Authored by 梁志锋

购物车修改

@@ -22,7 +22,6 @@ var $chosePanel = $('#chose-panel'), @@ -22,7 +22,6 @@ var $chosePanel = $('#chose-panel'),
22 confirming, 22 confirming,
23 curColorIndex, 23 curColorIndex,
24 curSizeIndex, 24 curSizeIndex,
25 - $curSizeRow,  
26 hasChooseColor, 25 hasChooseColor,
27 hasChooseSize, 26 hasChooseSize,
28 $curSizeBlock, 27 $curSizeBlock,
@@ -34,8 +33,6 @@ var $chosePanel = $('#chose-panel'), @@ -34,8 +33,6 @@ var $chosePanel = $('#chose-panel'),
34 33
35 //初始化购物车面板显示 34 //初始化购物车面板显示
36 function init() { 35 function init() {
37 - var $firstRow;  
38 -  
39 hasChooseColor = false; 36 hasChooseColor = false;
40 hasChooseSize = false; 37 hasChooseSize = false;
41 $curSizeBlock = null; 38 $curSizeBlock = null;
@@ -44,9 +41,7 @@ function init() { @@ -44,9 +41,7 @@ function init() {
44 $allChoseItems = $('.chose-items'); 41 $allChoseItems = $('.chose-items');
45 $sizeRowList = $('.size-list ul'); 42 $sizeRowList = $('.size-list ul');
46 $leftNum = $('#left-num'); 43 $leftNum = $('#left-num');
47 - $firstRow = $sizeRowList.eq(0);  
48 - $firstRow.toggleClass('hide');  
49 - $curSizeRow = $firstRow; 44 + $sizeRowList.eq(0).toggleClass('hide');
50 } 45 }
51 46
52 function checkColorSizeNum() { 47 function checkColorSizeNum() {
@@ -69,6 +64,7 @@ function show(html, cb) { @@ -69,6 +64,7 @@ function show(html, cb) {
69 init(); 64 init();
70 } 65 }
71 $('.chose-panel').show(); 66 $('.chose-panel').show();
  67 + $('body').css('overflow', 'hidden');
72 $num = $('#good-num'); 68 $num = $('#good-num');
73 cbFn = cb; 69 cbFn = cb;
74 } 70 }
@@ -76,6 +72,7 @@ function show(html, cb) { @@ -76,6 +72,7 @@ function show(html, cb) {
76 //隐藏当前Panel 72 //隐藏当前Panel
77 function hide() { 73 function hide() {
78 $('.chose-panel').hide(); 74 $('.chose-panel').hide();
  75 + $('body').css('overflow', 'auto');
79 } 76 }
80 77
81 //修改加入购物车的文字和背景 78 //修改加入购物车的文字和背景
@@ -90,18 +87,19 @@ function updateConformButtonClassAndText() { @@ -90,18 +87,19 @@ function updateConformButtonClassAndText() {
90 87
91 //重置颜色块的库存为0的样式 88 //重置颜色块的库存为0的样式
92 function resetColorZeroStock($siblingBlock) { 89 function resetColorZeroStock($siblingBlock) {
93 - var numArray = ($curSizeBlock.data('numstr') + '').split('/'), 90 + var numArray,
94 i; 91 i;
95 92
96 if (!hasChooseSize) { 93 if (!hasChooseSize) {
97 $siblingBlock.find('ul>li').each(function() { 94 $siblingBlock.find('ul>li').each(function() {
98 $(this).removeClass('zero-stock'); 95 $(this).removeClass('zero-stock');
99 - if ('0' === $(this).data('num')) { 96 + if (0 === $(this).data('num')) {
100 $(this).addClass('zero-stock'); 97 $(this).addClass('zero-stock');
101 } 98 }
102 }); 99 });
103 100
104 } else { 101 } else {
  102 + numArray = ($curSizeBlock.data('numstr') + '').split('/')
105 for (i = 0; i < numArray.length; i++) { 103 for (i = 0; i < numArray.length; i++) {
106 if ('0' === numArray[i]) { 104 if ('0' === numArray[i]) {
107 $siblingBlock.find('.block').eq(i).addClass('zero-stock'); 105 $siblingBlock.find('.block').eq(i).addClass('zero-stock');
@@ -130,12 +128,13 @@ $yohoPage.on('touchstart', '.chose-panel', function(e) { @@ -130,12 +128,13 @@ $yohoPage.on('touchstart', '.chose-panel', function(e) {
130 hide(); 128 hide();
131 }); 129 });
132 130
133 -$yohoPage.on('touchstart', '.color-list .block', function(e) { 131 +$yohoPage.on('touchstart', '.color-list .block', function() {
134 var $this = $(this), 132 var $this = $(this),
135 index, 133 index,
136 curSizeBlock, 134 curSizeBlock,
137 $preSiblingBlock, 135 $preSiblingBlock,
138 - scindex, 136 + $curSizeRow,
  137 + numArray,
139 curGoodNum; 138 curGoodNum;
140 139
141 var $siblingBlock = $this.closest('.block-list').siblings(':first'); 140 var $siblingBlock = $this.closest('.block-list').siblings(':first');
@@ -144,7 +143,6 @@ $yohoPage.on('touchstart', '.color-list .block', function(e) { @@ -144,7 +143,6 @@ $yohoPage.on('touchstart', '.color-list .block', function(e) {
144 index = $this.index(); 143 index = $this.index();
145 144
146 $preSiblingBlock = $siblingBlock.find('.chosed'); 145 $preSiblingBlock = $siblingBlock.find('.chosed');
147 - scindex = $preSiblingBlock.index();  
148 $curSizeRow = $sizeRowList.eq(index); 146 $curSizeRow = $sizeRowList.eq(index);
149 147
150 // 当前颜色已经是选中状态,再点击时 148 // 当前颜色已经是选中状态,再点击时
@@ -155,6 +153,16 @@ $yohoPage.on('touchstart', '.color-list .block', function(e) { @@ -155,6 +153,16 @@ $yohoPage.on('touchstart', '.color-list .block', function(e) {
155 $leftNum.val(0); 153 $leftNum.val(0);
156 hasChooseColor = false; 154 hasChooseColor = false;
157 155
  156 + $this.removeClass('zero-stock');
  157 + if ($curSizeBlock) {
  158 + numArray = ($curSizeBlock.data('numstr') + '').split('/')
  159 + for (i = 0; i < numArray.length; i++) {
  160 + if ('0' === numArray[i]) {
  161 + $('.color-list .block').eq(i).addClass('zero-stock');
  162 + }
  163 + }
  164 + }
  165 +
158 // 当前颜色不是选中状态,选中时 166 // 当前颜色不是选中状态,选中时
159 } else { 167 } else {
160 hasChooseColor = true; 168 hasChooseColor = true;
@@ -166,7 +174,7 @@ $yohoPage.on('touchstart', '.color-list .block', function(e) { @@ -166,7 +174,7 @@ $yohoPage.on('touchstart', '.color-list .block', function(e) {
166 // 之前选中的尺码去掉勾选样式 174 // 之前选中的尺码去掉勾选样式
167 if ($preSiblingBlock.length > 0) { 175 if ($preSiblingBlock.length > 0) {
168 $preSiblingBlock.removeClass('chosed'); 176 $preSiblingBlock.removeClass('chosed');
169 - curSizeBlock = $curSizeRow.children().get(scindex); 177 + curSizeBlock = $curSizeRow.children().get(curSizeIndex);
170 } 178 }
171 179
172 // 当前选中颜色对应的尺码行,其对应的尺码加上勾选样式 (前提是要判断下这个尺码是否存在) 180 // 当前选中颜色对应的尺码行,其对应的尺码加上勾选样式 (前提是要判断下这个尺码是否存在)
@@ -194,11 +202,10 @@ $yohoPage.on('touchstart', '.color-list .block', function(e) { @@ -194,11 +202,10 @@ $yohoPage.on('touchstart', '.color-list .block', function(e) {
194 202
195 // 修改颜色时修改商品图片 203 // 修改颜色时修改商品图片
196 changeGoodImgWhenClickColor(); 204 changeGoodImgWhenClickColor();
197 -});  
198 -  
199 -$yohoPage.on('touchstart', '.size-list .block', function(e) { 205 +}).on('touchstart', '.size-list .block', function() {
200 var $this = $(this), 206 var $this = $(this),
201 index, 207 index,
  208 + $curSizeRow,
202 curGoodNum; 209 curGoodNum;
203 210
204 var $siblingBlock = $this.closest('.block-list').siblings(':first'); 211 var $siblingBlock = $this.closest('.block-list').siblings(':first');
@@ -246,7 +253,6 @@ $yohoPage.on('touchstart', '.size-list .block', function(e) { @@ -246,7 +253,6 @@ $yohoPage.on('touchstart', '.size-list .block', function(e) {
246 253
247 // 重置颜色块的样式 254 // 重置颜色块的样式
248 resetColorZeroStock($siblingBlock); 255 resetColorZeroStock($siblingBlock);
249 -  
250 }); 256 });
251 257
252 $yohoPage.on('touchstart', '.btn-minus', function() { 258 $yohoPage.on('touchstart', '.btn-minus', function() {
@@ -332,7 +338,6 @@ $yohoPage.on('touchstart', '.btn-minus', function() { @@ -332,7 +338,6 @@ $yohoPage.on('touchstart', '.btn-minus', function() {
332 if (res.code === 200) { 338 if (res.code === 200) {
333 $('.num-tag').html(numInCart + buyNumber).removeClass('hide'); 339 $('.num-tag').html(numInCart + buyNumber).removeClass('hide');
334 confirming = false; 340 confirming = false;
335 - hide();  
336 341
337 if (cbFn) { 342 if (cbFn) {
338 cbFn(); 343 cbFn();
@@ -341,6 +346,8 @@ $yohoPage.on('touchstart', '.btn-minus', function() { @@ -341,6 +346,8 @@ $yohoPage.on('touchstart', '.btn-minus', function() {
341 if (res.message) { 346 if (res.message) {
342 tip.show(res.message); 347 tip.show(res.message);
343 } 348 }
  349 +
  350 + hide();
344 }).fail(function() { 351 }).fail(function() {
345 tip.show('网络出了点问题~'); 352 tip.show('网络出了点问题~');
346 }).always(function() { 353 }).always(function() {