|
@@ -18,9 +18,9 @@ var panelTmpl, |
|
@@ -18,9 +18,9 @@ var panelTmpl, |
18
|
$chosePanel = $('#chose-panel'),
|
18
|
$chosePanel = $('#chose-panel'),
|
19
|
$num,
|
19
|
$num,
|
20
|
$chosed,
|
20
|
$chosed,
|
21
|
- re = /\d+/,
|
21
|
+
|
|
|
22
|
+ // re = /\d+/,
|
22
|
leftNum,
|
23
|
leftNum,
|
23
|
- $sizeList,
|
|
|
24
|
confirming,
|
24
|
confirming,
|
25
|
hasChooseColor = false,
|
25
|
hasChooseColor = false,
|
26
|
hasChooseSize = false,
|
26
|
hasChooseSize = false,
|
|
@@ -61,6 +61,20 @@ function init() { |
|
@@ -61,6 +61,20 @@ function init() { |
61
|
$curSizeRow = $firstRow;
|
61
|
$curSizeRow = $firstRow;
|
62
|
}
|
62
|
}
|
63
|
|
63
|
|
|
|
64
|
+function checkColorSizeNum() {
|
|
|
65
|
+ if (!hasChooseColor && !hasChooseSize) {
|
|
|
66
|
+ tip.show('请选择颜色和尺码~');
|
|
|
67
|
+ return false;
|
|
|
68
|
+ } else if (!hasChooseColor) {
|
|
|
69
|
+ tip.show('请选择颜色~');
|
|
|
70
|
+ return false;
|
|
|
71
|
+ } else if (!hasChooseSize) {
|
|
|
72
|
+ tip.show('请选择尺码~');
|
|
|
73
|
+ return false;
|
|
|
74
|
+ }
|
|
|
75
|
+ return true;
|
|
|
76
|
+}
|
|
|
77
|
+
|
64
|
init();
|
78
|
init();
|
65
|
|
79
|
|
66
|
function show(data) {
|
80
|
function show(data) {
|
|
@@ -118,6 +132,7 @@ $('.color-list').on('touchstart', '.block', function(e) { |
|
@@ -118,6 +132,7 @@ $('.color-list').on('touchstart', '.block', function(e) { |
118
|
|
132
|
|
119
|
//颜色原来已经是勾选时,要清空剩余件数的提示
|
133
|
//颜色原来已经是勾选时,要清空剩余件数的提示
|
120
|
$that.find('.num .left-num').html('');
|
134
|
$that.find('.num .left-num').html('');
|
|
|
135
|
+ $('#left-num').val(0);
|
121
|
hasChooseColor = false;
|
136
|
hasChooseColor = false;
|
122
|
|
137
|
|
123
|
// 当前颜色不是选中状态,选中时
|
138
|
// 当前颜色不是选中状态,选中时
|
|
@@ -131,15 +146,15 @@ $('.color-list').on('touchstart', '.block', function(e) { |
|
@@ -131,15 +146,15 @@ $('.color-list').on('touchstart', '.block', function(e) { |
131
|
|
146
|
|
132
|
//把当前选中颜色对应的尺码那一行显示出来
|
147
|
//把当前选中颜色对应的尺码那一行显示出来
|
133
|
$sizeRowList.addClass('hide');
|
148
|
$sizeRowList.addClass('hide');
|
134
|
- $curSizeRow.toggleClass('hide');
|
149
|
+ $curSizeRow.removeClass('hide').addClass('show');
|
135
|
|
150
|
|
136
|
// 之前选中的尺码去掉勾选样式
|
151
|
// 之前选中的尺码去掉勾选样式
|
137
|
- if ($sizeChosed) {
|
152
|
+ if ($sizeChosed.length > 0) {
|
138
|
$sizeChosed.removeClass('chosed');
|
153
|
$sizeChosed.removeClass('chosed');
|
|
|
154
|
+ curSelectedSizeBlock = $curSizeRow.children().get(scindex);
|
139
|
}
|
155
|
}
|
140
|
|
156
|
|
141
|
// 当前选中颜色对应的尺码行,其对应的尺码加上勾选样式 (前提是要判断下这个尺码是否存在)
|
157
|
// 当前选中颜色对应的尺码行,其对应的尺码加上勾选样式 (前提是要判断下这个尺码是否存在)
|
142
|
- curSelectedSizeBlock = $curSizeRow.children().get(scindex);
|
|
|
143
|
if (curSelectedSizeBlock) {
|
158
|
if (curSelectedSizeBlock) {
|
144
|
curGoodNum = $(curSelectedSizeBlock).data('num');
|
159
|
curGoodNum = $(curSelectedSizeBlock).data('num');
|
145
|
$(curSelectedSizeBlock).addClass('chosed');
|
160
|
$(curSelectedSizeBlock).addClass('chosed');
|
|
@@ -147,9 +162,11 @@ $('.color-list').on('touchstart', '.block', function(e) { |
|
@@ -147,9 +162,11 @@ $('.color-list').on('touchstart', '.block', function(e) { |
147
|
//如果当前有尺码被选中,且数量等于0,则颜色块添加数量为0的样式
|
162
|
//如果当前有尺码被选中,且数量等于0,则颜色块添加数量为0的样式
|
148
|
if (curGoodNum > 0) {
|
163
|
if (curGoodNum > 0) {
|
149
|
$that.find('.num .left-num').html('剩余' + curGoodNum + '件');
|
164
|
$that.find('.num .left-num').html('剩余' + curGoodNum + '件');
|
|
|
165
|
+ $('#left-num').val(curGoodNum);
|
150
|
} else {
|
166
|
} else {
|
151
|
$(curSelectedSizeBlock).removeClass('zero-stock').addClass('zero-stock');
|
167
|
$(curSelectedSizeBlock).removeClass('zero-stock').addClass('zero-stock');
|
152
|
$that.find('.num .left-num').html('');
|
168
|
$that.find('.num .left-num').html('');
|
|
|
169
|
+ $('#left-num').val(0);
|
153
|
}
|
170
|
}
|
154
|
}
|
171
|
}
|
155
|
}
|
172
|
}
|
|
@@ -236,7 +253,6 @@ $('.size-list').on('touchstart', '.block', function(e) { |
|
@@ -236,7 +253,6 @@ $('.size-list').on('touchstart', '.block', function(e) { |
236
|
$that = $(e.target).closest('.chose-items'),
|
253
|
$that = $(e.target).closest('.chose-items'),
|
237
|
index,
|
254
|
index,
|
238
|
$colorChosed,
|
255
|
$colorChosed,
|
239
|
- selectedColorindex,
|
|
|
240
|
curGoodNum;
|
256
|
curGoodNum;
|
241
|
|
257
|
|
242
|
var $siblingBlock = $this.closest('.block-list').siblings(':first');
|
258
|
var $siblingBlock = $this.closest('.block-list').siblings(':first');
|
|
@@ -245,7 +261,6 @@ $('.size-list').on('touchstart', '.block', function(e) { |
|
@@ -245,7 +261,6 @@ $('.size-list').on('touchstart', '.block', function(e) { |
245
|
index = $this.index();
|
261
|
index = $this.index();
|
246
|
|
262
|
|
247
|
$colorChosed = $siblingBlock.find('.chosed');
|
263
|
$colorChosed = $siblingBlock.find('.chosed');
|
248
|
- selectedColorindex = $colorChosed.index();
|
|
|
249
|
$curSizeRow = $sizeRowList.eq(index);
|
264
|
$curSizeRow = $sizeRowList.eq(index);
|
250
|
|
265
|
|
251
|
// 当前尺码已经是选中状态,再点击时
|
266
|
// 当前尺码已经是选中状态,再点击时
|
|
@@ -253,10 +268,11 @@ $('.size-list').on('touchstart', '.block', function(e) { |
|
@@ -253,10 +268,11 @@ $('.size-list').on('touchstart', '.block', function(e) { |
253
|
|
268
|
|
254
|
//尺码原来已经是勾选时,要清空剩余件数的提示
|
269
|
//尺码原来已经是勾选时,要清空剩余件数的提示
|
255
|
$that.find('.num .left-num').html('');
|
270
|
$that.find('.num .left-num').html('');
|
|
|
271
|
+ $('#left-num').val(0);
|
256
|
hasChooseSize = false;
|
272
|
hasChooseSize = false;
|
257
|
|
273
|
|
258
|
// 去掉已经选中颜色的 数量为0的样式
|
274
|
// 去掉已经选中颜色的 数量为0的样式
|
259
|
- if ($colorChosed) {
|
275
|
+ if ($colorChosed.length > 0) {
|
260
|
$colorChosed.removeClass('zero-stock').addClass('zero-stock');
|
276
|
$colorChosed.removeClass('zero-stock').addClass('zero-stock');
|
261
|
}
|
277
|
}
|
262
|
|
278
|
|
|
@@ -272,11 +288,13 @@ $('.size-list').on('touchstart', '.block', function(e) { |
|
@@ -272,11 +288,13 @@ $('.size-list').on('touchstart', '.block', function(e) { |
272
|
}
|
288
|
}
|
273
|
|
289
|
|
274
|
// 如果当前有尺码被选中,且数量等于0,则颜色块添加数量为0的样式, 否则显示剩余件数
|
290
|
// 如果当前有尺码被选中,且数量等于0,则颜色块添加数量为0的样式, 否则显示剩余件数
|
275
|
- if (curGoodNum > 0) {
|
291
|
+ if (curGoodNum > 0 && hasChooseColor) {
|
276
|
$that.find('.num .left-num').html('剩余' + curGoodNum + '件');
|
292
|
$that.find('.num .left-num').html('剩余' + curGoodNum + '件');
|
|
|
293
|
+ $('#left-num').val(curGoodNum);
|
277
|
} else {
|
294
|
} else {
|
278
|
$colorChosed.removeClass('zero-stock').addClass('zero-stock');
|
295
|
$colorChosed.removeClass('zero-stock').addClass('zero-stock');
|
279
|
$that.find('.num .left-num').html('');
|
296
|
$that.find('.num .left-num').html('');
|
|
|
297
|
+ $('#left-num').val(0);
|
280
|
}
|
298
|
}
|
281
|
}
|
299
|
}
|
282
|
|
300
|
|
|
@@ -361,12 +379,11 @@ $('.size-list').on('touchstart', '.block', function(e) { |
|
@@ -361,12 +379,11 @@ $('.size-list').on('touchstart', '.block', function(e) { |
361
|
});
|
379
|
});
|
362
|
|
380
|
|
363
|
$('.btn-minus').on('touchstart', function() {
|
381
|
$('.btn-minus').on('touchstart', function() {
|
364
|
- var num = $num.val(),
|
|
|
365
|
- $chosed = $('.block-list>ul>li.chosed'),
|
|
|
366
|
- leftNum = re.exec($('.num .left-num').html());
|
382
|
+ var num = $num.val();
|
|
|
383
|
+
|
|
|
384
|
+ leftNum = $('#left-num').val();
|
367
|
|
385
|
|
368
|
- //若颜色和尺码没有被同时选中,则不能点击
|
|
|
369
|
- if ($chosed.length < 2) {
|
386
|
+ if (!checkColorSizeNum()) {
|
370
|
return;
|
387
|
return;
|
371
|
}
|
388
|
}
|
372
|
|
389
|
|
|
@@ -380,13 +397,14 @@ $('.btn-minus').on('touchstart', function() { |
|
@@ -380,13 +397,14 @@ $('.btn-minus').on('touchstart', function() { |
380
|
$('.btn-plus').on('touchstart', function() {
|
397
|
$('.btn-plus').on('touchstart', function() {
|
381
|
var num = $num.val();
|
398
|
var num = $num.val();
|
382
|
|
399
|
|
383
|
- //若颜色和尺码没有被同时选中,则不能点击
|
|
|
384
|
- if ($('.block-list>ul>li.chosed').length < 2) {
|
|
|
385
|
- tip.show('请选择颜色和尺码~');
|
400
|
+ leftNum = $('#left-num').val();
|
|
|
401
|
+
|
|
|
402
|
+ if (!checkColorSizeNum()) {
|
386
|
return;
|
403
|
return;
|
387
|
}
|
404
|
}
|
388
|
- leftNum = re.exec($('.num .left-num').html());
|
|
|
389
|
- if (num - 0 === leftNum - 0 || 0 === leftNum - 0) {
|
405
|
+
|
|
|
406
|
+
|
|
|
407
|
+ if (num - 0 === leftNum || 0 === leftNum) {
|
390
|
return;
|
408
|
return;
|
391
|
}
|
409
|
}
|
392
|
|
410
|
|
|
@@ -394,22 +412,35 @@ $('.btn-plus').on('touchstart', function() { |
|
@@ -394,22 +412,35 @@ $('.btn-plus').on('touchstart', function() { |
394
|
$num.val(num + 1);
|
412
|
$num.val(num + 1);
|
395
|
});
|
413
|
});
|
396
|
|
414
|
|
397
|
-$('#chose-btn-sure').on('touchend', function() {
|
415
|
+$('#chose-btn-sure').on('touchstart', function() {
|
398
|
|
416
|
|
399
|
var productSku,
|
417
|
var productSku,
|
400
|
buyNumber = $('#good-num').val() - 0,
|
418
|
buyNumber = $('#good-num').val() - 0,
|
401
|
|
419
|
|
402
|
promotionId,
|
420
|
promotionId,
|
403
|
isEdit = 0,
|
421
|
isEdit = 0,
|
404
|
- numInCart = $('.num-tag').html() - 0;
|
422
|
+ numInCart = $('.num-tag').html() - 0,
|
|
|
423
|
+ num = $num.val();
|
|
|
424
|
+
|
|
|
425
|
+ if (!checkColorSizeNum()) {
|
|
|
426
|
+ return;
|
|
|
427
|
+ }
|
405
|
|
428
|
|
406
|
- // goodsType,
|
|
|
407
|
- // isEdit;
|
429
|
+ if ($('#chose-btn-sure').html() === '已售罄') {
|
|
|
430
|
+ return;
|
|
|
431
|
+ }
|
|
|
432
|
+
|
|
|
433
|
+ leftNum = $('#left-num').val();
|
|
|
434
|
+
|
|
|
435
|
+ if (num > leftNum) {
|
|
|
436
|
+ tip.show('您选择的数量超过了最大库存量~');
|
|
|
437
|
+ return;
|
|
|
438
|
+ }
|
408
|
|
439
|
|
409
|
$chosed = $('.block-list>ul>li.chosed');
|
440
|
$chosed = $('.block-list>ul>li.chosed');
|
410
|
|
441
|
|
411
|
if (2 === $chosed.length && 0 === $chosed.closest('.zero-stock').length) {
|
442
|
if (2 === $chosed.length && 0 === $chosed.closest('.zero-stock').length) {
|
412
|
- productSku = $sizeList.closest('.chosed').data('skuid');
|
443
|
+ productSku = $curSizeBlock.data('skuid');
|
413
|
promotionId = $('[data-id="' + productSku + '"]').closest('.advance-block').data('promotion-id');
|
444
|
promotionId = $('[data-id="' + productSku + '"]').closest('.advance-block').data('promotion-id');
|
414
|
if (confirming) {
|
445
|
if (confirming) {
|
415
|
return false;
|
446
|
return false;
|