assist.js
27.6 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
import { API_HOST, SERVICE_HOST } from '../../libs/config';
import { GET, POST } from '../../libs/request';
import { getChannelCode, getGenderCode, getRecPosCode, getRecommandContentCode } from '../../utils/home';
import { parseBrandListData } from '../../utils/productList';
import { decodePhoneNumber, wechatLoginAction, getUnionID, decodeUnionId,openAuthorizeSettings, listen } from '../../utils/login';
import { shouldDiscardTap, getYHStorageSync} from '../../utils/util';
import {
logEvent,
YB_PAGE_OPEN_L,
YB_INVITE_C,
YB_INVITE_PICTURE_C,
YB_INVITE_PICTURE_SAVE_C,
YB_SHARE_PICTURE_RESULT_L,
YB_INVITE_FRIEND_C,
YB_ASSIST_C,
YB_ASSIST_LAUNCH_C,
YB_SHARE_RESULT_L,
} from '../../libs/analytics.js'
let timer;
let app = getApp();
const shareViewWidth = 540;
const shareViewHeight = 961;
const windowWidth = app.globalData.systemInfo.windowWidth;
const windowHeight = app.globalData.systemInfo.windowHeight;
const SC = windowHeight / shareViewHeight;
const { Toast, extend } = require('../../vendors/zanui/index');
let PV_ID = new Date().getTime() + '';
Page(extend({},Toast,{
/**
* 页面的初始数据
*/
data: {
windowWidth,
windowHeight,
from_page_name: '',
from_page_param: '',
current_page_name: 'assist',
current_page_param: '',
lackNum:1,
assistId:'',
assistUid:'',
formatTime: {},
assistUserInfo: [{ headIco:'http://img12.static.yhbimg.com/article/2018/02/01/14/022a34501042bf87c152d839a850336849.png'}],
needAssistArray:[],
dialogContent:'',
dialogConfirm:'',
dialogConfirmDetail:'',
dialogShowTwoButton:false,
needGetPhoneNumber:false,
hideHelpButton:false,
showInviteButton:false,
recommdData: [],
goAssist:false,
isSelfRegister:true,
dialogIsShowParticipate:false,
formId:'',
shareTitle:'帮我拆红包,听说最多有100元现金券哟!',
sharerData: {
isShow: false,
showType: 1, // 1 : 分享页 2 : 截图页
shareViewWidth: shareViewWidth,
shareViewHeight: shareViewHeight,
windowWidth,
windowHeight,
SC: SC,
qrCode: '',
headerUrl: '',
},
},
onLoad: function (options) {
// console.log("options:",options)
let app = getApp()
let that = this
let assistId = '';
that.dialog = that.selectComponent("#dialog");
if (options && options.assistId && options.assistId!=='undefined'){
assistId = options.assistId
that.setData({
assistId
})
}
if (options && options.scene && options.scene.length > 0) {
var scene = decodeURIComponent(options.scene)
if (scene.length > 0) {
assistId = scene;
}
// console.log("assistId:", assistId)
that.setData({
assistId
})
}
new app.WeToast();
let from_page_name = options.page_name ? options.page_name : '';
let from_page_param = options.page_param ? options.page_param : '';
let current_page_param = assistId;
that.setData({
hasUnionID: app.globalData.WXUnion_ID !== null && app.globalData.WXUnion_ID !== '' && app.globalData.WXUnion_ID !== undefined ? true : false,
from_page_name,
from_page_param,
current_page_param,
})
//判断如果没有活动id也没有uid,弹框提示并获取用户信息
if(!app.getUid()){
that.setData({
dialogNeedGetPhoneNumber: true,
needGetPhoneNumber:true,
})
}
if (!assistId && !app.getUid()){
that.setData({
showInviteButton: true,
})
that.setData({
dialogContent: '你获得了1个红包,还差1人即可打开。邀请好友助力有几率变大',
dialogConfirm: '邀请好友助力',
dialogConfirmDetail: '小伙伴仅限新人',
dialogNeedGetPhoneNumber:true,
showInviteButton:true,
})
that.dialog.showDialog();
}
if (app.globalData.WXUnion_ID){
that.fetchAssist(assistId)
}
//获取推荐的商品列表
that.getRecommed()
//订阅登录完成通知
listen(function (succeed) {
let that = this
if (!app.getUid()){
that.setData({
needGetPhoneNumber:true,
dialogNeedGetPhoneNumber:true
})
}else{
that.setData({
needGetPhoneNumber: false,
dialogNeedGetPhoneNumber:false
})
}
if (succeed) {
if (!assistId && !app.getUid()) {
that.setData({
dialogContent: '你获得了1个红包,还差1人即可打开。邀请好友助力有几率变大',
dialogConfirm: '邀请好友助力',
dialogConfirmDetail: '小伙伴仅限新人',
})
that.dialog.showDialog();
} else {
//发起获取助力活动的信息
this.fetchAssist(assistId)
}
}
}.bind(this))
var pages = getCurrentPages()
var currentPage = pages[pages.length - 1]
var url = currentPage.route
let params = {
PAGE_NAME: this.data.current_page_name,
PAGE_PARAM: this.data.current_page_param,
FROM_PAGE_NAME: this.data.from_page_name,
FROM_PAGE_PARAM: this.data.from_page_param,
PV_ID: PV_ID,
PAGE_PATH: url,
ASSIST_STATUS: '',
ASSIST_ID: assistId,
};
logEvent(YB_PAGE_OPEN_L, params);
// console.log("assistID:",assistId)
},
onReady:function(options){
this.dialog = this.selectComponent("#dialog");
},
onShow:function(options){
let that = this
let assistId = '';
if (that.data && that.data.assistId){
assistId = that.data.assistId
}
if (!assistId && !app.getUid()) {
// that.setData({
// showInviteButton: true,
// })
// that.setData({
// dialogContent: '你获得了1个红包,还差1人即可打开。邀请好友助力有几率变大',
// dialogConfirm: '邀请好友助力',
// dialogConfirmDetail: '小伙伴仅限新人',
// dialogNeedGetPhoneNumber: true,
// showInviteButton: true,
// })
// that.dialog.showDialog();
} else {
//发起获取助力活动的信息
that.fetchAssist(assistId)
}
},
onHide: function () {
// 生命周期函数--监听页面隐藏
this.stopTimer();
},
onUnload: function () {
// 生命周期函数--监听页面卸载
this.stopTimer();
},
//上报formid
formSubmit: function (e) {
// console.log('####formID:', e.detail.formId)
let app = getApp();
let _self = this;
let formId = e.detail.formId;
_self.setData({
formId,
})
_self.postFormId()
},
postFormId: function () {
let app = getApp();
let that = this;
//如果没有uid,不上报,否则接口报500
if(!app.getUid())return
let formIdParams = {
uid: app.getUid(),
openId: app.globalData.openID ? app.globalData.openID : getYHStorageSync('openID','assist'),
miniapp_type: app.globalData.miniapp_type,
formId: that.data.formId,
method: 'wechat.formId.add',
}
// console.log('formidParam:', formIdParams)
GET(API_HOST, formIdParams)
.then((data) => {
// console.log('responsedata', data)
})
.catch(error => {
})
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function (res) {
if (res && res.from == 'button') {
let params = {
PAGE_NAME: this.data.current_page_name,
ASSIST_ID: this.data.assistId,
};
logEvent(YB_INVITE_FRIEND_C, params);
}
var that = this
let imageUrl = 'http://img11.static.yhbimg.com/article/2018/06/05/13/013b81adcce4f10b0fb675186f41e3bc75.jpg';
let title = that.data.shareTitle;
let shareFrom = res.from;
let path = '/pages/assist/assist?assistId=' + that.data.assistId;
return {
title: title,
path: path,
imageUrl,
success: function (res) {
// 转发成功
let param = {
FROM: res.from,
SHARE_RESUIL: 1,
TITLE: title,
DESC: imageUrl,
PATH: path,
ASSIST_ID: that.data.assistId,
}
logEvent(YB_SHARE_RESULT_L, param);
},
fail: function (res) {
// 转发失败
let param = {
FROM: res.from,
SHARE_RESUIL: 0,
TITLE: title,
DESC: imageUrl,
PATH: path,
ASSIST_ID: that.data.assistId,
}
logEvent(YB_SHARE_RESULT_L, param);
}
}
},
bindPhoneNumComplete: function (result) {
let that = this
if (result && result.is_register && !that.data.isSelfRegister) {
that.assistSuccess()
}
},
showDialog() {
this.dialog.showDialog(1);
},
//取消事件
_cancelEvent() {
this.dialog.hideDialog();
this.setData({
goAssist:false
})
},
//确认事件
_confirmEvent() {
let that = this
this.dialog.hideDialog();
let params = {
PAGE_NAME: that.data.current_page_name,
ASSIST_ID: that.data.assistId,
};
logEvent(YB_INVITE_C, params);
that.startAssist()
// if(that.data.goAssist){
// this.setData({
// goAssist: false
// })
// }else{
// wx.navigateTo({
// url: '../../page/subPackage/pages/couponList/couponList',
// })
// }
},
_getUserInfo(){
let that = this
let assistUserInfo = [{
headIco : app.globalData.userInfo.avatarUrl
}]
this.setData({ assistUserInfo})
this.startAssist()
},
_goUserCenter(){
let that = this
that.dialog.hideDialog();
wx.switchTab({
url: '/pages/userCenter/userCenter'
})
// that.startAssist()
},
_goParticipate(){
let that = this
let app = getApp()
let uid = app.getUid();
let param = {
method: 'app.assist.start',
uid: uid,
unionId: app.globalData.WXUnion_ID,
}
wx.showLoading({
title: '加载中...',
});
GET(API_HOST, param)
.then(function (data) {
wx.hideLoading()
if (data && data.code == 200) {
that.updateAssistInfo(data)
// that.startSuccess(data.data)
} else if (data && data.code == 400) {
// console.log(data.code + data.message+'')
} else {
that.wetoast.toast({
title: data.code + data.message + '',
titleClassName: 'wetoast-title',
duration: 1000
});
}
})
.catch(function (error) {
wx.hideLoading()
that.wetoast.toast({
title: error.message + '',
titleClassName: 'wetoast-title',
duration: 1000
});
});
that.setData({
dialogContent: '你获得了1个红包,还差1人即可打开。邀请好友助力有几率变大',
dialogConfirm: '邀请好友助力',
dialogConfirmDetail: '小伙伴仅限新人',
dialogNeedGetPhoneNumber: false,
dialogIsShowParticipate:false,
showInviteButton: true,
dialogShowTwoButton: false,
})
that.dialog.showDialog();
},
helpBtnTapped:function(){
let that = this;
let app = getApp()
that.setData({
isSelfRegister: false,
})
if (app.getUid()){
that.setData({
dialogContent: '助力失败,你不是有货新人! 老朋友请直接领红包',
dialogConfirm:'点击领取',
dialogConfirmDetail:'',
dialogIsShowParticipate:true,//点击确认按钮,再弹出邀请好友的弹窗
})
that.dialog.showDialog();
let params = {
PAGE_NAME: that.data.current_page_name,
ASSIST_ID: that.data.assistId,
ASSIST_RESULT: 2,
};
logEvent(YB_ASSIST_C, params);
}else{
// this.startAssist()
}
},
startAssistBtnTapped:function(){
let that = this
that.startAssist()
that.setData({
isSelfRegister:true,
showInviteButton:true,
})
let params = {
PAGE_NAME: that.data.current_page_name,
ASSIST_ID: that.data.assistId,
};
logEvent(YB_INVITE_C, params);
// that.startAssist()
// this.showShare();
},
updateAssistInfo:function(data){
let that = this
// console.log("fetchAssist:", data)
let leftTime = data.data.leftSeconds;
let assistUserInfo = data.data.userInfo;
let assistId = data.data.assistId ? data.data.assistId:'';
let shareTitle = data.data.shareTitle;
let needAssistArray = [];
for (var i = 0; i < 2 - assistUserInfo.length; i++) {
needAssistArray[i] = i;
}
if (!app.getUid()) {
that.setData({
needGetPhoneNumber: true
})
} else {
that.setData({
needGetPhoneNumber: false
})
}
let qrCode = API_HOST + '/wechat/miniapp/img-check.jpg?param=' + assistId + '&miniQrType=5';
let sharerData = that.data.sharerData;
sharerData.headerUrl = assistUserInfo[0]?assistUserInfo[0].headIco:that.data.headIco;
sharerData.qrCode = qrCode;
that.setData({
leftTime,
assistUserInfo,
needAssistArray,
lackNum: needAssistArray.length,
assistId,
sharerData,
shareTitle,
})
if (leftTime > 0) {
that.stopTimer();
that.startTimer();
} else {
that.stopTimer();
}
},
startAssist: function (assistId) {
let that = this;
let app = getApp()
let uid = app.getUid();
let param = {
method: 'app.assist.start',
uid: uid,
assistId,
unionId: app.globalData.WXUnion_ID,
}
wx.showLoading({
title: '加载中...',
});
GET(API_HOST, param)
.then(function (data) {
wx.hideLoading()
if (data&&data.code == 200){
that.updateAssistInfo(data)
that.startSuccess(data.data)
} else if (data && data.code == 400){
// console.log(data.code + data.message+'')
}else{
that.wetoast.toast({
title: data.code + data.message + '',
titleClassName: 'wetoast-title',
duration: 1000
});
}
})
.catch(function (error) {
wx.hideLoading()
that.wetoast.toast({
title: error.message + '',
titleClassName: 'wetoast-title',
duration: 1000
});
});
},
fetchAssist: function (assistId) {
let that = this
let app = getApp()
let uid = app.getUid() ? app.getUid():0;
let unionId = app.globalData.WXUnion_ID ? app.globalData.WXUnion_ID:'';
if(!assistId){
assistId = that.data.assistId ? that.data.assistId:'';
}
let param = {
method: 'app.assist.info',
uid,
assistId,
unionId,
}
wx.showLoading({
title: '加载中...',
});
GET(API_HOST, param)
.then(function (data) {
// console.log("fetchAssistResponse:", data)
wx.hideLoading()
if(data && data.code==200){
that.updateAssistInfo(data)
that.fetchSuccess(data.data)
}else{
that.wetoast.toast({
title: '获取助力信息失败,请稍后重试',
titleClassName: 'wetoast-title',
duration: 1000
});
}
})
.catch(function (error) {
wx.hideLoading()
that.wetoast.toast({
title: '获取助力信息失败,请稍后重试',
titleClassName: 'wetoast-title',
duration: 1000
});
});
},
assistSuccess:function(){
let that = this
let app = getApp()
let uid = app.getUid();
let param = {
method: 'app.assist.success',
uid,
assistId:that.data.assistId,
}
GET(API_HOST, param)
.then(function (data) {
that.setData({
dialogContent: '助力成功!再为你奉上199元新人专享券',
dialogConfirm: '我也要领红包',
dialogConfirmDetail: '',
needGetPhoneNumber:false,
dialogNeedGetPhoneNumber:false,
dialogShowTwoButton:true
})
that.dialog.showDialog();
that.fetchAssist()
let params = {
PAGE_NAME: that.data.current_page_name,
ASSIST_ID: that.data.assistId,
ASSIST_RESULT: 2,
};
logEvent(YB_ASSIST_C, params);
})
.catch(function (error) {
that.wetoast.toast({
title: error.message + '',
titleClassName: 'wetoast-title',
duration: 1000
});
});
},
//调用发起助力接口成功,
startSuccess:function(data){
let that = this
if (data.assist && data.status==1){
that.setData({
dialogContent: '助力已完成,感谢小伙伴们!',
dialogConfirm: '我也要领红包',
dialogConfirmDetail: '',
})
that.dialog.showDialog();
} else if (data.assist && data.status == 2) {
that.setData({
dialogContent: '助力已结束,你来晚了~',
dialogConfirm: '我也要领红包',
dialogConfirmDetail: '小伙伴仅限新人',
})
that.dialog.showDialog();
} else if (!data.assist && data.status == 3){
// console.log("response:",data)
that.showShare()
}
},
fetchSuccess:function(data){
let that = this
if (!data.assist && (data.status == 0 || data.status == 3)) {
that.setData({
dialogContent: '你获得了1个红包,还差1人即可打开。邀请好友助力有几率变大',
dialogConfirm: '邀请小伙伴助力',
dialogConfirmDetail: '小伙伴仅限新人',
})
that.dialog.showDialog();
that.setData({
showInviteButton: true,
})
} else if (!data.assist && data.status == 1) {
that.setData({
dialogContent: '好友助力成功,现金券已到账,你可以在个人中心查看',
dialogConfirm: '再领一个红包',
dialogConfirmDetail: '',
goAssist: true,
})
that.dialog.showDialog();
that.setData({
showInviteButton: true,
})
} else if (!data.assist && data.status == 2) {
that.setData({
dialogContent: '助力人数不够,下次再努力!',
dialogConfirm: '再试一次',
dialogConfirmDetail: '',
})
that.dialog.showDialog();
that.setData({
showInviteButton: true,
})
} else if (!data.assist && data.status == 3) {
that.setData({
dialogContent: '助力人数不够,下次再努力!',
dialogConfirm: '再试一次',
dialogConfirmDetail: '',
})
that.dialog.showDialog();
that.setData({
showInviteButton: true,
})
} else if (data.assist && data.status == 1) {
that.setData({
dialogContent: '助力已完成,感谢小伙伴们!!',
dialogConfirm: '我也要领红包',
dialogConfirmDetail: '',
hideHelpButton: true,
})
that.dialog.showDialog();
} else if (data.assist && data.status == 2) {
that.setData({
dialogContent: '助力已结束,你来晚了~',
dialogConfirm: '我也要领红包',
dialogConfirmDetail: '',
hideHelpButton: true,
})
that.dialog.showDialog();
}
},
detailsRegularTap:function(){
wx.navigateTo({
url: '../webview/webview?url=' +'https://m.yohobuy.com/activity/feature/1583.html?title=助力活动说明细则&nodownload=1',
})
},
getPhoneNumber: function (e) {
var app = getApp()
var that = this;
if (e.detail.errMsg === 'getPhoneNumber:ok') {
decodePhoneNumber(e.detail.iv, e.detail.encryptedData, '', function (result) {
if (result.code != 200) {
that.wetoast.toast({
title: result.message,
titleClassName: 'wetoast-title',
duration: 1000,
});
} else {
let uid = app.globalData.userInfo.uid > 0 ? app.globalData.userInfo.uid : 0;
app.updateUid(uid)
that.setData({ uid });
if (result.is_register && !that.data.isSelfRegister){
//新注册用户
that.showZanToast({ title: '欢迎加入Yoho!Family!新人礼包已发放到个人中心-优惠券,请注意查收', success: function (){
that.assistSuccess();
}},1500);
}else if (result.is_register && that.data.isSelfRegister){
//自行注册
that.showShare()
}else{
that.setData({
dialogContent: '助力失败,助力仅限有货新人!老朋友请直接领红包',
dialogConfirm: '我也要领红包',
dialogConfirmDetail: '',
})
that.dialog.showDialog();
let params = {
PAGE_NAME: that.data.current_page_name,
ASSIST_ID: that.data.assistId,
ASSIST_RESULT: 1,
};
logEvent(YB_ASSIST_C, params);
}
if (!app.getUid()) {
that.setData({
needGetPhoneNumber: true
})
} else {
that.setData({
needGetPhoneNumber: false
})
}
// that._getUserInfo()
}
})
} else {
wx.navigateTo({
url: '/pages/bindPhoneNumber/bindPhoneNumber',
})
}
},
updateUserInfo() {
this.setData({
needGetPhoneNumber: false
});
this.data.assistId && this.fetchAssist(this.data.assistId)
},
/**
* 新的授权方式
*/
getUserInfo: function (e) {
var that = this;
if (e.detail.errMsg === 'getUserInfo:ok') {
decodeUnionId(app.getWechatThirdSession(), e, function (response) {
if (response.isHaveUnionID) {
that.setData({
hasUnionID: true,
});
}
});
} else {
openAuthorizeSettings(function (response) {
if (response.isHaveUnionID) {
that.setData({
hasUnionID: true,
})
};
if (response.succeed === true) {
} else {
// console.log("根据unionid没有查询到uid,需要再次点击授权getPhoneNumber")
}
});
}
},
startTimer: function (e) {
// console.log('startTimer');
let that = this;
timer = setInterval(function () {
let leftTime = that.data.leftTime - 1;
let formatTime = that.formatDate(parseInt(leftTime));
that.setData({
leftTime,
formatTime,
});
if (leftTime == 0) {
that.stopTimer();
that.fetchActivityGroupDetail();
that.fetchactivityList();
}
}, 1000);
},
stopTimer: function (e) {
// console.log('stopTimer');
clearInterval(timer);
},
format: function (m) {
if (m < 10) {
return [0, m];
} else {
var h1 = Math.floor(m / 10);
var h2 = m - h1 * 10;
return [h1, h2];
}
return [0, 0];
},
formatDate: function (shijianchuo) {
// 秒数
var second = Math.floor(shijianchuo);
// 小时位
var hr = Math.floor(second / 3600);
var hrFormat = this.format(hr);
// 分钟位
var min = Math.floor((second - hr * 3600) / 60);
var minFormat = this.format(min);
// 秒位
var sec = (second - hr * 3600 - min * 60);
var secFormat = this.format(sec);
var tFormat = {
h1: hrFormat[0],
h2: hrFormat[1],
m1: minFormat[0],
m2: minFormat[1],
s1: secFormat[0],
s2: secFormat[1],
};
return tFormat;
},
getRecommed: function () {
let gender = getGenderCode(getApp().globalData.selectedChannel);
let yh_channel = getChannelCode(getApp().globalData.selectedChannel);
let param = {
method: "app.home.newPreference",
gender,
yh_channel,
rec_pos: 100004,
limit: 30,
fromPage: "aFP_My",
}
GET(API_HOST, param)
.then(json => {
if (json && json.code && json.code == 200) {
// console.log('获取猜你喜欢数据成功');
// console.log(json);
let data = json.data.product_list;
data = parseBrandListData(data);
this.setData({
recommdData: data,
})
}
})
.catch(function (error) {
wx.hideLoading()
that.wetoast.toast({
title: error + '',
titleClassName: 'wetoast-title',
duration: 1000
});
});
},
/******************************/
/** 分享相关 **/
/******************************/
showShare: function (e) {
let sharerData = this.data.sharerData;
sharerData.isShow = true;
this.setData({
sharerData,
});
},
showImage: function (e) {
// console.log('showImage');
var that = this
let params = {
PAGE_NAME: that.data.current_page_name,
ASSIST_ID: that.data.assistId,
};
logEvent(YB_INVITE_PICTURE_C, params);
wx.getSetting({
success(res) {
// console.log(res);
if (!res.authSetting['scope.writePhotosAlbum']) {
wx.authorize({
scope: 'scope.writePhotosAlbum',
success() {
that.saveSnapShoot();
}
})
} else {
that.saveSnapShoot();
}
}
})
},
saveSnapShoot: function (e) {
let sharerData = this.data.sharerData;
sharerData.showType = 2;
this.setData({
sharerData,
});
this.drawElement('assistShareCanvas', 3);
},
drawElement: function (conName, num) {
let that = this
// console.log('drawElement');
const ctx = wx.createCanvasContext(conName)
ctx.setFillStyle('white')
ctx.fillRect(0, 0, (shareViewWidth - 105) * SC * num, (shareViewHeight - 200) * SC * num);
ctx.draw(true)
//图片
wx.getImageInfo({
src: 'https://cdn.yoho.cn/20180209/help/44.png',
success: function (res) {
ctx.drawImage(res.path, ((shareViewWidth - 350) / 2 - 50) * SC * num, 70 * SC * num, 350 * SC * num, 583 * SC * num);
ctx.draw(true);
//头像
wx.downloadFile({
url: that.data.sharerData.headerUrl,
success: function (res) {
ctx.save()
ctx.beginPath()
ctx.arc(((shareViewWidth - 190) / 2 - 50) * SC * num + 22 * SC * num, 194 * SC * num + 22 * SC * num, 22 * SC * num, 0, 2 * Math.PI)
ctx.clip()
ctx.drawImage(res.tempFilePath, ((shareViewWidth - 190) / 2 - 50) * SC * num, 194 * SC * num, 44 * SC * num, 44 * SC * num);
ctx.restore()
ctx.draw(true)
}
})
let qrCode = that.data.sharerData.qrCode;
if (qrCode.indexOf("https://") == -1) {
qrCode = qrCode.replace('http://', 'https://');
}
//二维码
wx.getImageInfo({
src: qrCode,
success: function (res) {
ctx.drawImage(res.path, ((shareViewWidth - 130) / 2 - 50) * SC * num, 440 * SC * num, 130 * SC * num, 130 * SC * num);
ctx.draw(true);
},
});
}
});
ctx.draw(true)
},
shareHide: function (e) {
// console.log('shareHide');
let sharerData = this.data.sharerData;
sharerData.isShow = false;
sharerData.showType = 1;
this.setData({
sharerData,
});
},
shareSaveImage: function (e) {
var that = this
wx.canvasToTempFilePath({
x: 0,
y: 10000,
width: (shareViewWidth - 100) * SC * 3,
height: (shareViewHeight - 200) * SC * 3,
destWidth: (shareViewWidth - 100) * SC * 6,
destHeight: (shareViewHeight - 200) * SC * 6,
canvasId: 'assistShareCanvas',
success: function (result) {
wx.saveImageToPhotosAlbum({
filePath: result.tempFilePath,
success(res) {
wx.showToast({
title:
'保存成功',
icon:
'success',
duration:
2000
})
that.shareHide();
},
fail(err) {
that.shareHide();
}
});
},
});
let params = {
PAGE_NAME: that.data.current_page_name,
ASSIST_ID: that.data.assistId,
};
logEvent(YB_INVITE_PICTURE_SAVE_C, params);
},
}))