list.js
32.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
/**
* 商品列表页
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/10/20
*/
var $ = require('yoho-jquery'),
Hammer = require('yoho-hammer'),
ellipsis = require('yoho-mlellipsis'),
lazyLoad = require('yoho-jquery-lazyload');
// 品牌页参数
var $brandHeader = $('#brand-header'),
$introBox = $('#intro-box');
var filter = require('plugin/filter');
var writeSearch = require('./write-search');
var tip = require('plugin/tip');
var loading = require('plugin/loading');
var $goodsContainer = $('#goods-container'),
$fsgc = $goodsContainer.children('.firstscreen-goods'),
$defaultgc = $goodsContainer.children('.default-goods'),
$ngc = $goodsContainer.children('.new-goods'),
$sgc = $goodsContainer.children('.sale-goods'),
$pgc = $goodsContainer.children('.price-goods'),
$dgc = $goodsContainer.children('.discount-goods'),
$newList = $('.new-list');
var winH = $(window).height();
window.$ = $;
var $input = $('#search-input input'),
$clear = $('#search-input .clear-input'),
$buriedpoint = $('.buriedpoint'),
$search = $('#search');
var shopId, sort, brand, outlets, app_type, age_level, msort, misort, coin, app_version, students, couponId;
var size, color, style, standard, gender, price, p_d, query, limited, specialoffer, specialsale_id, promotion;
// 默认筛选条件
var defaultOpt = require('common/query-param');
// 首屏加载标志
var firstScreen = $('.firstscreen-goods').children().size() > 0;
var $listNav = $('#list-nav'),
// 导航数据信息
navInfo = {
price: {
order: 1,
reload: true,
page: 0,
end: false
},
discount: {
order: 1,
reload: true,
page: 0,
end: false
},
default: {
order: 0,
reload: true,
page: 1,
end: false
},
new: {
order: 0,
reload: true,
page: 1,
end: false
},
sale: {
order: 0,
reload: true,
page: 1,
end: false
}
},
$pre = $listNav.find('.active'), // 纪录进入筛选前的active项,初始为选中项
searching,
btnIntroHammer,
introHammer,
brandColHammer;
var C_ID, RES_QTY, argument, optype, filext = {};
var category = $('#category-point').val();
var noResult = '<p class="no-result">未找到相关搜索结果</p>';
require('common');
C_ID = window._ChannelVary[window.cookie('_Channel')];
// 首屏无数据
if ($fsgc.children().length === 0) {
$goodsContainer.html(noResult);
}
ellipsis.init();
// pageCache 获取是否收藏
(function() {
if ($('.domain').val()) {
$.ajax({
url: '/product/index/brandFav',
data: {
domain: $('.domain').val()
},
dataType: 'json',
success: function(data) {
if (data.data) {
$('.brand-header .btn-col').addClass('coled');
}
},
error: function() {
tip.show('网络断开连接了~');
}
});
} else if ($('.shopId').val() && $('.shopId').val() !== 'undefined') {
$.ajax({
url: '/product/index/baseShopFav',
data: {
shopId: $('.shopId').val()
},
dataType: 'json',
success: function(data) {
if (data.collect) {
$('.brand-header .btn-col').addClass('coled');
}
},
error: function() {
tip.show('网络断开连接了~');
}
});
}
}());
// 搜索输入联动
function inputAction() {
var $searchAssociate = $('.search-associate');
var $icon = $('.search-icon');
var $searchItems = $('.search-items');
$input.on('input', function() {
if ($input.val() === '') {
$icon.css('color', '#b2b2b2');
$clear.addClass('hide');
$searchAssociate.html('');
$searchItems.show();
$searchAssociate.hide();
} else {
$icon.css('color', '#666');
$clear.removeClass('hide');
$searchAssociate.show();
}
// 联动搜索
$.ajax({
url: '/product/search/fuzzyDatas',
data: {
keyword: $input.val()
},
dataType: 'json',
success: function(data) {
var ajaxHtml = '';
var i;
if (data.length > 0) {
for (i = 0; i < data.length; i++) {
ajaxHtml += '<li><span class="keyword">' + data[i].keyword + '</span><span class="count">' +
data[i].count + ' items<i class="iconfont"></i></span></li>';
}
$searchAssociate.html(ajaxHtml);
$searchItems.hide();
} else {
$searchAssociate.html('');
}
$searchAssociate.find('li').on('touchend', function() {
$buriedpoint.val($(this).find('.keyword').html());
$search.closest('form').submit();
});
},
error: function() {
tip.show('网络断开连接了~');
}
});
});
}
inputAction();
$clear.on('touchend', function() {
$input.val('').trigger('input');
});
/**
* 手动触发搜索
*/
$search.on('touchend', function() {
$(this).closest('form').submit();
return false;
});
/**
* 获取url参数
*/
function getQueryString(name) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
var r = decodeURI(window.location.search).substr(1).match(reg);
if (r !== null) {
return decodeURIComponent(r[2]);
}
return null;
}
shopId = getQueryString('shop_id');
sort = getQueryString('sort');
outlets = getQueryString('outlets');
age_level = getQueryString('ageLevel');
app_type = getQueryString('app_type');
msort = getQueryString('msort');
misort = getQueryString('misort');
coin = getQueryString('coin');
app_version = getQueryString('app_version') || getQueryString('appVersion');
size = getQueryString('size');
color = getQueryString('color');
style = getQueryString('style');
standard = getQueryString('standard');
gender = getQueryString('gender');
price = getQueryString('price');
p_d = getQueryString('p_d');
brand = getQueryString('brand');
query = getQueryString('query');
limited = getQueryString('limited');
specialoffer = getQueryString('specialoffer');
specialsale_id = getQueryString('specialsale_id');
promotion = getQueryString('promotion');
students = getQueryString('students');
couponId = getQueryString('coupon_id');
if ($fsgc.children().length > 0) {
var fsgcgoods = [],
firstop,
firstyasparm = {};
$fsgc.find('.good-info').each(function() {
var fsgcgood = $(this).data('good-id');
if (fsgcgood) {
fsgcgoods.push(fsgcgood);
}
});
if (category) {
firstop = 'YB_CATEGORY_GOODS_LIST_L';
firstyasparm = Object.assign(firstyasparm, {
CATEGORY_ID: window.queryString.msort || window.queryString.sort || ''
});
} else {
firstop = 'YB_KEYWORD_GOODS_LIST_L';
firstyasparm = Object.assign(firstyasparm, {
KEYWORD: query || ''
});
}
firstyasparm = Object.assign(firstyasparm, {
C_ID: C_ID,
RES_QTY: $fsgc.children().length,
PRD_LIST: JSON.stringify(fsgcgoods).replace(/\[|\]/g, ''),
PAGE_NUM: 1,
FILTER_VALUE: '',
SORT_TYPE: 'default'
});
setTimeout(function() {
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: firstop,
param: JSON.stringify(firstyasparm)
}, true);
}
}, 200);
}
/**
* 筛选注册的回调,筛选子项点击后逻辑
* 需要执行search的场景:1.点选筛选项;2.relaod为true时切换导航;3.下拉加载
* @param opt {type, id}
*/
function search(opt) {
var setting = {},
ext,
att,
nav,
navType,
page,
$this,
$title,
params;
if (searching) {
return;
}
if (opt) {
// 筛选项变更则重置reload为true
for (att in navInfo) {
if (navInfo.hasOwnProperty(att)) {
navInfo[att].reload = true;
}
}
// 处理active状态
$listNav.children('.active').removeClass('active');
$pre.addClass('active');
switch (opt.type) {
case 'shop_id':
ext = {
shop_id: opt.id
};
break;
case 'gender':
ext = {
gender: opt.id
};
break;
case 'brand':
ext = {
brand: opt.id
};
break;
case 'sort':
ext = {
sort: opt.id
};
break;
case 'color':
ext = {
color: opt.id
};
break;
case 'ageLevel':
ext = {
age_level: opt.id
};
break;
case 'size':
ext = {
size: opt.id
};
break;
case 'price':
ext = {
price: opt.id
};
break;
case 'discount':
ext = {
discount: opt.id
};
break;
case 'outlets':
ext = {
outlets: opt.id
};
break;
case 'p_d':
ext = {
p_d: opt.id
};
break;
default:
break;
}
$.extend(filext, ext);
$.extend(defaultOpt, ext); // 扩展筛选项
}
// 导航类别
if ($pre.hasClass('new')) {
navType = 'new';
} else if ($pre.hasClass('price')) {
navType = 'price';
} else if ($pre.hasClass('discount')) {
navType = 'discount';
} else if ($pre.hasClass('default')) {
navType = 'default';
} else if ($pre.hasClass('sale')) {
navType = 'sale';
}
nav = navInfo[navType];
page = nav.page + 1;
if (nav.reload) {
page = 1;
} else if (nav.end) {
$('.search-divide').remove();
// 不需要重新加载并且数据请求结束
return;
}
params = {
type: navType,
order: nav.order,
page: page,
noLazy: true
};
if (shopId) {
params.shop_id = shopId;
}
if (age_level) {
params.age_level = age_level;
}
if (sort) {
params.sort = sort;
}
if (brand) {
params.brand = brand;
}
if (outlets) {
params.outlets = outlets;
}
if (app_type) {
params.app_type = app_type;
}
if (msort) {
params.msort = msort;
}
if (misort) {
params.misort = misort;
}
if (coin) {
params.coin = coin;
}
if (app_version) {
params.app_version = app_version;
}
if (size) {
params.size = size;
}
if (color) {
params.color = color;
}
if (style) {
params.style = style;
}
if (standard) {
params.standard = standard;
}
if (gender) {
params.gender = gender;
}
if (price) {
params.price = price;
}
if (p_d) {
params.p_d = p_d;
}
if (query) {
params.query = query;
}
if (limited) {
params.limited = limited;
}
if (specialoffer) {
params.specialoffer = specialoffer;
}
if (specialsale_id) {
params.specialsale_id = specialsale_id;
}
if (promotion) {
params.promotion = promotion;
}
if (students) {
params.students = students;
}
if (firstScreen) {
// 如果首屏加载了,则去掉12条记录
params.start = 12;
}
if (couponId) {
params.coupon_id = couponId;
}
$.extend(setting, defaultOpt, params);
searching = true;
loading.showLoadingMask();
argument = setting;
if (opt && opt.filtering) {
$fsgc.addClass('hide');
if (params.start) {
delete setting.start;
}
}
$.ajax({
type: 'GET',
url: location.protocol + '//m.yohobuy.com/product/search/search',
data: setting,
xhrFields: {
withCredentials: true
},
success: function(data) {
var num,
$container,
goodIds = [],
yasparm,
PRD_LIST;
switch (navType) {
case 'new':
$container = $ngc;
break;
case 'price':
$container = $pgc;
break;
case 'discount':
$container = $dgc;
break;
case 'default':
$container = $defaultgc;
break;
case 'sale':
$container = $sgc;
break;
default:
break;
}
yasparm = {
C_ID: C_ID,
PAGE_NUM: setting.page,
SORT_TYPE: setting.type,
FILTER_VALUE: opt ? JSON.stringify(filext).replace(/\{|\}|\"/g, '') : ''
};
if (category) {
optype = 'YB_CATEGORY_GOODS_LIST_L';
yasparm = Object.assign(yasparm, {
CATEGORY_ID: window.queryString.msort || window.queryString.sort || ''
});
} else {
optype = 'YB_KEYWORD_GOODS_LIST_L';
yasparm = Object.assign(yasparm, {
KEYWORD: setting.query || ''
});
}
if (data === '' || (data.list && data.list.length <= 0)) {
nav.end = true;
if (nav.reload) {
if (data.total === 0) {
$container.html(noResult);
}
yasparm = Object.assign(yasparm, {
PRD_LIST: '',
RES_QTY: 0
});
setTimeout(function() {
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: optype,
param: JSON.stringify(yasparm)
}, true);
}
}, 200);
}
} else {
if (nav.reload) {
$container.html(data);
num = $container.find('.good-info').length;
$('.search-divide').remove();
$container.append('<div class="search-divide">正在加载...</div>');
lazyLoad($container.find('.lazy'));
if (num < 12) {
$('.search-divide').remove();
}
RES_QTY = $container.find('.total').data('id');
$container.find('.good-info').each(function() {
var goodid = $(this).data('good-id');
if (goodid) {
goodIds.push(goodid);
}
});
PRD_LIST = JSON.stringify(goodIds).replace(/\[|\]/g, '');
yasparm = Object.assign(yasparm, {
PRD_LIST: PRD_LIST,
RES_QTY: RES_QTY
});
setTimeout(function() {
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: optype,
param: JSON.stringify(yasparm)
}, true);
}
}, 200);
} else {
num = $container.find('.good-info').length;
$('.search-divide').remove();
$container.append(data);
$container.append('<div class="search-divide">正在加载...</div>');
if (num < 12) {
$('.search-divide').remove();
}
if ($container.find('.total')[1]) {
$container.find('.total').eq(1).remove();
}
RES_QTY = $container.find('.total').data('id');
$container.find('.good-info:gt(' + (num - 1) + ')').each(function() {
var goodid = $(this).data('good-id');
if (goodid) {
goodIds.push(goodid);
}
});
PRD_LIST = JSON.stringify(goodIds).replace(/\[|\]/g, '');
yasparm = Object.assign(yasparm, {
PRD_LIST: PRD_LIST,
RES_QTY: RES_QTY
});
setTimeout(function() {
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: optype,
param: JSON.stringify(yasparm)
}, true);
}
}, 200);
// lazy good-infos who append in
lazyLoad($container.find('.good-info:gt(' + (num - 1) + ') .lazy'));
}
}
nav.reload = false;
nav.page = page;
searching = false;
loading.hideLoadingMask();
window.rePosFooter();
$('.good-detail-text .name').each(function() {
$this = $(this);
$title = $this.find('a');
$title[0].mlellipsis(2);
});
// 用于统计点击了商品列表的第几个商品,序号从1开始计算。
if (window._yas) {
switch (navType) {
case 'new':
window._yas(1 * new Date(), '1.0.16', 'yohobuy_m', window._ozuid,
'', $('.new-goods .good-info .good-detail-img .good-thumb'));
break;
case 'price':
window._yas(1 * new Date(), '1.0.16', 'yohobuy_m', window._ozuid,
'', $('.price-goods .good-info .good-detail-img .good-thumb'));
break;
case 'discount':
window._yas(1 * new Date(), '1.0.16', 'yohobuy_m', window._ozuid,
'', $('.discount-goods .good-info .good-detail-img .good-thumb'));
break;
case 'default':
window._yas(1 * new Date(), '1.0.16', 'yohobuy_m', window._ozuid,
'', $('.firstscreen-goods .default-goods .good-info .good-detail-img .good-thumb'));
break;
case 'sale':
window._yas(1 * new Date(), '1.0.16', 'yohobuy_m', window._ozuid,
'', $('.sale-goods .good-info .good-detail-img .good-thumb'));
break;
default:
break;
}
}
},
error: function() {
var $divide = $('.search-divide');
$divide.html('加载失败,点击重试');
$divide.one('click', function() {
$divide.html('正在加载...');
nav.reload = false;
searching = false;
search();
});
}
});
// 还原参数
params.start = 0;
firstScreen = false;
}
require('common/suspend-cart'); // 悬浮购物车
/* tar add 160914 */
if ($brandHeader.data('isbaseshop') === true) {
Object.assign(defaultOpt, {shop_id: $brandHeader.data('id')});
}
(function() {
var pars = {};
if (age_level) {
pars.age_level = age_level;
}
if (size) {
pars.size = size;
}
if (color) {
pars.color = color;
}
if (style) {
pars.style = style;
}
if (standard) {
pars.standard = standard;
}
if (gender) {
pars.gender = gender;
}
if (price) {
pars.price = price;
}
if (p_d) {
pars.p_d = p_d;
}
if (brand) {
pars.brand = brand;
}
if (sort) {
pars.sort = sort;
}
if (msort) {
pars.msort = msort;
}
if (misort) {
pars.misort = misort;
}
if (outlets) {
pars.outlets = outlets;
}
if (app_type) {
pars.app_type = app_type;
}
if (query) {
pars.query = query;
}
if (limited) {
pars.limited = limited;
}
if (specialoffer) {
pars.specialoffer = specialoffer;
}
if (specialsale_id) {
pars.specialsale_id = specialsale_id;
}
if (promotion) {
pars.promotion = promotion;
}
if (shopId) {
pars.shop_id = shopId;
}
if (couponId) {
pars.coupon_id = couponId;
}
$.extend(defaultOpt, pars);
$.ajax({
type: 'GET',
url: location.protocol + '//m.yohobuy.com/product/search/filter',
data: defaultOpt,
success: function(data) {
$goodsContainer.append(data);
// 初始化filter&注册filter回调
filter.initFilter({
fCbFn: search,
hCbFn: function() {
// 切换active状态到$pre上
$pre.addClass('active');
$pre.siblings('.filter').removeClass('active');
}
});
}
});
}());
lazyLoad($('.lazy'));
writeSearch.bindWirteLocal($('#search-form'));
// 导航栏点击逻辑说明:
// 1.点击非active项时切换active状态
// 2.价格和折扣active状态时继续点击切换排序
// 3.筛选无active时点击展开筛选面板
// 4.筛选有active时点击隐藏筛选面板并恢复点击筛选前active项的active状态
// 5.当前active为筛选并且点击其他项时,隐藏筛选面板
$listNav.bind('contextmenu', function() {
return false;
});
function newListHide() {
var $firstLi = $listNav.find('li.first-li-more');
if ($newList.hasClass('hide')) {
$firstLi.find('span.up').addClass('hide');
$firstLi.find('span.down').removeClass('hide');
} else {
$firstLi.find('span.down').addClass('hide');
$firstLi.find('span.up').removeClass('hide');
}
}
$newList.on('touchstart', 'li', function(e) {
var navType, bpIdData = $(this).attr('data-bp-id') || '',
$firstLiDom = $listNav.find('li.first-li-more');
e.preventDefault();
if ($(this).hasClass('new')) {
navType = 'new';
} else if ($(this).hasClass('default')) {
navType = 'default';
} else if ($(this).hasClass('sale')) {
navType = 'sale';
}
$newList.addClass('hide');
$firstLiDom.find('.nav-txt').text($(this).text());
$firstLiDom.attr('data-bp-id', bpIdData).addClass('active').siblings().removeClass('active');
$listNav.find('.first-li-more').removeClass('new default sale').addClass(navType);
$(document).trigger('shouldSendBpData', [bpIdData]);
newListHide();
if (navType !== 'default') {
$fsgc.addClass('hide');
}
if ($(this).hasClass('active')) {
return;
}
// 切换container显示
$goodsContainer.children('.container:not(.hide)').addClass('hide');
switch (navType) {
case 'new':
$ngc.removeClass('hide');
break;
case 'price':
$pgc.removeClass('hide');
break;
case 'discount':
$dgc.removeClass('hide');
break;
case 'default':
$defaultgc.removeClass('hide');
$fsgc.removeClass('hide');
break;
case 'sale':
$sgc.removeClass('hide');
break;
default:
break;
}
$pre = $firstLiDom;
search({filtering: true});
});
$(document).on('touchstart', function(e) {
if (!$newList.hasClass('hide') &&
$(e.target).closest('.new-list, li.first-li-more').length <= 0) {
$newList.addClass('hide');
newListHide();
}
});
$listNav.on('touchend touchcancel', function(e) {
var $this = $(e.target).closest('li'),
nav,
navType,
$active;
var bpIdData = $(this).find('.buriedpoint').attr('data-bp-id') || '';
if ($this.hasClass('first-li-more')) {
filter.hideFilter();
$newList.toggleClass('hide');
if ($this.hasClass('default')) {
$newList.find('li.default').addClass('active').siblings().removeClass('active');
} else if ($this.hasClass('new')) {
$newList.find('li.new').addClass('active').siblings().removeClass('active');
} else if ($this.hasClass('sale')) {
$newList.find('li.sale').addClass('active').siblings().removeClass('active');
}
newListHide();
return true;
}
// 最新li 列表
$newList.addClass('hide');
if ($this.hasClass('filter')) {
// 筛选面板切换状态
if ($this.hasClass('active')) {
filter.hideFilter();
// 点击筛选钱的active项回复active
$pre.addClass('active');
$this.removeClass('active');
} else {
$pre = $this.siblings('.active');
$pre.removeClass('active');
$this.addClass('active');
filter.showFilter();
}
} else {
if ($this.hasClass('new')) {
navType = 'new';
} else if ($this.hasClass('price')) {
navType = 'price';
} else if ($this.hasClass('discount')) {
navType = 'discount';
} else if ($this.hasClass('default')) {
navType = 'default';
} else if ($this.hasClass('sale')) {
navType = 'sale';
}
nav = navInfo[navType];
if ($this.hasClass('active')) {
// 最新无排序切换
if ($this.hasClass('new')) {
return;
}
if ($this.hasClass('price') || $this.hasClass('discount')) {
// 价格/折扣切换排序状态
$this.find('.icon > .iconfont').toggleClass('cur');
$pre = $this; // 更新pre为当前项
nav.reload = true; // 重置reload,HTML会被替换为逆序的HTML
nav.order = nav.order === 0 ? 1 : 0; // 切换排序
}
} else {
$active = $this.siblings('.active');
$pre = $this; // $pre为除筛选导航的其他导航项,若当前active的为筛选,则把$pre置为当前点击项
if ($active.hasClass('filter')) {
// 若之前active项为筛选,则隐藏筛选面板
filter.hideFilter();
} else {
// 切换container显示
$goodsContainer.children('.container:not(.hide)').addClass('hide');
switch (navType) {
case 'new':
$ngc.removeClass('hide');
break;
case 'price':
$pgc.removeClass('hide');
break;
case 'discount':
$dgc.removeClass('hide');
break;
case 'default':
$defaultgc.removeClass('hide');
$fsgc.removeClass('hide');
break;
case 'sale':
$sgc.removeClass('hide');
break;
default:
break;
}
}
$active.removeClass('active');
$this.addClass('active');
}
if (nav.reload) {
$(document).trigger('shouldSendBpData', [bpIdData]);
search({filtering: true});
}
}
});
function scrollHandler() {
// 当scroll到1/2$goodsContainer高度后继续请求下一页数据
if ($(window).scrollTop() + winH >
$(document).height() - 0.5 * $goodsContainer.height()) {
search();
}
}
// srcoll to load more
$(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
if ($brandHeader.length > 0) {
// 品牌介绍
btnIntroHammer = new Hammer($brandHeader.children('.btn-intro')[0]);
btnIntroHammer.on('tap', function() {
$introBox.removeClass('hide');
// 防止混合scroll发生
$('body').addClass('overflow-hidden');
});
// 关闭品牌介绍
introHammer = new Hammer(document.getElementById('intro-box'));
introHammer.on('tap', function(e) {
var $this = $(e.target);
e.srcEvent.preventDefault();
// 关闭品牌介绍box
if ($this.closest('#brand-intro').length === 0 || $this.hasClass('close-intro')) {
$introBox.addClass('hide');
$('body').removeClass('overflow-hidden');
}
});
// 品牌收藏
brandColHammer = new Hammer($brandHeader.children('.btn-col')[0]);
brandColHammer.on('tap', function(e) {
var $this = $(e.target).closest('.btn-col');
var id = $brandHeader.data('id'),
opt;
if ($this.hasClass('coled')) {
opt = 'cancel';
} else {
opt = 'ok';
}
$.ajax({
type: 'GET',
url: location.protocol + '//m.yohobuy.com/product/opt/favoriteBrand',
data: {
id: id,
opt: opt,
type: $brandHeader.data('isbaseshop') ? 'shop' : 'brand'
},
xhrFields: {
withCredentials: true
},
success: function(data) {
if (data.code === 200) {
$this.toggleClass('coled');
// 提示
if (opt === 'ok') {
tip.show('添加收藏成功');
} else {
tip.show('取消收藏成功');
}
} else if (data.code === 400) {
location.href = data.data;// 未登录跳转登录页
} else {
tip.show(data.message);
}
},
error: function() {
tip.show('网络断开连接了~');
}
});
});
}
var initialData = false;
$(window).one('scroll', function() {
// 初始请求最新第一页数据
if (!initialData) {
search();
initialData = true;
}
});
$listNav.on('touchstart', 'li', function() {
$listNav.find('li').removeClass('bytouch');
$(this).addClass('bytouch');
}).on('touchend touchcancel', 'li', function() {
$listNav.find('li').removeClass('bytouch');
});
$('#goods-container').on('click', '.good-info', function() {
var PRD_ID = $(this).data('good-id'),
PRD_NUM = $(this).index(),
FILTER_VALUE = filext ? JSON.stringify(filext).replace(/\{|\}|\"/g, '') : '',
yasparms,
firstType;
if ($(this).parent().hasClass('firstscreen-goods')) {
firstType = 'default';
PRD_NUM = PRD_NUM + 1;
} else if ($(this).parent().hasClass('default-goods')) {
PRD_NUM = PRD_NUM + 12;
}
yasparms = {
C_ID: C_ID,
PRD_ID: PRD_ID,
PRD_NUM: PRD_NUM,
PAGE_NUM: Math.ceil(PRD_NUM / 60),
FILTER_VALUE: FILTER_VALUE,
SORT_TYPE: argument ? argument.type : firstType
};
if (category) {
optype = 'YB_CATEGORY_GOODS_LIST_C';
yasparms = Object.assign(yasparms, {
CATEGORY_ID: window.queryString.msort || window.queryString.sort || ''
});
} else {
optype = 'YB_KEYWORD_GOOS_LIST_C';
yasparms = Object.assign(yasparms, {
KEYWORD: argument ? argument.query : query
});
}
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: optype,
param: JSON.stringify(yasparms)
}, true);
}
});
var fuckNum = $('.good-info').length;
fuckNum < 12 && $('.search-divide').remove();