index.js
27.3 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
//index.js
let plugin = requirePlugin("yoho-utils");
import { parseBrandListData } from '../../utils/productList';
import { parseHomeList } from '../../utils/newHome';
import { getChannelCode, getGenderCode, getRecPosCode, getRecommandContentCode, getResourceCode,getHomeContentCode} from '../../utils/home';
import objectAssign from '../../vendors/object-assign';
import { shouldDiscardTap, getGoodDetailParam, getImageUrl, formatImageUrl,getGuangType, getYHStorageSync} from '../../utils/util';
import {
JUMP_BRAND,
JUMP_DETAIL,
JUMP_PRODUCTPOOL,
jumpByUrl
} from '../../libs/urlRoute';
import { parse } from '../../vendors/query-string';
var mta = require('../../vendors/mta_analysis.js')
var touchStartLocationY=0;
// 1、小程序男首 305e0a7a4aba32b08c6dd6dc5da47fa9
// 2、小程序女首 5d9665e6a0a8ec5b2f0c126b36364d24
import {
logEvent,
YB_MAIN_EVENT,
YB_PAGE_OPEN_L,
YB_MAIN_TAB_C,
YB_SHARE_RESULT_L,
YB_SEARCH_C,
YB_SCAN_CODE_SUCCESS,
YB_SCAN_CODE_C,
YB_MAIN_STROLL_TAB_C,
} from '../../libs/analytics.js'
import { getQRCodeSource } from '../../libs/miniQRCodeRoute.js'
import { decodePhoneNumber, getUnionID, decodeUnionId, openAuthorizeSettings } from '../../utils/login';
let CHANNEL = "gender_channel"
//获取应用实例
let app = getApp()
const { extend, Toast } = require('../../vendors/zanui/index');
const windowWidth = app.globalData.systemInfo.windowWidth;
const windowHeight = app.globalData.systemInfo.windowHeight;
const pixelRatio = app.globalData.systemInfo.pixelRatio;
let activityItemWidth = 186;
let activityItemHeight = 237;
let PV_ID = new Date().getTime() + '';
Page(extend({},Toast,{
data: {
currentDate:null,
newFocusImg:[],//顶部轮播图集合
lastTapTimeStamp: 0,
navOpacity: 0.0,
windowWidth,
windowHeight,
// bannerWidth,
// bannerHeight,
//是否展开channel选择框
channelSelect:false,
//顶部Tab
selectedChannel: 'boy',
homelist:[],
newChannels:{
boy:{
data:[],//列表list
isLoading: false,
recommend: {
isLoading: false,
error: null,
data: null,
},
},
girl:{
data:[],
isLoading: false,
recommend: {
isLoading: false,
error: null,
data: null,
},
}
},
isShowIndicator: false,
newCustomer: false,
fixedFilter: false,
currentFixedFilterIndex: 0,
homeTabs: [],
guangList: {
page: 0,
sort_id: 0,
limit: 20,
list: [],
isLast: false,
},
dialogSrc: null,
dialogUrl: null,
// isShowLogin: true,
// openType: 'getUserInfo',
},
onLoad: function (e) {
//测试二维码进
if (e && e.q) {
let decodeQ = decodeURIComponent(e.q);
let qrParams = decodeQ.split('?')[1]
let obj = parse(qrParams);
let unionType = obj.union_type ? obj.union_type : '';
if (unionType) {
app.updateUnionType(unionType);
}
if (obj && obj.source == 'inviteNew') {
wx.setStorageSync('source', obj.source)
if (app.globalData.userInfo.uid) {
this.loadElement(e);
} else {
this.loginAndRegisterTapped();
}
}
}
if (e && e.scene && e.scene.length == 32) {
let code = e.scene;
getQRCodeSource(code).then(json => {
//解析渠道号
let unionType = json.union_type ? json.union_type : '';
if (unionType) {
app.updateUnionType(unionType);
}
if (json && json.source == 'inviteNew') {
wx.setStorageSync('source', json.source)
if (app.globalData.userInfo.uid) {
this.loadElement(e);
} else {
this.loginAndRegisterTapped();
}
} else {
this.loadElement(e);
}
}).catch(error => {
});
} else {
this.loadElement(e);
}
},
loadElement(e) {
mta.Page.init();
// this.getLastChannel();
// this.fetchNewHomeData();
this.getHomeTabList();
this.getGuangList(false);
//超过一天
var currentDate = new Date();
var pretimestamp = this.getStorage("pretimestamp");
var preDate;
if (pretimestamp) {
preDate = new Date(pretimestamp);
}
if (!preDate
|| currentDate.getFullYear() !== preDate.getFullYear()
|| currentDate.getMonth() !== preDate.getMonth()
|| currentDate.getDate() !== preDate.getDate()) {
this.setData({
currentDate,
});
this.showIndexDialog();
}
new app.WeToast;
let jumpType = e.jumpType;
if (jumpType == JUMP_BRAND) {
let brandId = e.brandId;
let brandName = e.brandName;
if (brandId != '' && brandName != '')
wx.navigateTo({
url: '../goodsList/brand?brandId=' + brandId + '&brandName=' + brandName + '&page_name=' + 'home' + '&page_param=' + ''
});
} else if (jumpType == JUMP_DETAIL) {
let productSkn = e.productSkn;
if (productSkn != '') {
wx.navigateTo({
url: '../goodsDetail/goodsDetail?productSkn=' + productSkn + '&page_name=' + 'home' + '&page_param=' + ''
});
}
} else if (jumpType == JUMP_PRODUCTPOOL) {
let productPool = e.productPool;
if (productPool != '') {
wx.navigateTo({
url: '../goodsList/productPool?productPool=' + productPool + '&page_name=' + 'home' + '&page_param=' + ''
});
}
}
this.removeStorage('newCustomer');
},
//跳转到登录页面
loginAndRegisterTapped: function (needBind) {
let that = this;
let app = getApp()
if (wx.getSetting) {
wx.getSetting({
success: (res) => {
if (res && res.authSetting && res.authSetting["scope.userInfo"] !== null && res.authSetting["scope.userInfo"] !== undefined && res.authSetting["scope.userInfo"] === false) {
wx.showModal({
title: '',
content: '检测到您未打开微信用户信息授权,开启后即可进行登录',
confirmText: "去开启",
confirmColor: "#000000",
success: function (res) {
if (res.confirm) {
wx.openSetting({
success: (res) => {
// console.log(res.authSetting["scope.userInfo"])
if (res.authSetting["scope.userInfo"] !== null && res.authSetting["scope.userInfo"] !== undefined && res.authSetting["scope.userInfo"] === true) {
getUnionID(app.getWechatThirdSession(), function (response) {
// console.log(response)
if (response) {
}
})
}
}
})
} else {
wx.redirectTo({
url: '../bindPhoneNumber/bindPhoneNumber',
})
}
}
})
} else {
wx.redirectTo({
url: '../bindPhoneNumber/bindPhoneNumber',
})
}
}
})
} else {
wx.showModal({
title: '提示',
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
})
}
},
onShow:function (){
var pages = getCurrentPages()
var currentPage = pages[pages.length - 1]
var url = currentPage.route
let params = {
PAGE_NAME: 'home',
PAGE_PARAM: '',
FROM_PAGE_NAME: '',
FROM_PAGE_PARAM: '',
PV_ID: PV_ID,
PAGE_PATH: url
};
logEvent(YB_PAGE_OPEN_L, params);
logEvent(YB_MAIN_TAB_C, {TAB_ID:1});
this.setData({
newCustomer: this.getStorage('newCustomer')
});
try{
this.dialog = this.selectComponent("#dialog");
}catch(error){}
},
onShareAppMessage: function (res) {
let param = {
FROM: res.from,
SHARE_RESUIL: 0,
TITLE: 'Yoho!Buy有货-潮流购物逛不停',
PATH: '/pages/index/index',
}
// 用户点击右上角分享
return {
title: param.TITLE, // 分享标题
desc: '精选1400+全球潮流品牌,明星潮牌和新锐原创品牌每日上新,100%正品行货。', // 分享描述
path: param.PATH, // 分享路径
success: function (res) {
param.SHARE_RESUIL = 1
logEvent(YB_SHARE_RESULT_L, param);
},
fail: function (res) {
param.SHARE_RESUIL = 2
logEvent(YB_SHARE_RESULT_L, param);
}
}
},
onPullDownRefresh: function () {
wx.stopPullDownRefresh();
// this.getLastChannel();
// this.fetchNewHomeData(true);
this.getHomeTabList();
this.getGuangList(false);
},
onPageScroll: function (event) {
var { scrollTop } = event;
var isShow = scrollTop > windowHeight * 2 ? true : false;
if (isShow != this.data.isShowIndicator) {
this.setData({
isShowIndicator: isShow
});
}
let pixelRatio = windowWidth/750;
let that = this;
wx.createSelectorQuery().select('#fixedFilterViewC').boundingClientRect(function (rect) {
if(rect) {
var y = rect.top / pixelRatio;
let fixedFilter = y >= 88 + 4 ? false : true;
if (fixedFilter != that.data.fixedFilter){
that.setData({
fixedFilter
});
}
}
}).exec()
},
//回到顶部
backToTop: function () {
wx.pageScrollTo({
scrollTop: 0,
})
},
backToIndex: function (y) {
wx.pageScrollTo({
scrollTop: y,
duration: 300,
})
},
//是否展开频道选择框
selectChannel:function(e){
let _selectChannel = this.data.channelSelect;
_selectChannel = !_selectChannel;
this.setData({ channelSelect: _selectChannel})
},
hiddenChannel:function(){
this.setData({
channelSelect:false,
})
},
//首页频道选择
channelSelected: function (event) {
// console.log(event)
let selectedChannel = event.target.dataset.type;
if (selectedChannel == this.data.selectedChannel) {
return;
}
app.globalData.selectedChannel = selectedChannel;
if (selectedChannel === 'boy') {
app.globalData.cid = '1'
}
else if (selectedChannel === 'girl') {
app.globalData.cid = '2'
}
let C_ID = app.globalData.cid;
let param={
C_ID,
}
logEvent('YB_MAIN_CHANNEL_C',param);
this.setData({
selectedChannel,
channelSelect:false
});
this.fetchNewHomeData();
this.getGuangList(false);
wx.setStorage({
key: CHANNEL,
data: this.data.selectedChannel,
})
this.backToTop();
},
jumpToYohood:function(event){
jumpByUrl("https://ad.yoho.cn/html5/2018/yohood/index.html?share_id=5381&title=YOHOOD2018&openby:yohobuy={\"action\":\"go.h5\",\"params\":{\"title\":\"YOHOOD2018\",\"share_id\":5381,\"url\":\"https://ad.yoho.cn/html5/2018/yohood/index.html?share_id=5381&title=YOHOOD2018\"}}")
this.setData({
channelSelect: false
});
},
//获取上次切换的频道 默认显示上次频道
getLastChannel: function () {
let lastChannel = getYHStorageSync(CHANNEL,'index');
if (lastChannel && (lastChannel === 'boy' || lastChannel === 'girl')) {
app.globalData.selectedChannel = lastChannel;
if (lastChannel === 'boy') {
app.globalData.cid = '1'
}
else if (lastChannel === 'girl') {
app.globalData.cid = '2'
}
this.setData({
selectedChannel: lastChannel
})
}
let C_ID = app.globalData.cid ? app.globalData.cid : '1';
let param = {
C_ID,
}
logEvent('YB_MAIN_CHANNEL_C', param);
},
jumpByRule: function (e) {
let jumpUrl = e.currentTarget.dataset.jump_rule;
if (!jumpUrl) {
return;
}
let F_ID = e.currentTarget.dataset.f_id;//楼层id
let I_INDEX = e.currentTarget.dataset.f_inindex + 1//楼层内index
let F_INDEX = e.currentTarget.dataset.f_index + 1//楼层序号
let F_NAME = e.currentTarget.dataset.f_name;//楼层名称
let param = {
F_ID, I_INDEX, F_INDEX, F_NAME,
F_URL: jumpUrl,
}
logEvent('YB_MAIN_EVENT', param);
jumpByUrl(jumpUrl, 'home');
},
//获取新首页数据
fetchNewHomeData: function (force) {
var channel = this.data.selectedChannel;
let newChannels = this.data.newChannels;
let currentData = newChannels[channel];
if (currentData && currentData.data && currentData.data.length > 0 && !force) {
this.setHomeList();
return;
}
let cotentCode = getHomeContentCode(channel);
let gender = getGenderCode(channel);
let yh_channel = getChannelCode(channel);
if (!force) {
this.setLoadingHomeData(true);
}
let param = {
content_code: cotentCode,
gender,
yh_channel,
page: 1,
limit: 10,
fromPage: 'aFP_Home',
union_id: plugin.getGlobalDataByKey('WXUnion_ID')
}
plugin.get({
url: '/operations/api/v5/resource/home',
data: param
}).then(json => {
this.setLoadingHomeData(false);
if (json && json.code && json.code == 200) {
let homeList = json.data.list;
homeList = parseHomeList(homeList, windowWidth, windowHeight, activityItemWidth, activityItemHeight);
if (!homeList || homeList.length <= 0) {
this.wetoast.toast({
title: json.message,
titleClassName: 'wetoast-title',
duration: 1500
});
}
let newChannels = this.data.newChannels;
let currentData = newChannels[channel];
currentData.data = homeList;
newChannels[channel] = currentData;
this.setData({
newChannels: newChannels
})
this.setHomeList(force);
} else {
this.setHomeList(force);
this.wetoast.toast({
title: json.message,
titleClassName: 'wetoast-title',
duration: 1500
});
}
})
.catch(error => {
this.setLoadingHomeData(false);
this.setHomeList(force);
this.wetoast.toast({
title: error.message,
titleClassName: 'wetoast-title',
duration: 1500
});
})
},
setLoadingHomeData: function (isLoading) {
let channel = this.data.selectedChannel;
let _newChannels = this.data.newChannels;
let currentData = _newChannels[channel];
if (currentData) {
currentData.isLoading = isLoading;
}
this.setData({
newChannels: _newChannels,
})
},
//可优化
setHomeList: function (force) {
let channel = this.data.selectedChannel;
let newChannels = this.data.newChannels;
let currentData = newChannels[channel];
if (currentData && currentData.data) {
this.setData({
homelist: currentData.data,
})
}
this.fetchRecommend(force);
},
// 清除storage
removeStorage: function(key) {
try {
wx.removeStorageSync(key);
} catch (e) {
// console.log(e);
}
},
// 获取storage
getStorage: function(key) {
return getYHStorageSync(key,'index');
},
// 设置storage
setStorage: function(key, value) {
try {
wx.setStorageSync(key, value);
} catch (e) {
// console.error(e);
}
},
//请求(男生、女生)猜你喜欢数据
fetchRecommend: function (force) {
let currentChannel = this.data.selectedChannel;
let currentChannelData = this.data.newChannels[currentChannel];
let recommend = currentChannelData.recommend;
if (recommend.data && recommend.data.length > 0 && !force) {
return;
}
let gender = getGenderCode(currentChannel);
let yh_channel = getChannelCode(currentChannel);
let param = {};
let content_code = getRecommandContentCode(currentChannel);
let rec_pos = getRecPosCode(currentChannel);
param = {
method: 'app.search.newLast7day',
content_code,
gender,
yh_channel,
rec_pos,
page: 1,
limit: 50,
};
let newChannelData = objectAssign(currentChannelData, { recommend: objectAssign(recommend, { isLoading: true, }) });
let newChannels = this.data.newChannels;
newChannels[currentChannel] = newChannelData;
this.setData({
newChannels: newChannels,
});
plugin.get({data: param})
.then(json => {
if (!json || !json.code || json.code != 200) {
let currentChannel = this.data.selectedChannel;
let currentChannelData = this.data.newChannels[currentChannel];
let newChannelData = objectAssign(currentChannelData, { recommend: objectAssign(recommend, { isLoading: false, error: { code: json.code, message: json.message } }) });
let newChannels = this.data.newChannels;
newChannels[currentChannel] = newChannelData;
this.setData({
newChannels: newChannels,
});
return;
}
let data = json.data.product_list;
data = parseBrandListData(data);
let currentChannel = this.data.selectedChannel;
let currentChannelData = this.data.newChannels[currentChannel];
let newChannelData = objectAssign(currentChannelData, { recommend: objectAssign(recommend, { isLoading: false, data }) });
let newChannels = this.data.newChannels;
newChannels[currentChannel] = newChannelData;
this.setData({
newChannels: newChannels,
});
})
.catch(error => {
let currentChannel = this.data.selectedChannel;
let currentChannelData = this.data.newChannels[currentChannel];
let newChannelData = objectAssign(currentChannelData, { recommend: objectAssign(recommend, { isLoading: false, error }) });
let newChannels = this.data.newChannels;
newChannels[currentChannel] = newChannelData;
this.setData({
newChannels: newChannels,
});
});
},
// 获取列表数据
getGuangList: function (isLoadMore) {
let that = this;
let guangList = this.data.guangList;
if (isLoadMore == false) {
guangList.page = 0;
guangList.sort_id = 0;
guangList.limit = 20;
guangList.list = [];
guangList.isLast = false;
that.setData({
guangList,
});
}
let isLast = guangList.isLast;
if (isLast) {
return;
}
let param = {
page: guangList.page + 1,
gender: app.globalData.selectedChannel === 'boy' ? '1,3' : '2,3',
sort_id: guangList.sort_id,
limit: guangList.limit,
uid: app.getUid(),
};
plugin.get({
url: '/guang/api/v2/article/getList',
data: param
}).then(json => {
if (json && json.code == 200) {
let artList = json.data.list.artList;
let page = json.data.page;
let totalPage = json.data.totalPage;
for(var i = 0; i<artList.length; i++){
let item = artList[i];
item.src = item.src.replace(/{width}/g, 345 * pixelRatio).replace(/{height}/g, 216 * pixelRatio).replace('{mode}', 2);
item.type = getGuangType(item.url);
guangList.list.push(item);
}
guangList.page = page;
guangList.isLast = totalPage == page;
that.setData({
guangList,
});
}
})
.catch(error => {
// console.log(error)
})
},
getHomeTabList: function () {
let that = this;
that.setData({
homeTabs : [],
currentFixedFilterIndex: 0
});
let param = {
method: 'app.resource.tab',
};
plugin.get({
data: param
}).then(json => {
if (json && json.code == 200) {
let list = json.data;
let homeTabs = [];
let currentFixedFilterIndex = 0;
for (var i = 0; i < list.length;i++) {
let item = list[i];
if (item.showFlag == 1 && (item.type == 1 || item.type == 2)){
homeTabs.push(item);
}
}
for (var i = 0; i < homeTabs.length; i++) {
let item = homeTabs[i];
if (item.defaultFlag == 1) {
currentFixedFilterIndex = i;
}
}
setTimeout(function () {
that.setData({
homeTabs,
currentFixedFilterIndex
});
}, 1000);
}
})
.catch(error => {
// console.log(error)
})
},
onReachBottom: function () {
let currentFixedFilterIndex = this.data.currentFixedFilterIndex;
let homeTabs = this.data.homeTabs;
let item = homeTabs.length > currentFixedFilterIndex ? homeTabs[currentFixedFilterIndex] : '';
if (item && item.type == 1) {
this.getGuangList(true);
}
},
tappedGuangArtContent: function (event) {
let articleId = event.currentTarget.dataset.articleId;
let jumpUrl = '/page/subPackage/pages/guang/detail?id=' + articleId + '&page_name=' + 'home' + '&page_param=' + '';
wx.navigateTo({
url: jumpUrl
});
let TAB_ID = parseInt(this.data.currentFixedFilterIndex) + 1;
let I_INDEX = event.currentTarget.dataset.f_inindex + 1//楼层内index
let param = {
TAB_ID,
I_INDEX,
F_URL: jumpUrl,
}
logEvent('YB_MAIN_EVENT', param);
},
fixedFilterTapped: function (event) {
let currentFixedFilterIndex = event.currentTarget.dataset.type;
if (currentFixedFilterIndex != this.data.currentFixedFilterIndex) {
let params = {
TAB_ID: parseInt(currentFixedFilterIndex) + 1,
};
logEvent(YB_MAIN_STROLL_TAB_C, params);
}
this.setData({ currentFixedFilterIndex });
let that = this;
wx.createSelectorQuery().select('#fixedFilterViewC').boundingClientRect(function (rect) {
let top0 = rect.top;
if (top0 <= 44) {
wx.createSelectorQuery().select('#fixedFilterViewCTop').boundingClientRect(function (rects) {
let pixelRatio = windowWidth / 750;
var offset = 88 * pixelRatio;
let top1 = rects.top;
let y = top0 - top1 - offset;
that.backToIndex(y);
}).exec()
}
}).exec()
},
productCellTapped: function(event) {
let data = event.currentTarget.dataset.productItem;
let productSkn = data.product_skn;
let jumpUrl = '../goodsDetail/goodsDetail?productSkn=' + productSkn + '&page_name=' + 'home' + '&page_param=' + '';
wx.navigateTo({
url: jumpUrl
});
let TAB_ID = parseInt(this.data.currentFixedFilterIndex) + 1;
let I_INDEX = event.currentTarget.dataset.f_inindex + 1//楼层内index
let param = {
TAB_ID,
I_INDEX,
F_URL: jumpUrl,
}
logEvent('YB_MAIN_EVENT', param);
},
brandCellTapped: function (event) {
let data = event.currentTarget.dataset.productItem;
let shop_id = data.shop_id;
let shop_name = data.shop_name;
wx.navigateTo({
url: '../goodsList/brandStore?shop_id=' + shop_id + '&shop_name' + shop_name + '&page_name=' + 'home' + '&page_param=' + ''
});
},
//wx.scanCode
scanCodeTapped: function (event){
logEvent(YB_SCAN_CODE_C, {});
wx.scanCode({
success: (res) => {
let url = res.path;
if (url) {
if (url.indexOf('page/subPackage') !== -1) {
url = '/' + url
} else {
url = url.replace(/pages/g, "..");
}
wx.navigateTo({
url: url,
});
} else {
url = res.result;
let hasOpenby = url.indexOf('openby:yohobuy=');
if (hasOpenby < 0) {
if (url.startsWith('https://m.yohobuy.com/product') || url.startsWith('http://m.yohobuy.com/product') || url.startsWith('https://o.yohobuy.com/mp') || url.startsWith('https://o.yohobuy.com/mp')) {
let ecodeUrl = encodeURIComponent(url);
wx.navigateTo({
url: '../goodsDetail/goodsDetail?q=' + ecodeUrl
});
} else if (url.startsWith('https://m.yohobuy.com/shop') || url.startsWith('http://m.yohobuy.com/shop')) {
wx.navigateTo({
url: '../goodsList/brandStore?q=' + url
});
}
} else {
jumpByUrl(url, 'home');
}
}
let params = {
PAGE_PATH: url,
};
logEvent(YB_SCAN_CODE_SUCCESS, params);
},
fail: (res) => {
// console.log('zjj-fail',res);
} ,
complete: (res) => {
//console.log('zjj-complete',res);
}
})
},
//事件处理函数
searchTapped: function (event) {
if (shouldDiscardTap(event.timeStamp, this.data.lastTapTimeStamp)) {
return;
}
let params = {
SEARCH_POS: 1,
};
logEvent(YB_SEARCH_C, params);
this.setData({ lastTapTimeStamp: event.timeStamp });
let param = {};
wx.navigateTo({
url: '../search/search?' + 'page_name=' + 'home' + '&page_param=' + '¶m=' + param
})
},
//活动商品点击
activityItemTapped: function (e) {
let F_ID = e.currentTarget.dataset.f_id;//楼层id
let I_INDEX = e.currentTarget.dataset.f_inindex + 1//楼层内index
let F_INDEX = e.currentTarget.dataset.f_index + 1//楼层序号
let F_NAME = e.currentTarget.dataset.f_name;//楼层名称
let param = {
F_ID, I_INDEX, F_INDEX, F_NAME,
}
logEvent('YB_MAIN_EVENT', param);
wx.navigateTo({
url: '../goodsDetail/goodsDetail?productSkn=' + e.currentTarget.dataset.skn + '&page_name=home&page_param='
});
},
//活动商品内“更多”点击
moreActivityItemTapped: function (event) {
let data = event.currentTarget.dataset;
if (data.type == 'go.list' && data.url) {
let param = getGoodDetailParam(data.url)
wx.navigateTo({
url: '../goodsList/activtyDetail' + '?title=' + data.title + '¶m=' + param + '&bannerUrl=' + data.src + '&page_name=home&page_param='
})
}
},
groupItemTapped: function (e) {
let activityId = e.currentTarget.dataset.activity_id;
let productSkn = e.currentTarget.dataset.skn;
// console.log(productSkn)
wx.navigateTo({
url: '/pages/groupPurchase/groupPurchaseDetail?productSkn=' + productSkn + '&activityId=' + activityId + '&page_name=home',
});
},
/**
* 首页资源位dialog
*/
showIndexDialog: function(){
var app = getApp();
let that = this;
let content_code = "0ddd512196d6eb4a571dc3281e0b2692";
let param = {
content_code,
}
plugin.get({
url: '/operations/api/v5/resource/get',
data: param
}).then(json => {
// console.log(json);
if (json && json.code && json.code == 200 && json.data[0] && json.data[0].data[0] && json.data[0].data[0].url){
this.setStorage('pretimestamp', Date.parse(that.data.currentDate));
that.setData({
dialogSrc: formatImageUrl(json.data[0].data[0].src, 340 * app.globalData.systemInfo.pixelRatio, 340 * app.globalData.systemInfo.pixelRatio,2),
dialogUrl: json.data[0].data[0].url,
});
that.setStorage('pretimestamp', Date.parse(that.data.currentDate));
that.dialog.showDialog();
}
}).catch(error => { });
},
//formId上报
formSubmitFromSwitchGender: function (e){
// console.log('----formSubmit---',e.detail.formId);
let formId = e.detail.formId;
plugin.postFormId({
formId,
position: "2"
})
},
formSubmitFromGuangArt: function (e){
// console.log('----formSubmit---',e.detail.formId);
let formId = e.detail.formId;
plugin.postFormId({
formId,
position: "3"
})
}
})
)