Authored by 梁志锋

尺码颜色优化

@@ -133,10 +133,17 @@ function displayGoodNum(curGoodNum) { @@ -133,10 +133,17 @@ function displayGoodNum(curGoodNum) {
133 } 133 }
134 134
135 //老的选中尺码去掉勾选,新的选中尺码加上勾选 135 //老的选中尺码去掉勾选,新的选中尺码加上勾选
136 -function changeSizeChosed(oldSizeIndex) { 136 +function changeSizeChosed(newSizeIndex) {
137 if (curColorIndex && $curSizeBlock && $curSizeBlock.length > 0) { 137 if (curColorIndex && $curSizeBlock && $curSizeBlock.length > 0) {
138 $curSizeBlock.removeClass('chosed'); 138 $curSizeBlock.removeClass('chosed');
139 - $curSizeBlock = $($sizeRowList.eq(oldSizeIndex).children().get(curColorIndex - 1)); 139 + var sizes = $sizeRowList.eq(newSizeIndex).children();
  140 + for(var i = 0; i < sizes.length; i++){
  141 + if($(sizes[i]).data('name') === $curSizeBlock.data('name')){
  142 + $curSizeBlock = $(sizes[i]);
  143 + curColorIndex = $("#" + $curSizeBlock.data('name')).data('index');
  144 + }
  145 + }
  146 +
140 $curSizeBlock.addClass('chosed'); 147 $curSizeBlock.addClass('chosed');
141 return $curSizeBlock.data('num'); 148 return $curSizeBlock.data('num');
142 } 149 }
@@ -144,10 +151,10 @@ function changeSizeChosed(oldSizeIndex) { @@ -144,10 +151,10 @@ function changeSizeChosed(oldSizeIndex) {
144 } 151 }
145 152
146 //老的选中颜色去掉勾选,新的选中颜色加上勾选 153 //老的选中颜色去掉勾选,新的选中颜色加上勾选
147 -function changeColorChosed(oldColorIndex) { 154 +function changeColorChosed(newColorIndex) {
148 if (curSizeIndex && $curColorBlock && $curColorBlock.length > 0) { 155 if (curSizeIndex && $curColorBlock && $curColorBlock.length > 0) {
149 $curColorBlock.removeClass('chosed'); 156 $curColorBlock.removeClass('chosed');
150 - $curColorBlock = $($colorRowList.eq(oldColorIndex).children().get(curSizeIndex - 1)); 157 + $curColorBlock = $($colorRowList.eq(newColorIndex).children().get(curSizeIndex - 1));
151 $curColorBlock.addClass('chosed'); 158 $curColorBlock.addClass('chosed');
152 return $curColorBlock.data('num'); 159 return $curColorBlock.data('num');
153 } 160 }
@@ -195,15 +202,15 @@ $yohoPage.on('touchstart', '.color-list .block', function() { @@ -195,15 +202,15 @@ $yohoPage.on('touchstart', '.color-list .block', function() {
195 } else { 202 } else {
196 hasChooseColor = true; 203 hasChooseColor = true;
197 204
  205 + // 尺码行当前行隐藏
  206 + $sizeRowList.eq(curSizeIndex).addClass('hide');
  207 +
198 //老的选中尺码去掉勾选,新的选中尺码加上勾选 208 //老的选中尺码去掉勾选,新的选中尺码加上勾选
199 curGoodNum = changeSizeChosed(index + 1); 209 curGoodNum = changeSizeChosed(index + 1);
200 210
201 // 显示剩余数量 211 // 显示剩余数量
202 displayGoodNum(curGoodNum); 212 displayGoodNum(curGoodNum);
203 213
204 - // 尺码行当前行隐藏  
205 - $sizeRowList.eq(curSizeIndex).addClass('hide');  
206 -  
207 //尺码对应行显示 214 //尺码对应行显示
208 $sizeRowList.eq(index + 1).removeClass('hide'); 215 $sizeRowList.eq(index + 1).removeClass('hide');
209 216
@@ -224,6 +231,7 @@ $yohoPage.on('touchstart', '.color-list .block', function() { @@ -224,6 +231,7 @@ $yohoPage.on('touchstart', '.color-list .block', function() {
224 }).on('touchstart', '.size-list .block', function() { 231 }).on('touchstart', '.size-list .block', function() {
225 var $this = $(this), 232 var $this = $(this),
226 index = $this.index(), 233 index = $this.index(),
  234 + colorName,
227 curGoodNum; 235 curGoodNum;
228 236
229 // 当前尺码已经是选中状态,再点击时 237 // 当前尺码已经是选中状态,再点击时
@@ -235,10 +243,10 @@ $yohoPage.on('touchstart', '.color-list .block', function() { @@ -235,10 +243,10 @@ $yohoPage.on('touchstart', '.color-list .block', function() {
235 hasChooseSize = false; 243 hasChooseSize = false;
236 244
237 //当前颜色行隐藏 245 //当前颜色行隐藏
238 - $colorRowList.eq(curColorIndex).removeClass('show').addClass('hide'); 246 + $colorRowList.eq(curColorIndex).addClass('hide');
239 247
240 //目标颜色行显示 248 //目标颜色行显示
241 - $colorRowList.eq(0).removeClass('hide').addClass('show'); 249 + $colorRowList.eq(0).removeClass('hide');
242 250
243 curColorIndex = 0; 251 curColorIndex = 0;
244 252
@@ -249,17 +257,20 @@ $yohoPage.on('touchstart', '.color-list .block', function() { @@ -249,17 +257,20 @@ $yohoPage.on('touchstart', '.color-list .block', function() {
249 } else { 257 } else {
250 hasChooseSize = true; 258 hasChooseSize = true;
251 259
  260 + colorName = $this.data('name');
  261 + index = $("#"+colorName).data('index') -1;
  262 +
  263 + // 颜色当前行隐藏
  264 + $colorRowList.eq(curColorIndex).addClass('hide');
  265 +
252 //老的选中颜色去掉勾选,新的选中颜色加上勾选 266 //老的选中颜色去掉勾选,新的选中颜色加上勾选
253 curGoodNum = changeColorChosed(index + 1); 267 curGoodNum = changeColorChosed(index + 1);
254 268
255 // 显示剩余数量 269 // 显示剩余数量
256 displayGoodNum(curGoodNum); 270 displayGoodNum(curGoodNum);
257 271
258 - // 颜色当前行隐藏  
259 - $colorRowList.eq(curColorIndex).removeClass('show').addClass('hide');  
260 -  
261 //颜色对应行显示 272 //颜色对应行显示
262 - $colorRowList.eq(index + 1).removeClass('hide').addClass('show'); 273 + $colorRowList.eq(index + 1).removeClass('hide');
263 274
264 curColorIndex = index + 1; 275 curColorIndex = index + 1;
265 $curSizeBlock = $this; 276 $curSizeBlock = $this;