Showing
1 changed file
with
119 additions
and
95 deletions
@@ -26,6 +26,11 @@ var $chosePanel = $('#chose-panel'), | @@ -26,6 +26,11 @@ var $chosePanel = $('#chose-panel'), | ||
26 | hasChooseSize, | 26 | hasChooseSize, |
27 | $curSizeBlock, | 27 | $curSizeBlock, |
28 | $sizeRowList, | 28 | $sizeRowList, |
29 | + $curColorBlock, | ||
30 | + $colorRowList, | ||
31 | + $curSizeRow, | ||
32 | + $curColorRow, | ||
33 | + rowIndex, | ||
29 | cbFn, | 34 | cbFn, |
30 | $allChoseItems, | 35 | $allChoseItems, |
31 | queryString, | 36 | queryString, |
@@ -41,7 +46,13 @@ function init() { | @@ -41,7 +46,13 @@ function init() { | ||
41 | $imgsThumb = $('.chose-panel').find('.thumb'); | 46 | $imgsThumb = $('.chose-panel').find('.thumb'); |
42 | $allChoseItems = $('.chose-items'); | 47 | $allChoseItems = $('.chose-items'); |
43 | $sizeRowList = $('.size-list ul'); | 48 | $sizeRowList = $('.size-list ul'); |
49 | + $colorRowList = $('.color-list ul'); | ||
44 | $leftNum = $('#left-num'); | 50 | $leftNum = $('#left-num'); |
51 | + $curSizeRow = $sizeRowList.eq(0); | ||
52 | + $curColorRow = $colorRowList.eq(0); | ||
53 | + rowIndex = 0; | ||
54 | + curColorIndex = 0; | ||
55 | + curSizeIndex = 0; | ||
45 | } | 56 | } |
46 | 57 | ||
47 | function checkColorSizeNum() { | 58 | function checkColorSizeNum() { |
@@ -107,39 +118,6 @@ function updateConformButtonClassAndText() { | @@ -107,39 +118,6 @@ function updateConformButtonClassAndText() { | ||
107 | } | 118 | } |
108 | } | 119 | } |
109 | 120 | ||
110 | -//重置颜色块的库存为0的样式 | ||
111 | -function resetColorZeroStock($siblingBlock) { | ||
112 | - var numArray, | ||
113 | - i; | ||
114 | - | ||
115 | - if (!hasChooseSize) { | ||
116 | - $siblingBlock.find('ul>li').each(function() { | ||
117 | - if (0 === $(this).data('num')) { | ||
118 | - $(this).addClass('zero-stock'); | ||
119 | - } else { | ||
120 | - $(this).removeClass('zero-stock'); | ||
121 | - } | ||
122 | - }); | ||
123 | - | ||
124 | - } else { | ||
125 | - numArray = ($curSizeBlock.data('numstr') + '').split('/'); | ||
126 | - for (i = 0; i < numArray.length; i++) { | ||
127 | - if ('0' === numArray[i]) { | ||
128 | - $siblingBlock.find('.block').eq(i).addClass('zero-stock'); | ||
129 | - } else { | ||
130 | - $siblingBlock.find('.block').eq(i).removeClass('zero-stock'); | ||
131 | - } | ||
132 | - } | ||
133 | - } | ||
134 | -} | ||
135 | - | ||
136 | -// 选择了颜色切换商品图片 | ||
137 | -function changeGoodImgWhenClickColor() { | ||
138 | - if (hasChooseColor && curColorIndex >= 0) { | ||
139 | - $imgsThumb.addClass('hide').eq(curColorIndex).removeClass('hide'); | ||
140 | - } | ||
141 | -} | ||
142 | - | ||
143 | init(); | 121 | init(); |
144 | 122 | ||
145 | $yohoPage.on('touchstart', '.chose-panel', function(e) { | 123 | $yohoPage.on('touchstart', '.chose-panel', function(e) { |
@@ -157,10 +135,6 @@ $yohoPage.on('touchstart', '.color-list .block', function() { | @@ -157,10 +135,6 @@ $yohoPage.on('touchstart', '.color-list .block', function() { | ||
157 | var $this = $(this), | 135 | var $this = $(this), |
158 | index, | 136 | index, |
159 | curSizeBlock, | 137 | curSizeBlock, |
160 | - $preSiblingBlock, | ||
161 | - $curSizeRow, | ||
162 | - numArray, | ||
163 | - i, | ||
164 | curGoodNum; | 138 | curGoodNum; |
165 | 139 | ||
166 | var $siblingBlock = $this.closest('.block-list').siblings(':first'); | 140 | var $siblingBlock = $this.closest('.block-list').siblings(':first'); |
@@ -168,24 +142,35 @@ $yohoPage.on('touchstart', '.color-list .block', function() { | @@ -168,24 +142,35 @@ $yohoPage.on('touchstart', '.color-list .block', function() { | ||
168 | $this.siblings('.chosed').removeClass('chosed'); | 142 | $this.siblings('.chosed').removeClass('chosed'); |
169 | index = $this.index(); | 143 | index = $this.index(); |
170 | 144 | ||
171 | - $preSiblingBlock = $siblingBlock.find('.chosed'); | ||
172 | - $curSizeRow = $sizeRowList.eq(index); | ||
173 | - | ||
174 | // 当前颜色已经是选中状态,再点击时 | 145 | // 当前颜色已经是选中状态,再点击时 |
175 | if ($this.hasClass('chosed')) { | 146 | if ($this.hasClass('chosed')) { |
176 | 147 | ||
177 | - //颜色原来已经是勾选时,要清空剩余件数的提示 | 148 | + //清空剩余件数的提示 |
178 | $allChoseItems.find('.num .left-num').html(''); | 149 | $allChoseItems.find('.num .left-num').html(''); |
179 | $leftNum.val(0); | 150 | $leftNum.val(0); |
180 | hasChooseColor = false; | 151 | hasChooseColor = false; |
181 | 152 | ||
182 | - $this.removeClass('zero-stock'); | ||
183 | - if ($curSizeBlock) { | ||
184 | - numArray = ($curSizeBlock.data('numstr') + '').split('/'); | ||
185 | - for (i = 0; i < numArray.length; i++) { | ||
186 | - if ('0' === numArray[i]) { | ||
187 | - $('.color-list .block').eq(i).addClass('zero-stock'); | ||
188 | - } | 153 | + //if (!hasChooseSize) { |
154 | + | ||
155 | + //当前尺码行隐藏 | ||
156 | + $sizeRowList.eq(curSizeIndex).removeClass('show').addClass('hide'); | ||
157 | + | ||
158 | + //目标尺码行显示 | ||
159 | + $sizeRowList.eq(0).removeClass('hide').addClass('show'); | ||
160 | + | ||
161 | + curSizeIndex = 0; | ||
162 | + //} | ||
163 | + | ||
164 | + //如果尺码已经是选择状态 | ||
165 | + if (curColorIndex) { | ||
166 | + | ||
167 | + // 之前选中的尺码去掉勾选样式,新尺码块勾选 | ||
168 | + if ($curSizeBlock && $curSizeBlock.length > 0) { | ||
169 | + $curSizeBlock.removeClass('chosed'); | ||
170 | + curSizeBlock = $sizeRowList.eq(0).children().get(curColorIndex - 1); | ||
171 | + $curSizeBlock = $(curSizeBlock); | ||
172 | + curGoodNum = $curSizeBlock.data('num'); | ||
173 | + $curSizeBlock.addClass('chosed'); | ||
189 | } | 174 | } |
190 | } | 175 | } |
191 | 176 | ||
@@ -193,23 +178,20 @@ $yohoPage.on('touchstart', '.color-list .block', function() { | @@ -193,23 +178,20 @@ $yohoPage.on('touchstart', '.color-list .block', function() { | ||
193 | } else { | 178 | } else { |
194 | hasChooseColor = true; | 179 | hasChooseColor = true; |
195 | 180 | ||
196 | - //把当前选中颜色对应的尺码那一行显示出来 | ||
197 | - $sizeRowList.addClass('hide'); | ||
198 | - $curSizeRow.removeClass('hide').addClass('show'); | ||
199 | - | ||
200 | - // 之前选中的尺码去掉勾选样式 | ||
201 | - if ($preSiblingBlock.length > 0) { | ||
202 | - $preSiblingBlock.removeClass('chosed'); | ||
203 | - curSizeBlock = $curSizeRow.children().get(curSizeIndex); | ||
204 | - $curSizeBlock = $(curSizeBlock); | ||
205 | - } | ||
206 | - | ||
207 | - // 当前选中颜色对应的尺码行,其对应的尺码加上勾选样式 (前提是要判断下这个尺码是否存在) | ||
208 | - if (curSizeBlock) { | ||
209 | - curGoodNum = $(curSizeBlock).data('num'); | ||
210 | - $(curSizeBlock).addClass('chosed'); | 181 | + //如果尺码已经是选择状态 |
182 | + if (curColorIndex) { | ||
183 | + | ||
184 | + // 之前选中的尺码去掉勾选样式,新尺码块勾选 | ||
185 | + if ($curSizeBlock && $curSizeBlock.length > 0) { | ||
186 | + $curSizeBlock.removeClass('chosed'); | ||
187 | + //curSizeBlock = $sizeRowList.eq(curSizeIndex + 1).children().get(curColorIndex - 1); | ||
188 | + curSizeBlock = $sizeRowList.eq(index + 1).children().get(curColorIndex - 1); | ||
189 | + $curSizeBlock = $(curSizeBlock); | ||
190 | + curGoodNum = $curSizeBlock.data('num'); | ||
191 | + $curSizeBlock.addClass('chosed'); | ||
192 | + } | ||
211 | 193 | ||
212 | - //如果当前有尺码被选中,且数量等于0,则颜色块添加数量为0的样式 | 194 | + //数量大于0 |
213 | if (curGoodNum > 0) { | 195 | if (curGoodNum > 0) { |
214 | if ($soonSoldOut.length > 0) { | 196 | if ($soonSoldOut.length > 0) { |
215 | $allChoseItems.find('.num .left-num').html('即将售罄'); | 197 | $allChoseItems.find('.num .left-num').html('即将售罄'); |
@@ -218,81 +200,123 @@ $yohoPage.on('touchstart', '.color-list .block', function() { | @@ -218,81 +200,123 @@ $yohoPage.on('touchstart', '.color-list .block', function() { | ||
218 | } | 200 | } |
219 | 201 | ||
220 | $leftNum.val(curGoodNum); | 202 | $leftNum.val(curGoodNum); |
203 | + | ||
204 | + //数量小于0 | ||
221 | } else { | 205 | } else { |
222 | $allChoseItems.find('.num .left-num').html(''); | 206 | $allChoseItems.find('.num .left-num').html(''); |
223 | $leftNum.val(0); | 207 | $leftNum.val(0); |
224 | } | 208 | } |
225 | } | 209 | } |
210 | + | ||
211 | + // 尺码行当前行隐藏 | ||
212 | + $sizeRowList.eq(curSizeIndex).removeClass('show').addClass('hide'); | ||
213 | + | ||
214 | + //尺码对应行显示 | ||
215 | + $sizeRowList.eq(index + 1).removeClass('hide').addClass('show'); | ||
216 | + | ||
217 | + curSizeIndex = index + 1; | ||
218 | + $curColorBlock = $this; | ||
219 | + | ||
220 | + // 修改颜色时修改商品图片 | ||
221 | + $imgsThumb.addClass('hide').eq(index).removeClass('hide'); | ||
226 | } | 222 | } |
227 | 223 | ||
228 | // 当前颜色块 切换勾选样式 | 224 | // 当前颜色块 切换勾选样式 |
229 | $this.toggleClass('chosed'); | 225 | $this.toggleClass('chosed'); |
230 | - curColorIndex = index; | ||
231 | $('#good-num').val(1); | 226 | $('#good-num').val(1); |
232 | 227 | ||
233 | - // 修改颜色时修改商品图片 | ||
234 | - changeGoodImgWhenClickColor(); | ||
235 | - | ||
236 | // 设置按钮的样式和文字 | 228 | // 设置按钮的样式和文字 |
237 | updateConformButtonClassAndText(); | 229 | updateConformButtonClassAndText(); |
238 | }).on('touchstart', '.size-list .block', function() { | 230 | }).on('touchstart', '.size-list .block', function() { |
239 | var $this = $(this), | 231 | var $this = $(this), |
240 | index, | 232 | index, |
241 | - $curSizeRow, | 233 | + curColorBlock, |
242 | curGoodNum; | 234 | curGoodNum; |
243 | 235 | ||
244 | var $siblingBlock = $this.closest('.block-list').siblings(':first'); | 236 | var $siblingBlock = $this.closest('.block-list').siblings(':first'); |
245 | 237 | ||
246 | $this.siblings('.chosed').removeClass('chosed'); | 238 | $this.siblings('.chosed').removeClass('chosed'); |
247 | index = $this.index(); | 239 | index = $this.index(); |
248 | - $curSizeRow = $sizeRowList.eq(index); | ||
249 | 240 | ||
250 | // 当前尺码已经是选中状态,再点击时 | 241 | // 当前尺码已经是选中状态,再点击时 |
251 | if ($this.hasClass('chosed')) { | 242 | if ($this.hasClass('chosed')) { |
252 | 243 | ||
253 | - //尺码原来已经是勾选时,要清空剩余件数的提示 | 244 | + //清空剩余件数的提示 |
254 | $allChoseItems.find('.num .left-num').html(''); | 245 | $allChoseItems.find('.num .left-num').html(''); |
255 | - $('#left-num').val(0); | 246 | + $leftNum.val(0); |
256 | hasChooseSize = false; | 247 | hasChooseSize = false; |
257 | - curSizeIndex = null; | ||
258 | - $curSizeBlock = null; | 248 | + |
249 | + //if (!hasChooseColor) { | ||
250 | + | ||
251 | + //当前颜色行隐藏 | ||
252 | + $colorRowList.eq(curColorIndex).removeClass('show').addClass('hide'); | ||
253 | + | ||
254 | + //目标颜色行显示 | ||
255 | + $colorRowList.eq(0).removeClass('hide').addClass('show'); | ||
256 | + | ||
257 | + curColorIndex = 0; | ||
258 | + //} | ||
259 | + | ||
260 | + //如果颜色已经是选择状态 | ||
261 | + if (curSizeIndex) { | ||
262 | + | ||
263 | + // 之前选中的颜色去掉勾选样式,新颜色块勾选 | ||
264 | + if ($curColorBlock && $curColorBlock.length > 0) { | ||
265 | + $curColorBlock.removeClass('chosed'); | ||
266 | + curColorBlock = $colorRowList.eq(0).children().get(curSizeIndex - 1); | ||
267 | + $curColorBlock = $(curColorBlock); | ||
268 | + curGoodNum = $curColorBlock.data('num'); | ||
269 | + $curColorBlock.addClass('chosed'); | ||
270 | + } | ||
271 | + } | ||
259 | 272 | ||
260 | // 当前尺码不是选中状态,选中时 | 273 | // 当前尺码不是选中状态,选中时 |
261 | } else { | 274 | } else { |
262 | hasChooseSize = true; | 275 | hasChooseSize = true; |
263 | - curGoodNum = $this.data('num'); | ||
264 | 276 | ||
265 | - // 之前选中的尺码去掉勾选样式 | ||
266 | - if ($curSizeBlock) { | ||
267 | - $curSizeBlock.removeClass('chosed'); | ||
268 | - } | 277 | + //如果颜色已经是选择状态 |
278 | + if (curSizeIndex) { | ||
279 | + | ||
280 | + // 之前选中的颜色去掉勾选样式,新颜色块勾选 | ||
281 | + if ($curColorBlock && $curColorBlock.length > 0) { | ||
282 | + $curColorBlock.removeClass('chosed'); | ||
283 | + //curColorBlock = $colorRowList.eq(curColorIndex + 1).children().get(curSizeIndex - 1); | ||
284 | + curColorBlock = $colorRowList.eq(index + 1).children().get(curSizeIndex - 1); | ||
285 | + $curColorBlock = $(curColorBlock); | ||
286 | + curGoodNum = $curColorBlock.data('num'); | ||
287 | + $curColorBlock.addClass('chosed'); | ||
288 | + } | ||
269 | 289 | ||
270 | - // 如果当前有尺码被选中,且数量等于0, 否则显示剩余件数 | ||
271 | - if (curGoodNum > 0 && hasChooseColor) { | ||
272 | - if ($soonSoldOut.length > 0) { | ||
273 | - $allChoseItems.find('.num .left-num').html('即将售罄'); | 290 | + //数量大于0 |
291 | + if (curGoodNum > 0) { | ||
292 | + if ($soonSoldOut.length > 0) { | ||
293 | + $allChoseItems.find('.num .left-num').html('即将售罄'); | ||
294 | + } else { | ||
295 | + $allChoseItems.find('.num .left-num').html('剩余' + curGoodNum + '件'); | ||
296 | + } | ||
297 | + | ||
298 | + $leftNum.val(curGoodNum); | ||
299 | + | ||
300 | + //数量小于0 | ||
274 | } else { | 301 | } else { |
275 | - $allChoseItems.find('.num .left-num').html('剩余' + curGoodNum + '件'); | 302 | + $allChoseItems.find('.num .left-num').html(''); |
303 | + $leftNum.val(0); | ||
276 | } | 304 | } |
277 | - $('#left-num').val(curGoodNum); | ||
278 | - } else { | ||
279 | - $allChoseItems.find('.num .left-num').html(''); | ||
280 | - $('#left-num').val(0); | ||
281 | } | 305 | } |
282 | 306 | ||
283 | - if (curGoodNum === 0 && hasChooseColor) { | ||
284 | - $this.addClass('zero-stock'); | ||
285 | - } | ||
286 | - curSizeIndex = index; | 307 | + // 颜色当前行隐藏 |
308 | + $colorRowList.eq(curColorIndex).removeClass('show').addClass('hide'); | ||
309 | + | ||
310 | + //颜色对应行显示 | ||
311 | + $colorRowList.eq(index + 1).removeClass('hide').addClass('show'); | ||
312 | + | ||
313 | + curColorIndex = index + 1; | ||
287 | $curSizeBlock = $this; | 314 | $curSizeBlock = $this; |
288 | } | 315 | } |
289 | 316 | ||
290 | $this.toggleClass('chosed'); | 317 | $this.toggleClass('chosed'); |
291 | $('#good-num').val(1); | 318 | $('#good-num').val(1); |
292 | 319 | ||
293 | - // 重置颜色块的样式 | ||
294 | - resetColorZeroStock($siblingBlock); | ||
295 | - | ||
296 | // 设置按钮的样式和文字 | 320 | // 设置按钮的样式和文字 |
297 | updateConformButtonClassAndText(); | 321 | updateConformButtonClassAndText(); |
298 | }); | 322 | }); |
-
Please register or login to post a comment