|
@@ -34,6 +34,11 @@ var $chosePanel = $('#chose-panel'), |
|
@@ -34,6 +34,11 @@ var $chosePanel = $('#chose-panel'), |
34
|
$soonSoldOut = $('.soonSoldOut-tag'),
|
34
|
$soonSoldOut = $('.soonSoldOut-tag'),
|
35
|
$yohoPage = $('.yoho-page');
|
35
|
$yohoPage = $('.yoho-page');
|
36
|
|
36
|
|
|
|
37
|
+//购物车编辑标相关变量
|
|
|
38
|
+var isEdit,
|
|
|
39
|
+ isSelected,
|
|
|
40
|
+ oldSknId;
|
|
|
41
|
+
|
37
|
//初始化购物车面板显示
|
42
|
//初始化购物车面板显示
|
38
|
function init() {
|
43
|
function init() {
|
39
|
hasChooseColor = false;
|
44
|
hasChooseColor = false;
|
|
@@ -47,6 +52,37 @@ function init() { |
|
@@ -47,6 +52,37 @@ function init() { |
47
|
$leftNum = $('#left-num');
|
52
|
$leftNum = $('#left-num');
|
48
|
curColorIndex = 0;
|
53
|
curColorIndex = 0;
|
49
|
curSizeIndex = 0;
|
54
|
curSizeIndex = 0;
|
|
|
55
|
+ isEdit = 0;
|
|
|
56
|
+}
|
|
|
57
|
+
|
|
|
58
|
+/*
|
|
|
59
|
+ * 设置当前面板为编辑模式
|
|
|
60
|
+ *
|
|
|
61
|
+ * @param {String} sknId. 当前编辑商品的sknId
|
|
|
62
|
+ *
|
|
|
63
|
+ * @param {Bool} isThisGoodSelected. 当前编辑商品的在购物车中是否被选中
|
|
|
64
|
+ *
|
|
|
65
|
+ * @return {undefined}
|
|
|
66
|
+ */
|
|
|
67
|
+function setEditModeWithSknId(sknId, isThisGoodSelected) {
|
|
|
68
|
+ $('#chose-btn-sure').html('确认');
|
|
|
69
|
+ isEdit = 1;
|
|
|
70
|
+ oldSknId = sknId;
|
|
|
71
|
+ isSelected = isThisGoodSelected;
|
|
|
72
|
+}
|
|
|
73
|
+
|
|
|
74
|
+//删除面板
|
|
|
75
|
+function removePannel() {
|
|
|
76
|
+ var $pannel = $('.chose-panel'),
|
|
|
77
|
+ $promotionId = $('#promotionId');
|
|
|
78
|
+
|
|
|
79
|
+ if ($pannel) {
|
|
|
80
|
+ $pannel.remove();
|
|
|
81
|
+ }
|
|
|
82
|
+
|
|
|
83
|
+ if ($promotionId) {
|
|
|
84
|
+ $promotionId.remove();
|
|
|
85
|
+ }
|
50
|
}
|
86
|
}
|
51
|
|
87
|
|
52
|
function checkColorSizeNum() {
|
88
|
function checkColorSizeNum() {
|
|
@@ -108,7 +144,7 @@ function updateConformButtonClassAndText() { |
|
@@ -108,7 +144,7 @@ function updateConformButtonClassAndText() { |
108
|
if (2 === $chosed.closest('.zero-stock').length) {
|
144
|
if (2 === $chosed.closest('.zero-stock').length) {
|
109
|
$('#chose-btn-sure').css('background-color', '#c0c0c0').html('已售罄');
|
145
|
$('#chose-btn-sure').css('background-color', '#c0c0c0').html('已售罄');
|
110
|
} else {
|
146
|
} else {
|
111
|
- $('#chose-btn-sure').css('background-color', '#eb0313').html('加入购物车');
|
147
|
+ $('#chose-btn-sure').css('background-color', '#eb0313').html(isEdit ? '确认' : '加入购物车');
|
112
|
}
|
148
|
}
|
113
|
}
|
149
|
}
|
114
|
|
150
|
|
|
@@ -355,7 +391,8 @@ $yohoPage.on('touchstart', '.btn-minus', function() { |
|
@@ -355,7 +391,8 @@ $yohoPage.on('touchstart', '.btn-minus', function() { |
355
|
buyNumber = $('#good-num').val() - 0,
|
391
|
buyNumber = $('#good-num').val() - 0,
|
356
|
|
392
|
|
357
|
promotionId,
|
393
|
promotionId,
|
358
|
- isEdit = 0,
|
394
|
+ cartGoodData,
|
|
|
395
|
+ url,
|
359
|
num = parseInt($num.val(), 10);
|
396
|
num = parseInt($num.val(), 10);
|
360
|
|
397
|
|
361
|
//颜色尺码没有选择
|
398
|
//颜色尺码没有选择
|
|
@@ -389,21 +426,39 @@ $yohoPage.on('touchstart', '.btn-minus', function() { |
|
@@ -389,21 +426,39 @@ $yohoPage.on('touchstart', '.btn-minus', function() { |
389
|
|
426
|
|
390
|
confirming = true;
|
427
|
confirming = true;
|
391
|
loading.showLoadingMask();
|
428
|
loading.showLoadingMask();
|
392
|
- $.ajax({
|
|
|
393
|
- method: 'POST',
|
|
|
394
|
- url: '/cart/index/add',
|
|
|
395
|
- data: {
|
429
|
+
|
|
|
430
|
+ //针对是否处于编辑模式设置不同的url和需要post的数据
|
|
|
431
|
+ if (isEdit) {
|
|
|
432
|
+ cartGoodData = {
|
|
|
433
|
+ new_product_sku: productSku,
|
|
|
434
|
+ old_product_sku: oldSknId,
|
|
|
435
|
+ buy_number: buyNumber,
|
|
|
436
|
+ selected: isSelected
|
|
|
437
|
+ };
|
|
|
438
|
+
|
|
|
439
|
+ url = '/cart/index/modify';
|
|
|
440
|
+
|
|
|
441
|
+ } else {
|
|
|
442
|
+ cartGoodData = {
|
396
|
productSku: productSku,
|
443
|
productSku: productSku,
|
397
|
buyNumber: buyNumber,
|
444
|
buyNumber: buyNumber,
|
398
|
promotionId: promotionId,
|
445
|
promotionId: promotionId,
|
399
|
isEdit: isEdit,
|
446
|
isEdit: isEdit,
|
400
|
cartType: queryString.cartType
|
447
|
cartType: queryString.cartType
|
|
|
448
|
+ };
|
|
|
449
|
+
|
|
|
450
|
+ url = '/cart/index/add';
|
401
|
}
|
451
|
}
|
|
|
452
|
+
|
|
|
453
|
+ $.ajax({
|
|
|
454
|
+ method: 'POST',
|
|
|
455
|
+ url: url,
|
|
|
456
|
+ data: cartGoodData
|
402
|
}).done(function(res) {
|
457
|
}).done(function(res) {
|
403
|
var cartNum;
|
458
|
var cartNum;
|
404
|
|
459
|
|
405
|
loading.hideLoadingMask();
|
460
|
loading.hideLoadingMask();
|
406
|
- if (res.code === 200) {
|
461
|
+ if (res.code === 200 && !isEdit) {
|
407
|
cartNum = res.data.goods_count;
|
462
|
cartNum = res.data.goods_count;
|
408
|
if (cartNum > 99) {
|
463
|
if (cartNum > 99) {
|
409
|
cartNum = '99+';
|
464
|
cartNum = '99+';
|
|
@@ -415,11 +470,20 @@ $yohoPage.on('touchstart', '.btn-minus', function() { |
|
@@ -415,11 +470,20 @@ $yohoPage.on('touchstart', '.btn-minus', function() { |
415
|
cbFn();
|
470
|
cbFn();
|
416
|
}
|
471
|
}
|
417
|
}
|
472
|
}
|
418
|
- if (res.message) {
|
473
|
+ if (res.message && !isEdit) {
|
419
|
tip.show(res.message);
|
474
|
tip.show(res.message);
|
420
|
}
|
475
|
}
|
421
|
|
476
|
|
422
|
hide();
|
477
|
hide();
|
|
|
478
|
+
|
|
|
479
|
+ if (isEdit) {
|
|
|
480
|
+ loading.showLoadingMask();
|
|
|
481
|
+
|
|
|
482
|
+ //延迟刷新,否则面板可能无法隐藏
|
|
|
483
|
+ setTimeout(function() {
|
|
|
484
|
+ window.location.reload();
|
|
|
485
|
+ }, 1);
|
|
|
486
|
+ }
|
423
|
}).fail(function() {
|
487
|
}).fail(function() {
|
424
|
tip.show('网络出了点问题~');
|
488
|
tip.show('网络出了点问题~');
|
425
|
}).always(function() {
|
489
|
}).always(function() {
|
|
@@ -431,3 +495,6 @@ $yohoPage.on('touchstart', '.btn-minus', function() { |
|
@@ -431,3 +495,6 @@ $yohoPage.on('touchstart', '.btn-minus', function() { |
431
|
|
495
|
|
432
|
exports.init = init;
|
496
|
exports.init = init;
|
433
|
exports.show = show;
|
497
|
exports.show = show;
|
|
|
498
|
+exports.remove = removePannel;
|
|
|
499
|
+exports.setEditModeWithSknId = setEditModeWithSknId;
|
|
|
500
|
+ |