detail.page.js
48.8 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
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
/**
* 商品详情页
* @author: tao.huang<tao.huang@yoho.cn>
* @date: 2016/9/22
*/
/**
* 说明:这里有一些优化方法。
* 页面已经被 nginx 缓存,变化后的数据需要通过 ajax 进行获取后,重新绑定事件。
*/
var $ = require('yoho-jquery');
var lazyLoad = require('yoho-jquery-lazyload');
var yas = require('../common/data-yas');
var dataLazyLoad = require('../plugins/lazy-load')(document);
var setPager = require('./detail/pager');
var notify = require('./detail/notify');
var favorite = require('./detail/brand-fav');
var bindEvent = $.Callbacks(); // eslint-disable-line
var Dialog = require('../common/dialog').Dialog;
var $main = $('.main'),
id = $main.data('id'),
shopId = parseInt($main.data('shop')),
brandId = parseInt($('#brand-favour').data('id')),
md5 = $main.data('md5'),
skn = $main.data('skn'),
deposit = $main.data('deposit') === 'Y',
secKill = $main.data('seckill') === 'Y',
limitCode = $main.data('limitcode'),
isBundle = $main.data('type') === 2, // 量贩商品
goodsBaseNum = isBundle ? $main.data('count') : 1; // 每次购买最低件数
var maxStock = -1; // 记录当前选中的颜色-尺码的库存量,若为-1,代表未选择尺码
var SLIDETIME = 200;
var colTxt = {
normal: '收藏商品',
coled: '已收藏',
hover: '取消收藏'
};
var oldStatus = {
txt: '已领取',
html: '<a class="coupon-btn">去使用</a>'
};
var BRAND_FAV = {
add: 'add',
cancel: 'cancel'
};
var $saleReturn = $('#saleReturn');
var dialogTpl = require('hbs/product/coupon-dialog.hbs');
var consultSuccessTpl = require('hbs/product/consult-success.hbs');
var pkgData;// 套餐数据
var notifyTpl = require('hbs/product/notify.hbs');
var notifyOkTpl = require('hbs/product/notify-ok.hbs');
var $goodsIdArr = [];
function limitedProductUrl(s) {
return window.location.href + '?openby:yohobuy={"action":"go.limitpurchase","params":{"lp":"' + s + '"}}';
}
function isEmpty(el) {
return !$.trim(el.html());
}
require('../plugins/slider');
require('../common/center-slider');
bindEvent.add(function() {
var $imgShow = $('#img-show'),
$thumbs = $('#thumbs > .thumb-wrap');
var $size = $('#sizes'),
$sizes = $size.children('.size'),
$sizeWarn = $size.find('.size-warn'),
$colorSizeTip = $size.children('.color-size-tip');
var $num = $('#num'),
$plusNum = $('#plus-num'),
$minusNum = $('#minus-num');
var $addToCart = $('#add-to-cart'),
$soldOut = $('#sold-out');
var $lcContainer = $('.lc-container'),
$itemBuy = $('.item-buy');
var $enableNotifyYou = $('#enable-notify');
var $qrcode = $('.qr-code');
var $descColor = $('#desc-color');
var thumbsLoaded = {};
var isTicket = $('input[name="isTicket"]').length > 0 && $('input[name="isTicket"]').val() === 'true';
var brandDomain = $('.home').attr('href');
var Alert = require('../common/dialog').Alert;
/** 优惠券开始 **/
var $moreCoupon = $('.more-coupon'),
$couponItem = $('.coupon-item');
function getCouponAsync(cid) {
var uid = getUid(); // eslint-disable-line
if (!uid) {
return $.Deferred().reject({data: {refer: window.signinUrl()}}).promise(); // eslint-disable-line
}
return $.getJSON('/product/detail/coupon', {
couponId: cid
}).then(function(result) {
var defer = $.Deferred(); //eslint-disable-line
if (result.code === 200) {
defer.resolve();
} else {
defer.reject(result);
}
return defer.promise();
});
}
function acquireCoupon($ele) {
var couponId = $ele.data('id');
var i = $ele.data('i');
var $item = $($couponItem.get(i));
var status = $item.data('status');
switch (status) {
case 1:
getCouponAsync(couponId).then(function() {
$ele.find('.coupon-status').text(oldStatus.txt);
$ele.find('.coupon-go').empty().append(oldStatus.html);
$item.data('status', 3);
}).fail(function(err) {
if (err.data && err.data.refer) {
return window.jumpUrl(err.data.refer);
}
alert(err.message);
});
break;
default:
window.jumpUrl(brandDomain);
}
}
function openCouponDialog(e) {
var $coupons = $couponItem.map(function(i) {
var $this = $(this);
return {
couponId: $this.data('id'),
couponName: $this.data('name'),
amount: $this.data('amount'),
acquireStatus: $this.data('status'),
rule4ShortName: $this.data('rule'),
i: i
};
}).get();
var newCoupons = $.grep($coupons, function(val) {
return val.acquireStatus === 1;
});
var oldCoupons = $.grep($coupons, function(val) {
return val.acquireStatus === 3;
});
var couponData = {
cssClass: window.screen.height > 800 ? 'coupon-big-list' : 'coupon-small-list',
newList: {
title: '可领取的券',
body: newCoupons
},
oldList: {
title: '已领取的券',
body: oldCoupons
}
};
var dialog = new Dialog({
content: dialogTpl({coupon: couponData}),
className: 'coupon-big'
});
dialog.$el.on('click', '.status', function() {
acquireCoupon($(this));
});
dialog.show();
e.stopPropagation();
}
// 打开优惠券列表
$moreCoupon.on('click', openCouponDialog);
/** 优惠券结束 **/
function getSku() {
return $('.size:not(.hide) li.focus').data('sku');
}
function imgShow(src) {
$imgShow.attr('src', src);
}
function bigImgShow(src) {
$('#big').attr('src', src);
}
// 查看细节图功能
var moveWidth = 135, // eslint-disable-line
w = 420,
h = 560,
_w = 1000,
radio = w / _w,
$moveObj = $('.move-object'),
$max = $('.max');
function move(e) {
var x = e.pageX - $imgShow.offset().left;
var y = e.pageY - $imgShow.offset().top;
// 滑块左上角的坐标
var _x = x - moveWidth / 2;
var _y = y - moveWidth / 2;
var _maxX = w - moveWidth;
var _maxY = h - moveWidth;
if (_x < 0) {
_x = 0;
} else if (_x >= _maxX) {
_x = _maxX;
}
if (_y < 0) {
_y = 0;
} else if (_y >= _maxY) {
_y = _maxY;
}
// 大图左上角的坐标
var offX = _x / radio, // eslint-disable-line
offY = _y / radio;
$moveObj.css({
left: _x,
top: _y
});
$max.get(0).scrollLeft = offX;
$max.get(0).scrollTop = offY;
}
$('.move-over').mouseleave(function() {
$('.move-object').addClass('hide');
$max.addClass('hide');
});
$('.move-over').mousemove(function(e) {
if ($moveObj.hasClass('hide')) {
$moveObj.removeClass('hide');
}
if ($max.hasClass('hide')) {
$max.removeClass('hide');
}
move(e);
});
// 细节图结束
// 促销弹出框
var icon = { // eslint-disable-line
unfold: '',
fold: ''
};
$('.activity-title').click(function() {
$(this).toggleClass('active');
if ($(this).hasClass('active')) {
$(this).find('span').html(icon.fold);
$('.activity-container').slideDown(400);
} else {
$(this).find('span').html(icon.unfold);
$('.activity-container').slideUp(400);
}
});
// 获取当前选择的商品数目
function getNum() {
return +$num.text();
}
// 是否能:量贩购买
function canBundleBuy() {
return goodsBaseNum < maxStock;
}
// 重置Num显示为最小购买数
function resetNum() {
$num.text(goodsBaseNum + '');
// +-按钮状态重置
if (maxStock === 1 || maxStock === 0 || !canBundleBuy()) {
// 数目为1/0时
$plusNum.addClass('dis');
$minusNum.addClass('dis');
} else {
$plusNum.removeClass('dis');
$minusNum.addClass('dis');
}
}
// 加入购物车和已售罄状态控制
function switchBtnStatus($color) {
// 全部售罄,按钮状态不变
if ($itemBuy.length === 0) {
return;
}
// 预上架商品,就不检查库存
if ($('#open-soon').length === 1) {
return;
}
// 选中的商品存量为0或者某个颜色的total为0
if (maxStock === 0 || ($color && ~~$color.data('total') === 0) || !canBundleBuy()) {
$itemBuy.addClass('hide'); // 隐藏加入购物车、即将开售、立即购买等相同位置的按钮
$soldOut.removeClass('hide');
} else {
// 包括默认的-1情况下
$itemBuy.removeClass('hide');
$soldOut.addClass('hide');
}
}
// size warn
function showSizeWarn() {
$sizes.not('.hide').children('.size-warn').removeClass('hide');
}
// size title
(function() {
var $sizeTitleJson = $('#size-title-json'),
jsonHtml = $sizeTitleJson.html(),
sizeTitle;
if (!jsonHtml) {
return;
}
sizeTitle = $.parseJSON(jsonHtml);
// 数据获取后删除
$sizeTitleJson.remove();
$sizes.children('li').each(function() {
var $this = $(this),
key = $this.data('name');
$this.data('title', sizeTitle[key]);
});
}());
// 这个文件商品详情页专用
require('../plugins/share')();
require('yoho-jquery-qrcode');
// 颜色
$('.colors').on('click', 'li', function() {
var $this = $(this),
index = $this.index();
var $imgs;
// 初始化color-size显示或隐藏
$colorSizeTip.addClass('hide');
// 隐藏尺码提示
$sizeWarn.addClass('hide');
maxStock = -1;
if ($this.hasClass('focus')) {
// 已获取焦点的颜色再次点击,清除尺码的选中
$sizes.eq(index).children('li').removeClass('focus');
} else {
// 未获取焦点,选择尺码
$this.siblings('.focus').removeClass('focus');
$this.addClass('focus');
// 切换图片显示
$thumbs.not('.hide').addClass('hide');
$imgs = $thumbs.eq(index).removeClass('hide').find('img');
if (typeof thumbsLoaded[index] === 'undefined') {
// trigger layLoad
lazyLoad($imgs, {
event: 'sporty'
});
$imgs.trigger('sporty');
thumbsLoaded[index] = true;
}
$imgs.first().addClass('active');
imgShow($imgs.first().data('shower'));
bigImgShow($imgs.first().data('origin'));
// 切换详细信息的颜色显示
$descColor.text($this.data('color'));
// 切换尺码显示
$sizes.not('.hide').addClass('hide').children('li').removeClass('focus');
$sizes.eq(index).removeClass('hide');
// 是否展览票
if (isTicket) {
$sizes.eq(index).children('li').trigger('click');
$('.chose-size').addClass('hide');
}
}
resetNum();
switchBtnStatus($this);
});
// 缩略图鼠标移入显示
$('#thumbs').on('mouseenter', '.thumb', function() {
var $this = $(this);
imgShow($this.data('shower'));
bigImgShow($this.data('origin'));
if (!$this.hasClass('active')) {
$this.siblings('.active').removeClass('active').end().addClass('active');
}
});
// 尺码
$size.on('click', 'li', function() {
var $this = $(this);
if ($this.hasClass('focus')) {
return;
}
maxStock = +$this.data('num');
$this.siblings('.focus').removeClass('focus');
$this.addClass('focus');
$colorSizeTip.html($this.data('title')).removeClass('hide');
$sizeWarn.addClass('hide');
switchBtnStatus();
// / 到货通知:状态
if ($this.data('notify') === 'Y') {
$enableNotifyYou.removeClass('hide');
notify.statusAsync(getSku()).then(function(result) {
// 检查当前请求是否是选中的sku
if (result.data.sku !== getSku()) {
return null;
}
if (result.data.status === 'Y') {
$enableNotifyYou.addClass('dis');
$enableNotifyYou.find('span').text('已订阅到货通知');
} else {
$enableNotifyYou.removeClass('dis');
$enableNotifyYou.find('span').text('到货通知');
}
}).fail(function(err) {
// 检查当前请求是否是选中的sku
if (err.data.sku !== getSku()) {
return null;
}
$enableNotifyYou.removeClass('dis');
$enableNotifyYou.find('span').text('到货通知');
});
} else {
$enableNotifyYou.addClass('hide');
}
resetNum();
}).on('click', '.size-ruler', function() {
// 尺码帮助
$('body,html').animate({
scrollTop: $('.size-info').offset().top
}, 300);
});
// 增加到货通知
$enableNotifyYou.on('click', function() {
if ($enableNotifyYou.hasClass('dis')) {
return;
}
if (!window.getUid()) {
return window.jumpUrl(window.signinUrl());
}
var opt = { //eslint-disable-line
className: 'notify-goods-wrapper',
closeIcon: true,
content: notifyTpl({pid: id, sku: getSku()})
};
var opt2 = {
className: 'notify-goods-wrapper',
closeIcon: true,
content: notifyOkTpl()
};
var dialog = new Dialog(opt); // eslint-disable-line
var FAV = { //eslint-disable-line
checked: '',
unchecked: ''
};
dialog.$el.on('click', '.ok', function() {
var $this = $(this),
sku = $this.data('sku'),
isFav = dialog.$el.find('.active').length === 1;
notify.addAsync(skn, sku).then(function() {
if (isFav) {
$('#collect-product').triggerHandler('click');
}
dialog.close();
new Dialog(opt2).show();
$enableNotifyYou.addClass('dis');
$enableNotifyYou.find('span').text('已订阅到货通知');
}).fail(function(err) {
if (err.code === 400) {
window.jumpUrl(err.data.refer);
return;
}
alert(err.message);
}).always(function() {
dialog.close();
});
});
dialog.$el.on('click', '.checked', function() {
var $this = $(this);
$this.toggleClass('active');
if ($this.hasClass('active')) {
$this.html(FAV.checked);
} else {
$this.html(FAV.unchecked);
}
});
dialog.show();
});
// 增加购买数量
$plusNum.click(function() {
var num = getNum();
if ($(this).hasClass('dis')) {
return;
}
if (maxStock === -1) {
showSizeWarn();// 显示选择尺码提示
return;
}
// 已售罄
if (maxStock === 0) {
return;
}
if (num === maxStock - 1) {
// +按钮不可点
$(this).addClass('dis');
}
// 数目为1时点+则移除-不可点状态
if (num === goodsBaseNum) {
$minusNum.removeClass('dis');
}
$num.text(num + 1 > maxStock ? maxStock : num + 1);
}).on('selectstart', function() {
return false;
});
// 减少购买数量
$minusNum.click(function() {
var num = getNum();
if ($(this).hasClass('dis')) {
return;
}
if (num === (goodsBaseNum + 1)) {
$(this).addClass('dis');
}
if (num === maxStock) {
// 恢复+可点
$plusNum.removeClass('dis');
}
$num.text(num - 1 < 0 ? 0 : num - 1);
}).on('selectstart', function() {
return false;
});
// 限购码
$('.get-lc:not(.dis)').hover(function() {
$lcContainer.removeClass('hide');
if (isEmpty($qrcode)) {
$qrcode.qrcode({
render: 'table',
size: 140,
text: limitedProductUrl(limitCode)
});
}
}, function() {
$lcContainer.addClass('hide');
});
// 加入购物车
$addToCart.click(function() {
if (maxStock === -1) {
showSizeWarn();
return;
}
// 加入购物车埋点
yas.givePoint('YB_GDS_DT_ADD_TO_SC', {PRD_ID: +$('.main').data('id'), PRD_NUM: getNum()});
$.ajax({
type: 'POST',
url: '/cart/index/add',
data: {
productSku: getSku(),
buyNumber: getNum()
}
}).then(function(data) {
var code = data.code;
var alert;
if (code === 200) {
$('#type-chose').slideUp(SLIDETIME);
$('#balance').slideDown(SLIDETIME);
$('#cart-num').text(data.data.goods_count); // 更新数目
} else if (code === 500) {
if (deposit) {
alert = new Alert('定金预售商品只能在APP端购买');
alert.show();
}
if (secKill) {
alert = new Alert('秒杀商品只能在APP端购买');
alert.show();
}
}
});
});
// 收藏
$('#collect-product').click(function() {
var $this = $(this),
cancel,
coltyp;
if ($this.hasClass('coled')) {
cancel = true;
}
coltyp = cancel ? 2 : 1;
// 收藏埋点
yas.givePoint('YB_COLLECTION_C', {PRD_ID: id, COL_TYP: coltyp});
$.ajax({
type: 'POST',
url: '/product/item/togglecollect',
data: {
productId: id,
type: cancel ? 'cancel' : 'add'
}
}).then(function(data) {
var code = data.code;
if (code === 200) {
$this.toggleClass('coled');
if (cancel) {
$this.find('em').text(colTxt.normal);
} else {
$this.find('em').text(colTxt.coled);
}
} else if (code === 403) {
location.href = data.data.url;
}
});
}).hover(function() {
var $this = $(this);
if ($this.hasClass('coled')) {
$this.find('em').text(colTxt.hover);
}
}, function() {
var $this = $(this);
if ($this.hasClass('coled')) {
$this.find('em').text(colTxt.coled);
}
});
// 继续购物
$('#keep-shopping').click(function() {
$('#type-chose').slideDown(SLIDETIME);
$('#balance').slideUp(SLIDETIME);
});
// 电子票立即购买
$('#buy-ticket').click(function() {
var sku,
buyNumber;
if (maxStock === -1) {
showSizeWarn();
return;
}
if ($(this).hasClass('dis')) {
return;
}
sku = $('.size:not(.hide) li.focus').data('sku');
buyNumber = getNum();
$.ajax({
type: 'POST',
url: '/cart/index/setTicket',
data: {
productSku: sku,
buyNumber: buyNumber
}
}).then(function(data) {
var $ticketForm,
myAlert;
if (data.code * 1 === 200) {
$ticketForm = $('form[name="ticket-form"]');
$ticketForm.html(
'<input name="productSku" value="' + sku + '" />' +
'<input name="buyNumber" value="' + buyNumber + '" />'
);
$ticketForm.submit();
} else if (data.code * 1 === 401) {
document.location.href = data.message;
} else {
myAlert = new Alert(data.message);
myAlert.show();
}
});
});
// 立即购买
$('#buy-now').click(function() {
var sku,
base,
myAlert;
if ($(this).hasClass('dis')) {
return;
}
if (maxStock === -1) {
showSizeWarn();
return;
}
base = $(this).data('base');
// 潮流尖货
if (!base) {
myAlert = new Alert('打开APP可抢购该商品哦~~');
myAlert.show();
return;
}
sku = $sizes.find('.focus').data('sku');
if (limitCode && sku && skn && base) {
location.href = base + '?sku=' + sku + '&skn=' + skn + '&limitcode=' + limitCode;
return;
}
if (sku && base) {
location.href = base + '?product_sku=' + sku;
return;
}
});
// 按钮鼠标移入效果【dis状态的按钮状态不变】
$('.buy-btn').mouseover(function() {
if ($(this).hasClass('dis')) {
return;
}
$(this).addClass('hover');
}).mouseleave(function() {
$(this).removeClass('hover');
});
// 只有一个尺码(多个或一个颜色)时默认选中第一个未售罄的颜色的第一个尺码
(function() {
var hasOnlyOneSize = true,
i;
for (i = 0; i < $sizes.length; i++) {
if ($sizes.eq(i).find('li').length !== 1) {
hasOnlyOneSize = false;
break;
}
}
if (hasOnlyOneSize) {
$sizes.eq($('.colors .focus').index()).find('li').click();
}
}());
});
// yas
require('../common');
require('./detail/latest-walk'); // 最近浏览
// 品牌收藏
$('#brand-favour').click(function() {
var $this = $(this);
var type = $this.hasClass('coled') ? BRAND_FAV.cancel : BRAND_FAV.add;
(function() {
switch (type) {
case BRAND_FAV.add:
return favorite.addFav(shopId, brandId);
case BRAND_FAV.cancel:
return favorite.cancelFav(shopId, brandId);
default:
return $.Deferred.reject().promise();
}
}()).then(function() {
$this.toggleClass('coled');
});
});
// 售后服务
$('.after-service-switch').click(function() {
var $this = $(this),
$content = $this.next('.after-service-content');
var html = {
down: '',
up: ''
};
if ($content.css('display') === 'none') {
$content.slideDown(SLIDETIME);
$this.find('.triangle').html(html.up);
} else {
$content.slideUp(SLIDETIME);
$this.find('.triangle').html(html.down);
}
});
// 商品详情区的热点
function loadHotArea() {
$.ajax({
type: 'GET',
url: '/product/detail/hotarea',
data: {
productId: id
}
}).then(function(html) {
$('#details-html').prepend(html);
// 修正热区尺寸使居中
$('.hot-point-wrap > img').load(function() {
$(this).parent('.hot-point-wrap').width($(this).width());
});
// Bind Hover event
$('.hot-point').hover(function() {
$(this).addClass('hover');
}, function() {
$(this).removeClass('hover');
});
});
}
window.fetchHotArea = window.once(loadHotArea);
// 商品详情图片懒加载
lazyLoad($('#details-html img'));
// 咨询和评价
function loadComment() {
var commentPage = {}, // 每个类型的分页页码
currentType = '7', // 当前评论展示的类型
cNumReady = false; // 只第一次请求后更新数量
var commentsTpl = require('hbs/product/comment-item.hbs'),
loadingComments;
function loadComments(type, nowPage) {
if (loadingComments) {
return;
}
commentPage[type] = commentPage[type] || 1;
loadingComments = true;
return $.ajax({
type: 'GET',
url: '/product/detail/comment',
data: {
productId: id,
page: nowPage,
filterId: type
}
});
}
// 购买评价
function loadAllComments(type, nowPage) {
loadComments(type, nowPage).then(function(data) {
var res, filter, $ul, totalnum = 0, baseUrl;
if (data.code === 200) {
res = data.data;
filter = data.filter || [];
$ul = $('.comments [data-comment-list=' + type + '] ul');
if (res.length === 0) {
$ul.next('.more-wrap').addClass('hide');
return;
}
if (filter && filter.length && !cNumReady) {
// cNumReady = true;
$(filter).each(function(idx, fit) {
if (fit.num) {
$('.comments [data-comment-type=' + fit.filterId + '] em').text(fit.num);
if (fit.filterId === '7') { // 全部数量
$('.consult-comment .block-title .comment-num').text(fit.num);
}
if (fit.filterId === type) {
totalnum = fit.num;
}
}
});
}
totalnum = Math.ceil(totalnum / 10) * 20;
$ul.empty().append(commentsTpl({
comments: res
}));
baseUrl = '/product/detail/comment?productId=' + id + '&filterId=7';
$ul.append(setPager({
baseUrl: baseUrl,
totalRecords: totalnum,
page: nowPage,
type: 'ellipsis',
theme: 'msg-pager'
}));
}
}).always(function() {
loadingComments = false;
});
}
$('.comments ul').on('click', 'a', function() {
var $this = $(this);
var href = $this.data('page');
var data = href.split('?')[1].split('&');
var result = data.map(function(i) {
return i.split('=')[1];
});
loadAllComments(currentType, result[2]);
});
// 评论类型的切换
$('.comments').on('click', '.comment-tabs h2[data-comment-type]', function() {
var $t = $(this),
$tabs = $t.closest('.comment-tabs'),
type = $t.attr('data-comment-type');
currentType = type;
$tabs.find('h2[data-comment-type]').removeClass('active');
$t.addClass('active');
$('.comments').find('[data-comment-list]').hide();
$('.comments').find('[data-comment-list=' + type + ']').show();
if (!commentPage[type]) { // 首次切换自动加载
loadAllComments(type);
}
});
loadAllComments(currentType);
}
// 购买评价的相关事件
$('.comments').on('click', '.img-preview .img-thumb', function() {
var $t = $(this);
var $d = $t.closest('.img-preview').find('.img-detail');
$d.toggle();
if ($d.is(':visible')) {
$t.addClass('active');
} else {
$t.removeClass('active');
}
});
$('.comments').on('click', '.img-preview [data-role="preview-close"]', function() {
var $img = $(this).closest('.img-preview').find('.img-wrap img'),
rotate = 0;
$(this).closest('.img-detail').hide();
$img.data('rotate', rotate);
$img.css('transform', 'rotate(' + rotate + 'deg)');
});
$('.comments').on('click', '.img-preview [data-role="preview-left"]', function() {
var $img = $(this).closest('.img-preview').find('.img-wrap img'),
rotate = ($img.data('rotate') || 0) * 1;
rotate -= 90;
$img.data('rotate', rotate);
$img.css('transform', 'rotate(' + rotate + 'deg)');
});
$('.comments').on('click', '.img-preview [data-role="preview-right"]', function() {
var $img = $(this).closest('.img-preview').find('.img-wrap img'),
rotate = ($img.data('rotate') || 0) * 1;
rotate -= 90;
$img.data('rotate', rotate);
$img.css('transform', 'rotate(' + rotate + 'deg)');
});
window.fetchComment = window.once(loadComment);
function loadConsult() {
var consultsTpl = require('hbs/product/consult-item.hbs'),
$consultsUl = $('#consults-ul'),
$consultNum = $('.consult-num'),
loadingConsults = false;
// 顾客咨询
function loadConsults(nowPage) {
if (loadingConsults) {
return;
}
loadingConsults = true;
$.ajax({
type: 'GET',
url: '/product/detail/consult',
data: {
productId: id,
page: nowPage
}
}).then(function(data) {
var res;
var totalNum;
var baseUrl = '/product/detail/consult?productId=' + id;
if (data.code === 200) {
res = data.data;
if (res.length === 0) {
$consultsUl.next('.more-wrap').addClass('hide');
return;
}
// 更新总数显示
$consultNum.text(res[0].total);
totalNum = Math.ceil(res[0].total / 10) * 20;
$consultsUl.empty().append(consultsTpl({
consults: res
}));
$('#consults-ul .zan-content').on('click', '.cuslike', function() {
var $this = $(this);
var cid = $this.data('id');
var like = $this.data('like');
$.ajax({
type: 'GET',
url: '/product/detail/consult/like/' + cid
}).then(function(result) {
if (result && result.code === 400) {
return window.jumpUrl(result.data.refer);
}
if (result && result.code === 200) {
$this.addClass('getzan');
$('.zan-content .icon-border[data-id=' + cid + '] .likeNum')
.replaceWith('<em class="likeNum">' + (like + 1) + '</em>');
}
});
});
$('#consults-ul .zan-content').on('click', '.cususeful', function() {
var $this = $(this);
var cid = $this.data('id');
var useful = $this.data('useful');
$this.addClass('getzan');
$.ajax({
type: 'GET',
url: '/product/detail/consult/useful/' + cid
}).then(function(result) {
if (result && result.code === 400) {
return window.jumpUrl(data.data.refer);
}
if (result && result.code === 200) {
$('.zan-content .usefulData[data-id=' + cid + '] .usefulNum')
.replaceWith('<em class="usefulNum">' + (useful + 1) + '</em>');
}
});
});
baseUrl = '/product/detail/consult?productId=' + id;
$('.consults-pager').empty().append(
setPager({
baseUrl: baseUrl,
totalRecords: totalNum,
page: nowPage,
type: 'ellipsis',
theme: 'msg-pager'
})
);
}
}).always(function() {
loadingConsults = false;
});
}
$('.consults-pager').on('click', 'a', function() {
var $this = $(this);
var href = $this.data('page');
var data = href.split('?')[1].split('&');
var result = data.map(function(i) {
return i.split('=')[1];
});
loadConsults(result);
});
// 我要咨询
$('#consults-btn').click(function() {
// TODO:点击我要资讯的时候更新验证码显示
$('.new-consult').removeClass('hide');
$('.consult-success').addClass('hide');
});
// 提交咨询
$('#submit-consult').click(function() {
var $textArea = $('#textbox'),
content = $.trim($textArea.val());
var consultData = {
msg: '发表成功,等待客服回复',
download: '扫我下载app',
learn: '及时了解回复内容'
};
var pass = true;
if (content === '') {
$textArea.attr('placeholder', '请输入咨询内容');
$textArea.addClass('err');
pass = false;
}
if (pass === false) {
return;
}
$.ajax({
type: 'POST',
url: '/product/detail/consult',
data: {
productId: id,
content: content
}
}).then(function(data) {
var code = data.code;
if (code === 200) {
$textArea.removeClass('err');
new Dialog({
content: consultSuccessTpl({success: consultData}),
className: 'consult-alert',
btns: [
{
id: 'consult-sure',
btnClass: ['alert-sure', 'btn-close'],
name: '确定'
}
]
}).show();
// 清空输入
$textArea.val('');
} else if (code === 400) {
// 跳转登录页
location.href = data.data.refer;
}
});
});
loadConsults(1);
}
window.fetchConsult = window.once(loadConsult);
function randomString(len) {
var $chars = 'ABCDEFGHJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890-';
var maxPos = $chars.length,
pwd = '',
i;
for (i = 0; i < len; i++) {
pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
}
return pwd;
}
/*
* 页面加载完
*/
function initPageYas() {
var loadYas = {
REC_POSE: 100013,
REC_ID: randomString(40),
PRD_ID: $goodsIdArr.join(','),
PRD_NUM: $goodsIdArr.length,
ORDER_CODE: '',
ACTION_ID: 0,
PAGE_NUM: 1
};
// 关键词搜索结果页展示时
yas.givePoint('YB_CHOOSE_FOR_YOU_Y', loadYas);
}
// 店铺推荐
function loadRecommend() {
$.ajax({
type: 'GET',
url: '/product/detail/recommend',
data: {
skn: skn,
size: 20,
num: 1
}
}).then(function(data) {
var pro = data.data.products;
var recommendTpl = require('hbs/product/recommend.hbs');
var html = recommendTpl(data.data);
if (data.code === 200 && pro.length !== 0) {
$('#recommend-shop').removeClass('hide');
$('#recommend-content').append(html);
$('.recommend-slider').slider2({
shownum: 5,
isCircle: true
});
$('.recommend-slider .img-item .goods-id').each(function() {
$goodsIdArr.push($(this).html());
});
} else {
$('.bottom-title').eq(0).removeClass('bottom-cur').addClass('hide');
$('.bottom-title').eq(1).addClass('bottom-cur');
$('.bottom-title').filter('.change').addClass('hide');
$('#recommend-shop').remove();
$('.individual-comment .latest-walk').show();
fetchLatestWalk(); // eslint-disable-line
}
// 页面加载完,埋点
initPageYas();
});
}
// 点击为您推荐商品埋点
$('.recommend-slider').on('click', '.img-item', function() {
var $this = $(this);
var proId = $this.find('.goods-id').html();
var loadYas = {
REC_POSE: 100013,
REC_ID: randomString(40),
PRD_ID: proId,
PRD_NUM: $goodsIdArr.indexOf(proId) + 1,
ORDER_CODE: '',
ACTION_ID: 1,
PAGE_NUM: 1
};
// 关键词搜索结果页展示时
yas.givePoint('YB_CHOOSE_FOR_YOU_Y', loadYas);
});
window.fetchRecommend = window.once(loadRecommend);
// 加载套餐默认信息
$(function() {
return $.ajax({
type: 'GET',
url: '/product/detail/getPacakge',
data: {
skn: skn
}
}).then(function(result) {
if (result.code === 200 && result.data.packageData.length > 0) {
var packageTpl = require('hbs/product/package.hbs'); // eslint-disable-line
pkgData = result.data;
$('#package').html(packageTpl(pkgData));
// 详情页套餐区
$('.good-info .good-detail-text > a').dotdotdot({
wrap: 'letter'
});
} else {
$('#package').addClass('hide');
}
});
});
// 套餐点击事件
$('.package-box').on('click', '#buy-detail', function() {
var isSingle = true,
singleSkuList = [];
for (var i = 0; i < pkgData.packageData.length; i++) {
var pData = pkgData.packageData[i];
if (pData.colors.length === 1 && pData.colors[0].size.length === 1) {
singleSkuList.push(pData.colors[0].size[0].sku);
} else {
isSingle = false;
}
}
// 如果只有套餐中商品,都只有一个颜色一个尺码,就直接跳转结算页
if (isSingle) {
if (!window.getUid()) {
return window.jumpUrl(window.signinUrl());
}
window.location.href = '//www.yohobuy.com/cart/easypay?bundle=' + pkgData.bundleId + '&sku=' + singleSkuList.join(',');
return true;
}
var pkgDetailTpl = require('hbs/product/package-dialog.hbs');
var opt = {
className: 'pkg-dialog',
closeIcon: false,
content: pkgDetailTpl(pkgData)
};
var pkgDialog = new Dialog(opt);
pkgDialog.show();
// 选择颜色
pkgDialog.$el.on('click', '.pkg-colors li', function() {
var $this = $(this);
var index = $this.index();
var $colorName = $this.find('.color-name');
var $pkType = $this.closest('.type-chose');
var $pkSizesUl = $pkType.find('.pkg-sizes ul');
var $pkgColor = $pkType.find('.chose-done .pkg-color');
var $pkgSize = $pkType.find('.chose-done .pkg-size');
var $pkgSizeWarn = $pkType.find('.pkg-sizes .size-warn');
if ($this.hasClass('focus') || $this.hasClass('disable')) {
return;
}
$this.addClass('focus').siblings('.focus').removeClass('focus');
// 取消尺码的选择
$pkSizesUl.find('li').removeClass('focus');
$pkgColor.html('"' + $colorName.html() + '"');
$pkgSize.html('');
$pkSizesUl.addClass('hide').eq(index).removeClass('hide');
$pkgSizeWarn.addClass('hide');
});
// 选择尺码
pkgDialog.$el.on('click', '.pkg-sizes li', function() {
var $this = $(this);
var $pkType = $this.closest('.type-chose');
var $pkgSize = $pkType.find('.chose-done .pkg-size');
var $pkgSizeWarn = $this.siblings('.size-warn');
if ($this.hasClass('focus') || $this.hasClass('disable')) {
return;
}
$this.addClass('focus').siblings('.focus').removeClass('focus');
$pkgSize.html('"' + $this.html() + '码"');
$pkgSizeWarn.addClass('hide');
});
// 立即购买跳转
pkgDialog.$el.on('click', '#pay-pkg', function() {
if (!window.getUid()) {
return window.jumpUrl(window.signinUrl());
}
var bundleId = $('#package-pro').data('bundleid'),
$selectedPkgSizes = $('.pkg-sizes .size:not(.hide)'),
flag = true,
skuList = [];
$selectedPkgSizes.each(function() {
var $sku = $(this).find('li.focus');
if ($sku.length === 0) {
flag = false;
$(this).find('.size-warn.warn-tip').removeClass('hide');
} else {
skuList.push($sku.data('sku'));
}
});
if (flag) {
window.location.href = '//www.yohobuy.com/cart/easypay?bundle=' + bundleId + '&sku=' + skuList.join(',');
}
});
});
// 店铺推荐和最近浏览
$('.bottom-tab').on('click', '.bottom-title', function() {
var $this = $(this),
index = $this.index();
var $latestWalk = $('.individual-comment .latest-walk'),
$recommendComment = $('.individual-comment #recommend-shop');
if ($this.hasClass('change')) {
return;
}
if ($this.hasClass('bottom-cur')) {
return;
}
$this.addClass('bottom-cur');
$this.siblings('.bottom-cur').removeClass('bottom-cur');
if (index === 0) {
// 店铺推荐
$recommendComment.slideDown(SLIDETIME);
$latestWalk.slideUp(SLIDETIME);
$('.change').removeClass('hide');
} else {
// 最近游览
fetchLatestWalk(); // eslint-disable-line
$recommendComment.slideUp(SLIDETIME);
$latestWalk.slideDown(SLIDETIME);
$('.change').addClass('hide');
}
});
$('.recommend-content').find('.iconfont').mouseenter(function() {
$(this).addClass('focus');
}).mouseleave(function() {
$(this).removeClass('focus');
});
// 特殊商品退换货
function loadReturn() {
return $.ajax({
type: 'GET',
url: '/product/detail/return',
data: {
skn: skn
}
}).then(function(result) {
if (result.code === 200) {
if (result.data.result === 'N') {
$saleReturn.removeClass().addClass('not-support-saleReturned-service');
}
}
});
}
window.fetchReturn = window.once(loadReturn);
// 首屏加载后,对比数据是否变化,如果变化,重新渲染,重新绑定事件
bindEvent.fire();
// 当前只渲染商品详情页的变化敏感的部分
(function() {
$.ajax({
type: 'GET',
url: '/product/detail/header',
dataType: 'html',
data: {
productId: id,
md5: md5
}
}).then(function(result) {
if (result) {
$('.main').html(result);
bindEvent.fire(); // 重新绑定事件
}
});
favorite.getFavNum(shopId, brandId).then(function(result) {
$('#brand-favour').find('span').html(result);
});
favorite.statusFav(shopId, brandId).then(function() {
$('#brand-favour').addClass('coled');
});
}());
$(window).scroll(function() {
var sc = $(document);
var win = $(window);
var scrollStart = $('.other-infos').offset().top;
var scrollBottom = sc.height() - $('#after-service-switch').offset().top;
var scrollEnd = $('#textbox').offset().top;
if (sc.scrollTop() >= scrollStart && sc.scrollTop() <= scrollEnd) {
$('.shoppingCar').addClass('fixednav');
} else {
$('.shoppingCar').removeClass('fixednav');
}
if (sc.height() - win.height() - sc.scrollTop() <= scrollBottom) {
$('.shoppingCar').height(win.height() - (scrollBottom + win.height() + sc.scrollTop() - sc.height()));
} else {
$('.shoppingCar').height(1000);
}
$('.getnav').each(function(i, ele) {
var data;
if ($(ele).offset().top - $(window).scrollTop() < 100) {
data = $(ele).data('id');
$('.shoppingCar-nav li:eq(' + data + ')').siblings().find('a').removeClass('fixed');
$('.shoppingCar-nav li:eq(' + data + ')').find('a').addClass('fixed');
}
});
});
$('.shoppingCar').on('click', '.option', function(e) {
var $this = $(this);
if ($this.hasClass('fixed')) {
return;
}
$this.closest('li').siblings().find('.option').removeClass('fixed');
$this.addClass('fixed');
if ($this.hasClass('comment')) {
window.fetchComment();
} else if ($this.hasClass('consult')) {
window.fetchConsult();
}
e.stopPropagation();
});
$('.shoppingCar-btn').on('click', function() {
var $addToCart = $('#add-to-cart');
var sc = $(document);
if (maxStock === -1) {
sc.scrollTop(200);
} else {
$addToCart.trigger('click');
}
});
$(function() {
$('.bottom-tab .change').click(function() {
$('.img-brand-switch .next').trigger('click');
});
});
$(function() {
var font = $('.description-content .basic li');
$('.size-table tbody tr:odd td').css('background-color','#f9f9f9');
font.each(function(i, ele) {
if ((i + 1) % 4 === 0) {
$(this).find('.justpostion').css({display: 'inline-block', 'margin-left': '40px'});
} else if ((i + 1) % 4 === 1) {
return;
} else {
$(this).find('.justpostion').css('margin-left', '56px');
}
});
});
/*获取商品编码*/
function getPrdId(){
return +$('.main').data('id');
}
$('#buy-now').click(function(){
var num = +$('#num').text();
var option = {
PRD_ID : getPrdId(),
PRD_NUM : num,
}
});
/*点击商品详情页商品角度图时埋点*/
$('#thumbs > .thumb-wrap').on('click', '.thumb', function(){
var $this = $(this);
var $index = $this.index()+1;
yas.givePoint('YB_GDS_PICTURE_C', {PRD_ID: getPrdId(), PIC_INDEX: $index});
});
/*点击商品分享渠道时埋点*/
$('.share-row .share-to i').on('click',function(){
var $this = $(this);
var $index = $this.index()+1;
yas.givePoint('YB_GDS_SHARE_TYPE_C', {PRD_ID: getPrdId(), TYPE_ID: $index});
});
$('.chose-color .colors').on('click', 'li', function(){
});
/*点击商品详情页尺寸时埋点*/
$('#sizes .size').on('click', 'li', function(){
var $this = $(this);
yas.givePoint('YB_GDS_SIZE_C', {PRD_ID: getPrdId(), SIZE: $this.data('name')});
});
/*点击商品详情页模块导航时埋点*/
$('.shoppingCar .shoppingCar-nav ul').on('click', 'li', function(){
var $this = $(this);
var $index = $this.index()+1;
yas.givePoint('YB_GDS_NAVIGATION_C', {PRD_ID: getPrdId(), NAV_INDE: $index});
});
/*点击商品评价模块中的全部/有图/图片时埋点*/
$('.cc-content .comment-tabs').on('click', 'h2', function(){
var $this = $(this);
var $index = $this.index()+1;
yas.givePoint('YB_GDS_REVIEWS_TAB_C', {PRD_ID: getPrdId(), POS_ID: $index});
});
$('.comments').on('click', '.img-preview .img-thumb', function() {
yas.givePoint('YB_GDS_REVIEWS_TAB_C', {PRD_ID: getPrdId(), POS_ID: 3});
});
/*点击商品详情页中的【我要咨询】时埋点*/
$('#submit-consult').click(function(){
yas.givePoint('YB_GDS_CONSULT_C', {PRD_ID: getPrdId()});
});
/*点击商品详情页底部店铺推荐和最近浏览TAB时埋点*/
$('.bottom-tab p').on('click', 'span', function(){
var $this = $(this);
var $index = $this.index()+1;
if( $index !== 3){
yas.givePoint('YB_GDS_RECOMMEND_REVIEW_TAB_C', {PRD_ID: getPrdId(), TAB_ID: $index});
}
});
/*点击商品详情页底部店铺推荐和最近浏览中的商品时*/
$('.recommend-content .img-list').on('click', 'li', function(){
var $this = $(this);
var relatedID = +$this.find('.goods-id').text();
var option = {
PRD_ID: getPrdId(),
RELATED_ID: relatedID,
TAB_ID : 1
};
yas.givePoint('YB_GDS_RECOMMEND_REVIEW_GOODS_C', option);
});
$('#latest-walk-goods').on('click', '.good', function(){
var $this = $(this);
var relatedID = +$this.find('a').attr('href').split('_')[1];
var option = {
PRD_ID: getPrdId(),
RELATED_ID: relatedID,
TAB_ID : 2
};
yas.givePoint('YB_GDS_RECOMMEND_REVIEW_GOODS_C', option);
});
// $('#package').click(function(){
// getPrdId();
// });
// 数据懒加载
dataLazyLoad.init({cls: '.datalazyload', threshold: 0});