chose-panel.js
23.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
/**
* 购物车选择尺寸、颜色和数量面板
* 显示时构造当前商品信息的HTML插入yoho-page;消失则是直接清除HTML
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/10/21
*/
// bikai
// 增加init函数,异步请求的接口需要重新初始化一下选择列表
// 异步渲染的模板统一插入 #chose-panel ,兼容页面多个选择框
let $ = require('yoho-jquery'),
tip = require('js/plugin/tip'),
loading = require('js/plugin/loading');
let innerScroll = require('js/plugin/inner-scroll');
let $chosePanel = $('#chose-panel'),
$num,
$chosed,
$imgsThumb,
$leftNum,
leftNum,
confirming,
curColorIndex,
curSizeIndex,
hasChooseColor,
hasChooseSize,
$curSizeBlock,
$sizeRowList,
$curColorBlock,
$colorRowList,
cbFn,
$allChoseItems,
queryString,
$choseArea,
$cartBar,
$soonSoldOut = $('.soon-sold-out-tag'),
$yohoPage = $('.yoho-page'),
// 门票 限购数量
ticketsLimit = $('#limitNum').val() || 0,
single = $('#single').val() || 0,
$productSku = $('#productSku'),
$buyNumber = $('#buyNumber'),
$buyNowForm = $('#buyNowForm');
// 购物车编辑标相关变量
let isEdit,
isSelected,
oldSknId,
isGift;
// 限购商品的商品码。只有限购商品时才会设置。
let limitProductCode,
// 限购商品的skn。只有限购商品时才会设置。
skn;
// 套餐模式
let budnleMode;
// 量贩商品
let discountNum = $('#mnum').val() - 0,
discountLimit = false;
let C_ID;
let $sizeInfo,
$thumbImg;
require('js/common');
C_ID = window._ChannelVary[window.cookie('_Channel')];
// 禁用数字编辑
function disableNumEdit() {
let $numBtn = $('.chose-panel').find('.num .btn>.iconfont');
// 添加disabled样式
$numBtn.hasClass('disabled') ? null : $numBtn.addClass('disabled');
$yohoPage.off('touchstart', '.btn-minus');
$yohoPage.off('touchstart', '.btn-plus');
}
// 初始化购物车面板显示
function init() {
discountNum = $('#mnum').val() - 0;
hasChooseColor = false;
hasChooseSize = false;
$curSizeBlock = null;
queryString = $.queryString();
$imgsThumb = $('.chose-panel').find('.thumb');
$choseArea = $('.chose-panel .main .chose-items');
$allChoseItems = $('.chose-items');
$sizeRowList = $('.size-list ul');
$colorRowList = $('.color-list ul');
$leftNum = $('#left-num');
$cartBar = $('.cart-bar');
curColorIndex = 0;
curSizeIndex = 0;
isEdit = 0;
$sizeInfo = $('.size-info');
$thumbImg = $('.thumb-img');
}
/*
* 设置当前面板为编辑模式
*
* @param {String} sknId. 当前编辑商品的sknId
*
* @param {Bool} isThisGoodSelected. 当前编辑商品的在购物车中是否被选中
*
* @param {Bool} gift. 是促销选择尺码
*
* @return {undefined}
*/
function setEditModeWithSknId(sknId, isThisGoodSelected, gift) {
$('#chose-btn-sure').html('确认');
isEdit = 1;
oldSknId = sknId;
isSelected = isThisGoodSelected;
isGift = gift;
}
/*
* 设置当前面板为限购商品模式
*
* @param {String} code 当前限购商品的商品码
*
* @param {String} sknId. 当前限购商品的sknId
*
* @return {undefined}
*/
function setLimitGoodModeWithSknId(code, sknId) {
disableNumEdit();
$('#chose-btn-sure').html('立即购买');
limitProductCode = code;
skn = sknId;
}
/*
* 设置当前面板为套餐商品选择模式
*
* @param {String} sknId. 当前限购商品的sknId
*
* @return {undefined}
*/
function setBundleModeWithSknId(sknId) {
disableNumEdit();
isEdit = 1;
skn = sknId;
$('#chose-btn-sure').html('确认');
budnleMode = true;
}
// 删除面板
function removePannel() {
let $pannel = $('.chose-panel'),
$promotionId = $('#promotionId');
if ($pannel) {
$pannel.remove();
}
if ($promotionId) {
$promotionId.remove();
}
}
// 检查门票选择
function checkTickets() {
if (!hasChooseColor && !hasChooseSize) {
if (single) {
tip.show('请选择日期~');
} else {
tip.show('请选择日期和区域~');
}
return false;
} else if (!hasChooseColor) {
tip.show('请选择日期~');
return false;
} else if (!hasChooseSize && !single) {
tip.show('请选择区域~');
return false;
}
return true;
}
function checkColorSizeNum() {
if (ticketsLimit) {
// 门票
if (!checkTickets()) {
return;
}
}
if (!hasChooseColor && !hasChooseSize) {
tip.show('请选择颜色和尺码~');
return false;
} else if (!hasChooseColor) {
tip.show('请选择颜色~');
return false;
} else if (!hasChooseSize) {
tip.show('请选择尺码~');
return false;
}
return true;
}
function show(html, cb) {
if (html) {
$chosePanel.html(html);
init();
}
if ($('#promotionId').val() !== '') {
disableNumEdit();
}
$('.chose-panel').show();
$num = $('#good-num');
cbFn = cb;
innerScroll.disableScroll($choseArea);
}
// 隐藏当前Panel
function hide() {
$('.chose-panel').hide();
innerScroll.enableScroll($choseArea);
if ($cartBar.length > 0) {
$cartBar.show();
}
}
// 修改加入购物车的文字和背景
let isSeckill = $('.limit-num-text').length;
let isSecKills = 0;
function updateConformButtonClassAndText() {
if (isSeckill > 0) {
$chosed = $allChoseItems.find('.chosed');
if ($chosed.closest('.zero-stock').length === 2) {
$('#chose-btn-sure').css('background-color', '#c0c0c0').html('已售罄');
} else if (limitProductCode || ticketsLimit) {
$('#chose-btn-sure').css('background-color', '#eb0313').html('立即购买');
} else {
$('#chose-btn-sure').css('background-color', '#eb0313').html(isEdit ? '确认' : '立即购买');
}
} else {
$chosed = $allChoseItems.find('.chosed');
discountLimit = discountNum && $chosed.length === 2 && $('#left-num').val() - 0 < discountNum;
if ($chosed.closest('.zero-stock').length === 2 || discountLimit) {
$('#chose-btn-sure').css('background-color', '#c0c0c0').html('已售罄');
} else if (limitProductCode || ticketsLimit) {
$('#chose-btn-sure').css('background-color', '#eb0313').html('立即购买');
} else if ($('.seckill-time').length >= 1) {
$('#chose-btn-sure').css('background-color', '#eb0313').html(isEdit ? '确认' : '立即购买');
} else {
$('#chose-btn-sure').css('background-color', '#eb0313').html(isEdit ? '确认' : '加入购物车');
}
}
}
// 显示剩余件数
function displayGoodNum(curGoodNum) {
// 门票限购
if (ticketsLimit) {
$allChoseItems.find('.num .left-num').html('限购' + ticketsLimit + '件');
$leftNum.val(curGoodNum);
return;
}
// 数量大于
if (curGoodNum > 0) {
$allChoseItems.find('.num .left-num').html('');
if ($soonSoldOut.length > 0) {
$allChoseItems.find('.num .left-num').html('即将售罄');
} else {
curGoodNum < 4 && $allChoseItems.find('.num .left-num').html('剩余' + curGoodNum + '件');
}
$leftNum.val(curGoodNum);
// 数量小于0
} else {
$allChoseItems.find('.num .left-num').html('');
$leftNum.val(0);
}
}
// 老的选中尺码去掉勾选,新的选中尺码加上勾选
function changeSizeChosed(newSizeIndex) {
let sizes,
sizeBlock,
i;
if (curColorIndex && $curSizeBlock && $curSizeBlock.length > 0) {
$curSizeBlock.removeClass('chosed');
sizes = $sizeRowList.eq(newSizeIndex).children();
for (i = 0; i < sizes.length; i++) {
if ($(sizes[i]).data('id') === $curSizeBlock.data('id')) {
$curSizeBlock = $(sizes[i]);
sizeBlock = '#' + $curSizeBlock.data('id');
curColorIndex = $(sizeBlock).data('index');
$curSizeBlock.addClass('chosed');
return $curSizeBlock.data('num');
}
}
// 特殊处理: 老的选中尺码在新选中的颜色对应尺码中不存在,需要下述1,2,3
// 1.重置尺码选择的标志变量.
$curSizeBlock = null;
hasChooseSize = false;
// 2.当前颜色行隐藏
$colorRowList.eq(curColorIndex).addClass('hide');
// 3.目标颜色行第一行显示
$colorRowList.eq(0).removeClass('hide');
curColorIndex = 0;
return -1;
}
return 0;
}
// 老的选中颜色去掉勾选,新的选中颜色加上勾选
function changeColorChosed(newColorIndex) {
if (curSizeIndex && $curColorBlock && $curColorBlock.length > 0) {
$curColorBlock.removeClass('chosed');
$curColorBlock = $($colorRowList.eq(newColorIndex).children().get(curSizeIndex - 1));
$curColorBlock.addClass('chosed');
return $curColorBlock.data('num');
}
return 0;
}
// 添加门票
function addTickets(productSku, buyNumber) {
let data = {
productSku: productSku,
buyNumber: buyNumber
};
// 校验电子票
$.ajax({
url: '/cart/index/checkTickets',
dataType: 'json',
data: data,
type: 'post',
success: function(addRestult) {
if (addRestult.code !== 200) {
if (addRestult.code === 401) {
window.location.href = '//m.yohobuy.com/signin.html?refer=' + window.location.href;
}
tip.show(addRestult.message);
} else {
$productSku.val(productSku);
$buyNumber.val(buyNumber);
$buyNowForm.submit();
}
},
error: function() {
tip.show('网络异常~');
}
});
}
init();
$yohoPage.on('touchstart', '.chose-panel', function(e) {
let $cur = $(e.target);
if ($cur.closest('.main').length > 0) {
return;
}
// 点击蒙版消失
hide();
return false;
});
function chosedLength() {
let $chosedL = $('.block-list li.chosed'),
infoHtml,
choosedInfo = $('.choosed-info'),
notChoose = $('.not-choose'),
chosedStr = $chosedL.eq(0).html() ? $chosedL.eq(0).html().replace(/(^\s*)|(\s*$)/g, '') : '',
strlen = 0;
choosedInfo.removeClass('hide');
if (!notChoose.hasClass('hide')) {
notChoose.addClass('hide');
}
for (let i = 0; i < chosedStr.length; i++) {
if (chosedStr.charCodeAt(i) > 255) {
strlen += 2;
} else {
strlen++;
}
if (strlen >= 16) {
chosedStr = chosedStr.substring(0, i) + '...';
break;
}
}
if ($chosedL.length === 2) {
$chosedL.each(function() {
infoHtml = '已选:' + chosedStr + '、' + $chosedL.eq(1).html();
});
} else if ($chosedL.length === 1) {
infoHtml = '已选:' + chosedStr;
} else {
choosedInfo.addClass('hide');
notChoose.removeClass('hide');
}
choosedInfo.html(infoHtml);
}
$yohoPage.on('touchstart', '.color-list .block', function() {
let $this = $(this),
index = $this.index(),
curGoodNum;
// 当前颜色已经是选中状态,再点击时
if ($this.hasClass('chosed')) {
// 清空剩余件数的提示
$allChoseItems.find('.num .left-num').html('');
$leftNum.val(0);
hasChooseColor = false;
// 当前尺码行隐藏
$sizeRowList.eq(curSizeIndex).addClass('hide');
// 目标尺码行显示
$sizeRowList.eq(0).removeClass('hide');
curSizeIndex = 0;
// 老的选中尺码去掉勾选,新的选中尺码加上勾选
changeSizeChosed(0);
// 当前颜色不是选中状态,选中时
} else {
hasChooseColor = true;
// 尺码行当前行隐藏
$sizeRowList.eq(curSizeIndex).addClass('hide');
// 老的选中尺码去掉勾选,新的选中尺码加上勾选
curGoodNum = changeSizeChosed(index + 1);
// 显示剩余数量
displayGoodNum(curGoodNum);
// 尺码对应行显示
$sizeRowList.eq(index + 1).removeClass('hide');
curSizeIndex = index + 1;
$curColorBlock = $this;
// 修改颜色时修改商品图片
$imgsThumb.addClass('hide').eq(index).removeClass('hide');
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: 'YB_GDS_COLOR_C',
param: JSON.stringify({
C_ID: C_ID,
PRD_ID: $('#goodsId').val(),
COLOR: $(this).html()
})
}, true);
}
}
// 颜色块切换勾选样式
$this.siblings('.chosed').removeClass('chosed');
// 特殊处理: 老的选中尺码在新选中的颜色对应尺码中不存在, 需要将颜色的第一行对应的颜色块加上勾选样式.
if (curGoodNum === -1) {
$curColorBlock = $($colorRowList.eq(0).children().get(index));
$curColorBlock.addClass('chosed');
// 当前选择的颜色块,加上勾选样式
} else {
$this.toggleClass('chosed');
}
$('#good-num').val(discountNum || 1);
// 设置按钮的样式和文字
updateConformButtonClassAndText();
// 展览票
if (ticketsLimit && single) {
// 选中日期
$curSizeBlock = $('.size-list .size-row .block').eq(index + 1);
$curSizeBlock.addClass('chosed');
// 显示剩余数量
displayGoodNum($curColorBlock.data('num'));
hasChooseSize = true;
return false;
}
chosedLength();
}).on('touchstart', '.size-list .block', function() {
let $this = $(this),
index,
curGoodNum;
// 当前尺码已经是选中状态,再点击时
if ($this.hasClass('chosed')) {
// 清空剩余件数的提示
$allChoseItems.find('.num .left-num').html('');
$leftNum.val(0);
hasChooseSize = false;
// 当前颜色行隐藏
$colorRowList.eq(curColorIndex).addClass('hide');
// 目标颜色行显示
$colorRowList.eq(0).removeClass('hide');
curColorIndex = 0;
// 老的选中颜色去掉勾选,新的选中颜色加上勾选
changeColorChosed(0);
if (!$sizeInfo.hasClass('hide')) {
$sizeInfo.addClass('hide');
}
// 当前尺码不是选中状态,选中时
} else {
hasChooseSize = true;
index = $('#' + $this.data('id')).data('index') - 1;
// 颜色当前行隐藏
$colorRowList.eq(curColorIndex).addClass('hide');
// 老的选中颜色去掉勾选,新的选中颜色加上勾选
curGoodNum = changeColorChosed(index + 1);
// 显示剩余数量
displayGoodNum(curGoodNum);
// 颜色对应行显示
$colorRowList.eq(index + 1).removeClass('hide');
curColorIndex = index + 1;
$curSizeBlock = $this;
$sizeInfo.html($(this).data('info')).removeClass('hide');
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: 'YB_GDS_SIZE_C',
param: JSON.stringify({
C_ID: C_ID,
PRD_ID: $('#goodsId').val(),
SIZE: $(this).html()
})
}, true);
}
}
// 颜色块切换勾选样式
$this.siblings('.chosed').removeClass('chosed');
$this.toggleClass('chosed');
$('#good-num').val(discountNum || 1);
chosedLength();
// 设置按钮的样式和文字
updateConformButtonClassAndText();
});
$yohoPage.on('touchstart', '.btn-minus', function() {
let num = parseInt($num.val(), 10);
leftNum = $('#left-num').val();
if (!checkColorSizeNum()) {
return;
}
if (discountNum && num <= discountNum + 1) {
$('.btn-minus').addClass('discount-gray');
}
if (discountNum && num <= discountNum) {
tip.show('量贩商品,' + discountNum + '件起购');
return;
}
if (num === 1 || leftNum - 0 === 0) {
tip.show('您选择的数量不能为零~');
return;
}
if (num < 0) {
tip.show('您选择的数量不能为负数~');
return;
}
$num.val(num - 1);
}).on('touchstart', '.btn-plus', function() {
let num = parseInt($num.val(), 10),
maxTips = ticketsLimit ? '每人只可购买' + ticketsLimit + '张当日门票' : '您选择的数量超过了最大库存量~';
leftNum = ticketsLimit || $('#left-num').val();
if (!checkColorSizeNum()) {
return;
}
if (discountNum && num >= discountNum) {
$('.btn-minus').removeClass('discount-gray');
}
if (num - 0 === leftNum || leftNum === 0) {
return;
}
// TODO:库存数验证
if (num > leftNum - 1) {
tip.show(maxTips);
return;
}
$num.val(num + 1);
}).on('touchstart', '#chose-btn-sure', function() {
let productSku,
productSkn,
buyNumber = $('#good-num').val() - 0,
promotionId,
cartGoodData,
url,
num = parseInt($num.val(), 10);
// 颜色尺码没有选择
if (!checkColorSizeNum()) {
return;
}
if ($('#chose-btn-sure').html() === '已售罄') {
return;
}
leftNum = $('#left-num').val() - 0;
if (num > leftNum) {
tip.show('您选择的数量超过了最大库存量~');
return;
}
if (num < 0) {
tip.show('您选择的数量小于一件~');
return;
}
if (num < discountNum) {
tip.show('量贩商品,' + discountNum + '件起购');
return;
}
$chosed = $('.block-list>ul>li.chosed');
setTimeout(function() {
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: 'YB_GDS_DT_ADD_TO_SC',
param: JSON.stringify({
C_ID: window._ChannelVary[window.cookie('_Channel')],
PRD_ID: $('#goodsId').val(),
PRD_NUM: buyNumber,
PRD_SKN: $('#productSkn').val(),
PRD_SKU: $curSizeBlock.data('skuid')
})
}, true);
}
});
if ($chosed.length === 2 && $chosed.closest('.zero-stock').length === 0) {
isSecKills = $('.seckill-time').length; // 秒杀标记
productSku = $curSizeBlock.data('skuid');
productSkn = $('.chose-panel').data('skn');
promotionId = $('#promotionId').val();
if (confirming) {
return false;
}
if (!ticketsLimit) {
confirming = true;
}
if (!isSecKills) {
loading.showLoadingMask();
}
// 立即购买门票
if (ticketsLimit) {
addTickets(productSku, buyNumber);
return;
}
if (budnleMode && cbFn) {
let sizeChose = $('.size-list').find('.chosed'),
sku = sizeChose.data('skuid'),
color = $('.color-list').find('.chosed').html().substring(0, 4) + '...',
size = sizeChose.html();
cbFn({
skn,
sku,
color,
size
});
confirming = false;
hide();
return false;
}
// 针对是否处于编辑模式设置不同的url和需要post的数据
if (isEdit) {
cartGoodData = {
new_product_sku: productSku,
new_product_skn: productSkn,
old_product_sku: oldSknId,
buy_number: buyNumber,
selected: isSelected
};
if (isGift) {
cartGoodData.promotionId = promotionId;
}
url = isGift ? '/cart/index/new/modifyPriceGift' : '/cart/index/new/modify';
} else if (limitProductCode) {
isSecKills = $('.seckill-time').length; // 秒杀标记
$(this).css('background-color', '#ccc').removeAttr('id');
// 当前面板选择的是限购商品
url = $('#limitProductPay').val() + '?limitproductcode=' + limitProductCode + '&sku=' +
productSku + '&skn=' + skn + '&buy_number=' + buyNumber;
removePannel();
if (!isSecKills) {
loading.showLoadingMask();
}
// 调用接口判断商品是否可以购买
$.ajax({
url: url
}).then(function(res) {
// 如果有错,则商品不可购买,执行页面刷新,否则跳到结算页面
if (res.error) {
tip.show(res.message);
setTimeout(function() {
location.reload();
}, 2000);
} else {
location.href = url;
}
}).fail(function() {
tip.show('网络异常!');
setTimeout(function() {
location.reload();
}, 2000);
});
return false;
} else {
cartGoodData = {
productSku: productSku,
new_product_skn: productSkn,
buyNumber: buyNumber,
promotionId: promotionId,
isEdit: isEdit,
cartType: queryString.cartType
};
url = '/cart/index/add';
}
if (!isSecKills) {
$.ajax({
method: 'POST',
url: url,
data: cartGoodData
}).done(function(res) {
let cartNum;
loading.hideLoadingMask();
if (res.code === 200 && !isEdit) {
cartNum = res.data.goods_count;
if (cartNum > 99) {
cartNum = '99+';
}
$('.num-tag').html(cartNum).removeClass('hide');
confirming = false;
if (cbFn) {
cbFn(cartGoodData);
}
}
if (res.message && !isEdit) {
tip.show(res.message);
}
hide();
if (isEdit) {
loading.showLoadingMask();
if (cbFn) {
cbFn(cartGoodData);
} else {
// 延迟刷新,否则面板可能无法隐藏
setTimeout(function() {
// 获取当前页面商品类型:普通商品/预售商品
window.location.href = '/cart/index/index?cartType=' + $('#cartType').val();
}, 1);
}
}
}).fail(function() {
tip.show('网络出了点问题~');
}).always(function() {
confirming = false;
});
} else {
let thisSkn = $('#productSkn').val();
let thisSku = '';
thisSku = $('.size-list').find('.chosed').attr('data-skuid');
window.location.href = '/cart/index/seckill?skn=' + thisSkn + '&sku=' + thisSku;
}
}
return false; // 阻止加入购物车按钮冒泡
});
$yohoPage.on('click', '.close', function() {
hide();
});
$yohoPage.on('touchstart', '.thumb', function() {
if ($thumbImg.hasClass('hover')) {
$thumbImg.removeClass('hover');
} else {
$thumbImg.addClass('hover');
}
});
exports.init = init;
exports.show = show;
exports.remove = removePannel;
exports.setEditModeWithSknId = setEditModeWithSknId;
exports.disableNumEdit = disableNumEdit;
exports.setLimitGoodModeWithSknId = setLimitGoodModeWithSknId;
exports.setBundleModeWithSknId = setBundleModeWithSknId;