blessing.js
27.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
import {
getBindtapData,
checkAuthUtils
} from '../../utils/util';
import Dialog from '../../ui/vant-weapp/dialog/dialog';
import Poster from '../../miniprogram_dist/poster/poster';
// import calendar from '../../utils/calendar.js';
let calendar = require('../../utils/calendar.js');
const innerAudio = wx.createInnerAudioContext();
let app = getApp();
Page({
data: {
isOverShare: true,
authorizeVisible: false,
evttype: "",
total: 0,
page: 1,
size: 10,
productList: [], // 产品列表
indexInfo: {},
userInfo: {},
options: {},
detailData: {},
ownerMember: {}, // 房主
memberList: [], // 用户信息
blessContent: [], // 祝福内容
isAuth: false, // 是否授权
// type: 0, // 0单人 1组队
// 个人信息修改
updateUserInfoDialogVisible: false,
updateUserInfo: {}, // 需要更新的用户数据
files: [], // 上传文件列表
// 房间信息信息修改
updateRoomDialogVisible: false,
updateRoomInfo: {}, // 需要更新的房间数据
// 加入房间
joinRoomDialogVisible: false,
joinRoomDialogVisibleUnAuth: false,
isJoin: false, // 是否能加入状态
joined: false, // 是否已加入
isPlayingBgm: false,
isMore: false,
imageUrl: "", // 海报图
posterVisible: false,
wxCodeUrl: "", // 微信小程序码
lunarDate: "", //农历月日
},
onShareAppMessage(res) {
let {
detailData,
ownerMember,
options
} = this.data;
let title = "亲爱的家人们新年快乐";
if (detailData.type == 0) {
// 单人 给您拜年啦!来看看是怎样特别的祝福
title = `${ownerMember.memberName}给您拜年啦!来看看是怎样特别的祝福`;
} else {
// 团队
if (detailData.count > 0) {
title = `${ownerMember.memberName}携${detailData.familyName}${detailData.count}人给您拜年啦!看看这${detailData.count}人都是谁`;
} else {
title = `${ownerMember.memberName}给您拜年啦!来看看是怎样特别的祝福`;
}
}
let shareType = ""
// let imageUrl = detailData && detailData.thumbnail || "";
if (res.from === 'button') {
// 来自页面内转发按钮
// shareType == join 分享给家人,能加入 组队模式
shareType = res.target.dataset.data || "";
console.log("shareType:", shareType);
if (shareType) {
console.log("shareType222:",shareType);
title = `${ownerMember.memberName}邀请您组队发祝福!体验今年最火爆的拜年方式`
wx.aldstat.sendEvent('拜年页分享', {
'分享': '邀请分享'
});
} else {}
let act = res.target.dataset.act || "";
if (act == "made") {
this.onShareBlessMakeHandler();
}
} else {}
// 权重 参数memberCode(房主memberCode) => 本人memberCode
let memberCode = "";
if (options.m) {
memberCode = options.m;
} else if (detailData.customMade == 1) {
memberCode = app.store.getItem("memberCode");
}
let path = `pages/blessing/blessing?c=${detailData.blessCode}&m=${memberCode}&t=${shareType}`;
console.log("share path:", path);
wx.aldstat.sendEvent('拜年页分享', {
'分享': '普通分享'
});
return {
title,
path,
// imageUrl
}
},
showAuth() {
let _this = this;
wx.login({
success: function (res) {
app.store.setItem('wxcode', res.code);
_this.setData({
authorizeVisible: true
})
}
});
},
checkAuth() {
return new Promise((resolve, reject) => {
let {
detailData
} = this.data;
let isAuth = detailData.isAuth == 1;
resolve(isAuth);
// checkAuthUtils().then((result) => {
// console.log("checkAuth result:", result);
// console.log("checkAuth detailData.isAuth:", detailData.isAuth);
// let isAuth = result && detailData.isAuth == 1;
// this.setData({
// isAuth
// });
// console.log("checkAuth isAuth:", isAuth);
// resolve(isAuth);
// });
});
},
checkAuthShowComp(evttype) {
return new Promise((resolve, reject) => {
this.checkAuth().then((result) => {
if (result) {
resolve(true);
} else {
if (evttype) {
this.setData({
evttype
})
} else {
this.setData({
evttype: ""
})
}
console.log("checkAuthShowComp evttype:", this.data.evttype);
this.showAuth();
}
});
});
},
onHide() {
},
onUnload() {
this.pauseBgm();
},
onLoad(options) {
wx.login({
success(res) {
app.store.setItem('wxcode2', res.code);
}
});
let date = new Date();
let lunar = calendar.calendar.solar2lunar(date.getFullYear(), date.getMonth() + 1, date.getDate());
let lunarDate = lunar.IMonthCn + lunar.IDayCn;
this.setData({
options,
lunarDate
});
// this.initData();
this.queryBlessDetail().then((result) => {
this.playBgm();
let {
detailData,
ownerMember,
memberList
} = this.data;
this.checkAuth();
// 判断memberList里面是否有自己
let joined = false;
memberList.forEach(element => {
if (element.mySelf == 1) {
joined = true;
}
});
/**q
* 显示加入房间条件
* 1.已定制
* 2.类型为组队类型
* 3.非房主
* 4.shareType为join t="join"
* 5.未加入过 判断memberList里面是否有自己
*/
console.log("---- 判断是否显示加入 Start ----");
console.log("已定制:", detailData.customMade == 1);
console.log("类型为组队类型:", detailData.type == 1);
console.log("非房主:", ownerMember.mySelf == 0);
console.log("shareType为join:", options);
console.log("是否加入过:", joined);
this.setData({
joined
})
if (detailData.customMade == 1 && detailData.type == 1 && ownerMember.mySelf == 0 && options.t == "join" && !joined) {
this.setData({
// joinRoomDialogVisible: true,
isJoin: true,
});
if (detailData.isAuth == 1) {
this.setData({
joinRoomDialogVisible: true,
})
} else {
this.setData({
joinRoomDialogVisibleUnAuth: true,
})
}
}
});
console.log("memberCode:", app.store.getItem("memberCode"));
wx.aldstat.sendEvent('进入页面', {
'页面名字': '拜年详情页'
});
},
/**
* 基础方法
* 授权完毕重拉数据用
*/
initData() {
this.checkAuth().then((result) => {});
},
playBgm() {
let _this = this;
let {
detailData
} = this.data;
if (detailData.musicUrl) {
innerAudio.src = detailData.musicUrl;
innerAudio.seek(0);
innerAudio.play();
innerAudio.onEnded(() => {
_this.playBgm();
})
this.setData({
isPlayingBgm: true,
})
}
},
pauseBgm() {
innerAudio.pause();
innerAudio.offEnded(() => {})
this.setData({
isPlayingBgm: false,
})
},
onBgmHandler() {
if (this.data.isPlayingBgm) {
this.pauseBgm();
} else {
this.playBgm();
}
},
onShowMoreHandler() {
this.setData({
isMore: true
})
},
onHideMoreHandler() {
this.setData({
isMore: false
})
},
onShowMakeHandler() {
let {
detailData
} = this.data;
let _this = this;
wx.showModal({
title: '提示',
content: '需要定制祝福才能邀请亲友哦~',
confirmText: "马上创建",
success(res) {
if (res.confirm) {
// 已授权
app.post({
url: app.api.blessMade,
data: {
blessCode: detailData.blessCode,
}
}).then((result) => {
this.queryBlessDetail().then((result) => {
this.showTips("定制祝福成功!马上邀请您的亲友吧!");
});
}).catch((err) => {});
} else if (res.cancel) {
}
}
})
},
showTips(tips) {
wx.showToast({
title: tips + "",
icon: "none"
})
},
showTipsByWxml(evt) {
let tips = getBindtapData(evt);
wx.showToast({
title: tips + "",
icon: "none"
})
},
/**
* 赞赏祝福
* 跳转到赞赏页
*/
toReward() {
app.router.push({
path: "reward"
})
},
/**
* 选择更多祝福模版
*/
onMoreTemplateHandler() {
let pages = getCurrentPages();
if (pages.length > 1) {
// 如果能返回上一级
app.router.push({
openType: "back"
});
} else {
app.router.push({
openType: "redirect",
path: "index",
query: {
t: "bless"
}
});
}
},
onHidePosterHandler() {
this.setData({
posterVisible: false
})
},
/**
* 图片查看
*/
onPreviewImageHandler(evt) {
let current = this.data.imageUrl;
let urls = [current];
wx.previewImage({
current: current,
urls: urls
})
},
/**
* 保存图片到本地
*/
saveImageToPhotosAlbum() {
let _this = this;
wx.saveImageToPhotosAlbum({
filePath: _this.data.imageUrl,
success(res) {
wx.showModal({
content: '图片已经保存到你的相册,快去发送到朋友圈拜年吧!',
showCancel: false,
confirmText: '确认',
success(res) {}
})
},
fail(err) {
wx.getSetting({
success: (res) => {
if (!res.authSetting['scope.writePhotosAlbum']) {
// 未授权
wx.showModal({
title: '提示',
content: '小程序请求访问相册权限',
confirmText: '前往授权',
success(res) {
if (res.confirm) {
wx.openSetting({
success(res) {}
})
} else if (res.cancel) {}
}
})
}
}
})
}
})
},
// 配置小程序码
getWxCode() {
let {
detailData
} = this.data;
let memberCode = app.store.getItem("memberCode");
// let wxCodePath = `pages/blessing/blessing?c=${detailData.blessCode}&m=${memberCode}`;
return new Promise((resolve, reject) => {
// 先获取小程序码
app.post({
url: app.api.wxacodeGet,
data: {
page: "pages/blessing/blessing",
content: JSON.stringify({
blessCode: detailData.blessCode || "",
ownerMemberCode: memberCode || "",
})
}
}).then((result) => {
this.setData({
wxCodeUrl: result
})
resolve(result);
})
});
},
/**
* 分享图片祝福
* 生成海报
*/
onPosterHandler() {
console.log("onPosterHandler");
let {
detailData
} = this.data;
if (detailData.customMade == 1) {
// 先获取小程序码
this.getWxCode().then((result) => {
let posterData = this.getPosterConfig();
this.onCreatePoster(posterData);
});
} else {
// this.showTips("请先定制祝福")
app.post({
url: app.api.blessMade,
data: {
blessCode: detailData.blessCode,
}
}).then((result) => {
this.queryBlessDetail().then((result) => {
this.getWxCode().then((result) => {
let posterData = this.getPosterConfig();
this.onCreatePoster(posterData);
});
});
}).catch((err) => {});
}
},
onPosterSuccess(e) {
wx.hideLoading();
const {
detail
} = e;
console.log("detail:", detail)
this.setData({
imageUrl: detail,
posterVisible: true,
})
},
onPosterFail(err) {
wx.hideLoading();
console.error(err);
},
/**
* 异步生成海报
*/
onCreatePoster(posterConfig) {
console.log("posterConfig:", posterConfig);
this.setData({
posterConfig: posterConfig
}, () => {
Poster.create(true); // 入参:true为抹掉重新生成
});
},
// 获取海报数据
getPosterConfig() {
let {
detailData,
ownerMember,
memberList,
wxCodeUrl
} = this.data;
let avatarWid = 120;
let nickname = ownerMember.memberName;
let avatar = ownerMember.memberHead;
let desc = "";
if (detailData.type == 1) {
// 组队
if (detailData.count > 0) {
desc = `携${detailData.familyName}${detailData.count}人`
} else {
desc = `携${detailData.familyName}`
}
} else {
// 单人
desc = `向各位亲朋好友`
}
let blocks = []
let images = [
// 背景图
{
x: 0,
y: 0,
width: 750,
height: 1334,
url: "../../image/poster/poster_c1.png",
},
// 头像
{
x: 184,
y: 186,
width: avatarWid,
height: avatarWid,
borderRadius: avatarWid,
zIndex: 22,
url: avatar,
},
// 小程序码
{
width: 100,
height: 100,
borderRadius: 100,
x: 586,
y: 1198,
url: wxCodeUrl,
zIndex: 31
}
];
let lines = [];
let texts = [
// 房主昵称
{
x: 53,
y: 460,
fontSize: 60,
color: "#fee085",
textAlign: "left",
zIndex: 11,
text: nickname,
},
// 文案
{
x: 53,
y: 540,
fontSize: 60,
color: "#fee085",
textAlign: "left",
zIndex: 11,
text: desc,
}
];
// 组队补充
if (detailData.type == 1) {
// 头像昵称取出3人
let member1 = memberList[0] || null;
let member2 = memberList[1] || null;
let member3 = memberList[2] || null;
let memberDrawList = [];
if (member1) memberDrawList.push(member1);
if (member2) memberDrawList.push(member2);
if (member3) memberDrawList.push(member3);
let endX = 630;
let wid = 160;
let startY = 800;
memberDrawList.forEach((element, idx) => {
images.push({
x: endX - (idx * wid) - ((wid - 92) / 2) - 4,
y: startY + 2,
width: 92,
height: 92,
borderRadius: 92,
zIndex: 101,
url: element.memberHead,
})
texts.push({
x: endX - (idx * wid),
y: startY + 136,
width: wid,
fontSize: 24,
color: "#fee085",
textAlign: "center",
zIndex: 101,
text: element.memberName,
})
});
if (memberDrawList.length > 0) {
texts.push({
x: 686,
y: startY + 200,
fontSize: 48,
color: "#fee085",
textAlign: "right",
zIndex: 11,
text: `长按查看全部${detailData.count}人`,
})
} else {
texts.push({
x: 686,
y: startY + 200,
fontSize: 48,
color: "#fee085",
textAlign: "right",
zIndex: 11,
text: `长按查看祝福`,
})
}
}
let posterData = {
width: 750,
height: 1334,
debug: false,
blocks: blocks,
images: images,
lines: lines,
texts: texts,
}
return posterData;
},
// 显示更新用户信息
showUpdateUserInfoDialog() {
let {
detailData
} = this.data;
if (detailData.customMade == 1) {
this.checkAuthShowComp().then((result) => {
this.setData({
updateUserInfoDialogVisible: true,
updateUserInfo: {},
files: []
})
});
} else {
this.showTips("请先定制祝福");
}
},
// 房主名字
onUpdateUserInfoBindInput(e) {
this.setData({
updateUserInfo: {
memberName: e.detail.value
}
})
},
// 显示更新用户信息
showUpdateRoomDialog() {
let {
detailData
} = this.data;
if (detailData.customMade == 1) {
this.checkAuthShowComp().then((result) => {
this.setData({
updateRoomDialogVisible: true,
updateRoomInfo: {},
})
});
} else {
this.showTips("请先定制祝福");
}
},
// 家庭名称
onUpdateFamilyNameBindInput(e) {
this.setData({
"updateRoomInfo.familyName": e.detail.value
})
},
// 祝福语
onUpdateSentenceBindInput(e) {
this.setData({
"updateRoomInfo.sentence": e.detail.value
})
},
/**
* 更新房间信息
*/
onUpdateRoomHander() {
let {
detailData,
ownerMember,
updateRoomInfo
} = this.data;
console.log("updateRoomInfo:", updateRoomInfo);
app.post({
url: app.api.blessUpdateRoom,
data: {
blessCode: detailData.blessCode,
// ownerMemberCode: app.store.getItem("memberCode"),
familyName: updateRoomInfo.familyName || "",
sentence: updateRoomInfo.sentence || "",
}
}).then((result) => {
console.log("result:", result);
this.queryBlessDetail();
}).catch((err) => {});
},
/**
* 上传头像
*/
onUploadHandler() {
let _this = this;
wx.chooseImage({
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
count: 1,
success(res) {
// tempFilePath可以作为img标签的src属性显示图片
const tempFiles = res.tempFiles
let files = tempFiles;
console.log("chooseImage files:", files);
_this.setData({
files
});
}
})
},
/**
* 更新拜年页用户信息
*/
onUpdateUserInfoHander() {
let {
detailData,
ownerMember,
updateUserInfo,
files
} = this.data;
let pics = [];
files.forEach(element => {
pics.push(element.path)
});
this.uploadToCustomService(pics).then((picRes) => {
console.log("picRes:", picRes);
console.log("updateUserInfo:", updateUserInfo);
app.post({
url: app.api.blessUpdateUserInfo,
data: {
blessCode: detailData.blessCode,
ownerMemberCode: this.data.options.m ? this.data.options.m : app.store.getItem("memberCode") ? app.store.getItem("memberCode") : "",
memberName: updateUserInfo.memberName || "",
memberHead: picRes[0] || "",
}
}).then((result) => {
console.log("result:", result);
this.queryBlessDetail();
}).catch((err) => {});
})
},
/**
* 上传到自定义服务器
* urlList 需要上传的图片地址
*/
uploadToCustomService(urlList) {
let _this = this;
return new Promise((resolve, reject) => {
// promise列表
let p = [];
// 用promise上传音频
urlList.forEach(element => {
let myPromise = new Promise((resolve2, reject2) => {
_this.uploadfileMultiple(element).then((result2) => {
resolve2(result2)
}).catch((err) => {
reject2();
});
});
p.push(myPromise);
});
Promise.all(p).then(uploadFiles => {
resolve(uploadFiles)
}, reason => {
reject();
});
});
},
/**
* 多文件上传
* @param {*} filePath
*/
uploadfileMultiple(filePath) {
let _this = this;
return new Promise((resolve, reject) => {
wx.uploadFile({
url: app.config.NET_CONFIG.commonApi + app.api.uploadFile,
filePath: filePath,
name: 'file',
// header: {}, // 设置请求的 header
header: {
'content-type': 'multipart/form-data'
},
formData: {
path: '/weapp/jyes/avatar/'
},
// HTTP 请求中其他额外的 form data
success(res) {
let result = JSON.parse(res.data).content;
resolve(result);
},
fail() {
reject()
},
complete: function () {}
})
});
},
/**
* 视频详情
*/
queryBlessDetail() {
return new Promise((resolve, reject) => {
let {
options
} = this.data;
const scene = options.scene || "";
app.post({
url: app.api.blessDetail,
data: {
blessCode: this.data.options.c || "",
ownerMemberCode: this.data.options.m ? this.data.options.m : app.store.getItem("memberCode") ? app.store.getItem("memberCode") : "",
scene: scene || ""
}
}).then((result) => {
let blessContent = [];
try {
blessContent = JSON.parse(result.blessContent) || [];
} catch (error) {}
let memberList = result.memberList;
// hardcode数据
// for (let index = 0; index < 6; index++) {
// memberList.push({
// blessCode: "4144feba2b904ba89585d90e8618a863",
// blessMemberCode: "747e8e314d0e46679be17fb495975439",
// count: 2,
// customMade: 0,
// familyName: "祝福团体称呼",
// memberCode: "9af835ad57234cf2826b770dcc8a9897",
// memberHead: "https://wx.qlogo.cn/mmopen/vi_32/v4XnMftVxCzkFD8ibLicDjxicFhzugVt4vUWsHmup9ZeunwZhQ21H9ugELpgyTicsVyNCXenqIlUHBIkZ2aEP2qPpw/132",
// memberName: "ee",
// mySelf: 1,
// owner: 0,
// sentence: "定义"
// })
// }
this.setData({
detailData: result,
ownerMember: result.ownerMember,
memberList: memberList,
blessContent: blessContent,
isAuth: result.isAuth == 1
});
console.log("detailData:", result);
console.log("blessContent:", this.data.blessContent);
console.log("类型 type => ", result.type == 1 ? "组队" : "单人");
console.log("是否已定制 customMade => ", result.customMade == 1 ? "已经定制" : "未定制");
console.log("是否自己房间 mySelf => ", result.ownerMember.mySelf == 1 ? "是" : "否");
console.log("房主信息 ownerMember => ", result.ownerMember);
console.log("是否授权 isAuth =>", this.data.isAuth);
console.log("房主信息 =>", result.ownerMember);
console.log("祝福内容 =>", result.blessContent);
resolve(result);
}).catch((err) => {
reject(err);
});
});
},
/**
* 标记定制祝福
*/
onBlessMakeHandler() {
let {
detailData,
isAuth
} = this.data;
console.log("isAuth:", isAuth);
if (isAuth) {
// 把房间变成自己
this.setData({
isJoin: false,
joined: false,
"options.m": app.store.getItem("memberCode")
})
this.queryBlessDetail().then((result) => {
// 已授权
app.post({
url: app.api.blessMade,
data: {
blessCode: detailData.blessCode,
}
}).then((result) => {
this.queryBlessDetail().then((result) => {
this.showTips("定制祝福成功!");
});
}).catch((err) => {});
})
} else {
// 未授权
}
},
/**
* 未定制时但已授权时,戳起分享作为定制
*/
onShareBlessMakeHandler() {
let {
detailData,
isAuth
} = this.data;
app.post({
url: app.api.blessMade,
data: {
blessCode: detailData.blessCode,
}
}).then((result) => {
this.queryBlessDetail().then((result) => {});
}).catch((err) => {});
},
/**
* 加入房间
*/
onBlessJoinHandler(e) {
// this.checkAuthShowComp("join").then((result) => {
let {
options,
detailData
} = this.data;
app.post({
url: app.api.blessJoin,
data: {
ownerMemberCode: options.m,
blessCode: detailData.blessCode
}
}).then((result) => {
this.setData({
isJoin: false
})
this.queryBlessDetail().then((result) => {
this.showTips("加入成功");
});
}).catch((err) => {});
},
// 点击确认授权按钮
bindGetUserInfo(e) {
let _this = this;
wx.showLoading();
_this.getUserInfo(e.detail);
},
// 授权操作
getUserInfo(e) {
console.log("getUserInfo 1111111");
let {
detailData
} = this.data;
let _this = this;
if (e.encryptedData && e.iv) {
// 同意授权
app.post({
url: app.api.register,
sid: false,
data: {
blessCode: detailData.blessCode,
encryptedData: e.encryptedData,
iv: e.iv,
code: app.store.getItem("wxcode2"),
tlMemberCode: app.globalData.tlMemberCode
}
}).then((res2) => {
wx.hideLoading();
if (res2 && res2.sessionId) {
app.store.setItem('sessionId', res2.sessionId);
app.store.setItem('memberCode', res2.memberCode);
}
this.showTips("授权成功");
this.queryBlessDetail().then((result) => {
this.checkAuth().then((result) => {}).catch((err) => {});
}).catch((err) => {});
}).catch((err) => {
wx.hideLoading();
console.log("授权成功 err:", err);
})
} else {
// 取消授权
wx.hideLoading();
console.log("取消授权");
}
},
// 授权后加入组队
getUserInfo2(evt) {
let {
detailData
} = this.data;
let e = evt.detail;
if (e.encryptedData && e.iv) {
wx.showLoading();
// 同意授权
app.post({
url: app.api.register,
sid: false,
data: {
// blessCode: detailData.blessCode,
encryptedData: e.encryptedData,
iv: e.iv,
code: app.store.getItem("wxcode2"),
tlMemberCode: app.globalData.tlMemberCode
}
}).then((res2) => {
wx.hideLoading();
if (res2 && res2.sessionId) {
app.store.setItem('sessionId', res2.sessionId);
app.store.setItem('memberCode', res2.memberCode);
}
this.onBlessJoinHandler();
}).catch((err) => {
wx.hideLoading();
})
} else {}
},
// 授权后定制祝福
getUserInfo3(evt) {
console.log("getUserInfo3 33333");
let {
detailData
} = this.data;
let e = evt.detail;
if (e.encryptedData && e.iv) {
wx.showLoading();
// 同意授权
app.post({
url: app.api.register,
sid: false,
data: {
// blessCode: detailData.blessCode,
encryptedData: e.encryptedData,
iv: e.iv,
code: app.store.getItem("wxcode2"),
tlMemberCode: app.globalData.tlMemberCode
}
}).then((res2) => {
wx.hideLoading();
if (res2 && res2.sessionId) {
app.store.setItem('sessionId', res2.sessionId);
app.store.setItem('memberCode', res2.memberCode);
}
this.queryBlessDetail().then((result) => {
this.onBlessMakeHandler();
});
}).catch((err) => {
wx.hideLoading();
})
} else {}
},
/**
* 隐藏蒙层
*/
hideMask() {
this.setData({
productDetailVisible: false,
authorizeVisible: false,
})
},
/**
* 子组件事件
* @param {*} evt
*/
evtcomp(evt) {
let {
name,
data
} = evt.detail;
if (data && data.evttype && data.evttype == "join") {
console.log("55555");
}
switch (name) {
// 隐藏蒙层
case "_evt_hide_mask":
this.hideMask();
break;
/**
* 重拉数据已在
*/
case "_evt_auth_complete":
// this.initData();
this.hideMask();
console.log("_evt_auth_complete:", data.evttype);
if (data && data.evttype && data.evttype == "join") {
this.queryBlessDetail().then((result) => {
this.onBlessJoinHandler();
});
} else {
this.queryBlessDetail();
}
break;
default:
break;
}
},
})