luckyGo_details.js
40.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
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
var t = require("../../../../utils/util.js"),
ut = t,
e = require("../../../../utils/common.js"),
a = require("../../../../utils/wxParse/wxParse.js"),
s = getApp(),
i = s.request,
rq = i,
oo = s.globalData,
o = s.globalData.setting,
os = o;
var regeneratorRuntime = require('../../../../utils/runtime.js');
let self = null;
Page({
data: {
//activity_type:1,//活动类型 商家1 阶梯2 会员3
p_status:1,//会员团的详细情况 1是正在行 2是成功 3失败
sf_length: 1,//人数大于5
erweima:false,
meng:false,
zk:true,
stoid: o.stoid,
hiddenName: true,
teamlist:null,
teamgroup:null,
goods:null,//商品数据
pindGoods: null,//拼单数据
imageurl: o.imghost,
pay_f:0,//支付是否成功
order_sn:"",//订单编号
canvasHidden:false, //画画版
screenWidth:0,
pd_xx: 0, //弹框
max_num:0,//最低成团人数
min_price:0,//最低价格
is_show:0,//加载完才显示
share_img_localpath:"", //分享图片的本地图片
share_ewm_localpath: "", //分享的二维码本地图片
share_head:"", //分享头像的本地图片
iurl:os.imghost,
ct_price:0,//阶梯团成团价格
sf_arr:null,
showRules: false,
isSuccess: false,
showPoster: false,
luckyGoMembers: [],
// team_id: 0,
},
onLoad: function (t) {
self = this;
if(t.team_id != null && t.team_id !=undefined) {
this.setData({
team_id: t.team_id,
});
};
this.setData({
param: t,
});
var that=this;
var th=this;
//获取用户设备信息,屏幕宽度
wx.getSystemInfo({
success: res => {
that.setData({ screenWidth: res.screenWidth })
}
})
var pay_f = t.payf, order_sn = t.ordersn;
this.setData({ pay_f: pay_f, order_sn: order_sn});
this.init(order_sn);
//-- 自定义海报 --
getApp().request.promiseGet("/api/weshop/goods/poster/page", {
data:{store_id:os.stoid, type:1, is_use:1 }
}).then(res=>{
if(res.data.code==0 && res.data.data && res.data.data.pageData && res.data.data.pageData[0] ){
var poster_data=res.data.data.pageData[0];
var json_str=poster_data.jsonStr;
if(json_str){
var json_data=JSON.parse(json_str);
if(json_data.bg_img){
//-- 把图片那到本地 --
wx.getImageInfo({
src:json_data.bg_img,
success: function(res) {
var path= res.path;
th.setData({share_b_img:path})
},
fail: function(res) {}
});
}
th.setData({poster:json_data})
}
}
})
},
onShow: function() {
this.get_team_info();
},
onUnload: function () {
// 开团成功后,清除storage里的team_id
// if(this.data.luckyGoInfo && this.data.luckyGoInfo.num == 0) {
// wx.removeStorageSync('team_id');
// };
// // 如果是从会员中心的幸运购列表点击进来的,退出时清除storage里的team_id
// if(this.data.param.from == 1) {
// let team_id = wx.getStorageSync('team_id');
// if(team_id != null && team_id != undefined) wx.removeStorageSync('team_id');
// };
wx.removeStorageSync('team_id');
},
//关闭展开列表
click: function(e) {
this.setData({
hiddenName: !this.data.hiddenName,
zk: !this.data.zk,
})
},
//打开收起拼团列表
czk: function(e) {
this.setData({
zk:!this.data.zk,
hiddenName: !this.data.hiddenName,
})
},
//打开蒙板提示
cmeng: function(e) {
this.setData({
meng:!this.data.meng,
})
},
//关闭蒙板提示
cmc: function(e) {
this.setData({
meng: !this.data.meng,
})
},
//打开二维码提示
cerweima: function(e) {
this.setData({
meng: !this.data.meng,
erweima: !this.data.erweima,
})
},
cerc: function(e) {
this.setData({
erweima: !this.data.erweima,
meng: !this.data.meng,
})
},
async init( order_sn) {
// wx.showLoading();
var th = this;
var goods_id = 0,//商品ID,
pageteam=null,//
original_img=null ,//商品图片
order=null,//订单编号
id = 0,//团购id
pt_listno = "",//团编号
pt_prom_id = 0, //活动id
ee = this,
//team_id = 0,//活动id
ordertx=[],//头像图片
share_img=null,//分享图片
teamlist=null,//活动表
goods=null,//商品
teamgroup=null,//活動从表
max_num=0,//最低价格时的成团人数
p_status=1;
//--如果商家团的时候---
// await getApp().request.promisePost("/api/weshop/order/pay/vipAutoTuan", {
// data: {orderSn:order_sn,storeId:os.stoid }
// })
//获取order信息根据订单编号order_sn
// await getApp().request.promiseGet("/api/weshop/order/page", {
// data: { store_id: o.stoid, order_sn: order_sn,}
// }).then(res => {
// console.log('获取order信息====>', order);
// order = res.data.data.pageData[0];
// pt_prom_id = order.pt_prom_id;
// pt_listno = order.pt_listno;
// })
// if (this.data.payf || order.pt_status == 3) p_status = 3; //失败
// if (order.pt_status == 2 || order.pt_status == 4 || order.pt_status == 5)
// p_status = 2; //成功
// if (order.pt_status < 2 && !this.data.payf)
// p_status = 1; //正在进行
// if ( order.pt_status == 6) p_status = 4; //支付尾款失败
// //多少人参团头像
// // await getApp().request.promiseGet("/api/weshop/order/pagePtList", {
// // data: { store_id: o.stoid, pt_listno: pt_listno, }
// // }).then(res => {
// // ordertx = res.data.data.pageData;
// // })
// var min_price=0;
// //获取活动表的信息根据活动pt_prom_id
// await getApp().request.promiseGet("/api/weshop/teamlist/get/" + os.stoid + "/" + pt_prom_id, {
// data: { }
// }).then(res => {
// if (res.data.code==0){
// teamlist = res.data.data;
// this.setData({teamlist: teamlist});
// //获取当前时间,并且判断剩余时间
// var nt = ut.gettimestamp();
// teamlist.status = 0;
// if (nt >= teamlist.start_time) teamlist.status = 1;
// goods_id = res.data.data.goods_id;
// id = res.data.data.id;
// share_img = ee.data.imageurl + res.data.data.share_imgurl;
// //----------查看阶梯团------------
// if (teamlist.ct_rylist != "" && teamlist.ct_rylist != null && teamlist.ct_rylist != undefined){
// var ct_rylist = JSON.parse(teamlist.ct_rylist);
// var max=0; var pri=0;
// ct_rylist.forEach(function (val,ind) {
// if(val.rynum>max){
// max=val.rynum;
// pri = val.price;
// }
// })
// max_num=max;
// min_price=pri;
// }
// //获取商品信息
// getApp().request.promiseGet("/api/weshop/goods/get/" + os.stoid + "/" + goods_id, {
// }).then(res => {
// //商品地址
// original_img = ee.data.imageurl+ res.data.data.original_img,
// goods = res.data.data
// ee.setData({goods: goods,image: original_img,})
// })
// }
// })
//只装5个
// var ordertx2=[],sf_num=0,ct_nun=teamlist.ct_num;
// if(max_num){
// ct_nun=parseInt(max_num);
// if (ct_nun < ordertx.length) ct_nun = ordertx.length;
// }
// if(ct_nun>5) ct_nun=5;
// for(var i=0;i<ct_nun;i++){
// if (i >= ordertx.length) sf_num++
// else
// ordertx2.push(ordertx[i]);
// }
// var sf_arr=[];
// for (var i=0;i<sf_num;i++){
// sf_arr.push(i);
// }
//获取活动从表信息team_id:305暂时
// await getApp().request.promiseGet("/api/weshop/teamgroup/page" , {
// data: { store_id: os.stoid, listno: pt_listno, team_id: pt_prom_id }
// }).then(res => {
// teamgroup = res.data.data.pageData[0];
// if (teamgroup){
// var buy_start_date = ut.formatTime(teamgroup.buy_start_date, "yyyy-MM-dd hh:mm:ss");
// teamgroup.buy_start_date=buy_start_date;
// }
// })
// var ct_price = 0,
// num_0 = ordertx.length;
// if (teamlist.kttype == 3){
// var js_data = JSON.parse(teamlist.ct_rylist);
// js_data.forEach(function (val,ind) {
// if (num_0<=val.rynum && ct_price==0){
// ct_price=val.price;
// }
// })
// if(ct_price==0) ct_price=min_price;
// }
//获取大家都在团信息
// getApp().request.promiseGet("/api/weshop/teamlist/pageteam/1?store_id="+ os.stoid +"&is_end=0&is_show=1" , {
// data:{page:1,pageSize:2}
// }).then(res => {
// if(res.data.code==0 && res.data.data && res.data.data.pageData && res.data.data.pageData.length>0){
// pageteam = res.data.data.pageData;
// ee.setData({pageteam: pageteam,})
// }
// })
//--当是成团的时候的操作--
// if(order.pt_status==2 || order.pt_status==4 || order.pt_status==5){
// //设置值
// ee.setData({
// ordertx2: ordertx2, ordertx: ordertx, teamlist: teamlist, teamgroup: teamgroup, min_price: min_price,
// order: order, share_img: share_img,max_num:max_num,
// pindGoods: teamlist,is_show:1, zk:false,
// hiddenName: false, ct_price:ct_price,p_status:p_status,sf_arr:sf_arr});
// //--是否支付了尾款--
// if(order.pt_status==4 || order.pt_status==5){
// ee.setData({is_pay_wk:1});
// }
// }else{
// console.log("239什么鬼", teamlist);
// //设置值
// ee.setData({
// ordertx2: ordertx2, ordertx: ordertx, teamlist: teamlist, teamgroup: teamgroup,
// order: order, p_status: p_status, min_price:min_price,
// share_img: share_img, max_num: max_num, pindGoods: teamlist, is_show: 1,
// ct_price: ct_price, p_status: p_status,sf_arr:sf_arr});
// }
wx.hideLoading();
// wx.setNavigationBarTitle({
// title: "拼团详情",
// });
// ee.countDown2();
//获取分享图片的本地地址
// var path2 = os.imghost + th.data.luckyGoInfo.original_img;
// wx.getImageInfo({
// src: path2,
// success: function (res) {
// //res.path是网络图片的本地地址
// ee.data.share_img_localpath = res.path;
// },
// fail: function (res) {
// //失败回调
// }
// });
},
//---小于10的格式化函数----
// timeFormat(param) {
// return param < 10 ? '0' + param : param;
// },
// countDown2() {
// var th = this;
// // 获取当前时间,同时得到活动结束时间数组
// var newTime = ut.gettimestamp();
// var o = this.data.teamgroup;
// if(!o) return false;
// var endTime = o.kt_end_time;
// if (o.status == 0) endTime = o.start_time;
// //看一下,是否要支付尾款
// if(o.team_type==3 && th.data.order.pt_status==2){
// endTime = o.wk_end_time;
// }
// let obj = null;
// // 如果活动未结束,对时间进行处理
// if (endTime - newTime > 0) {
// let time = (endTime - newTime);
// // 获取天、时、分、秒
// let day = parseInt(time / (60 * 60 * 24));
// let hou = parseInt(time % (60 * 60 * 24) / 3600);
// let min = parseInt(time % (60 * 60 * 24) % 3600 / 60);
// let sec = parseInt(time % (60 * 60 * 24) % 3600 % 60);
// obj = {
// day: this.timeFormat(day),
// hou: this.timeFormat(hou),
// min: this.timeFormat(min),
// sec: this.timeFormat(sec)
// }
// } else {
// //活动已结束,全部设置为'00'
// obj = {
// day: '00',
// hou: '00',
// min: '00',
// sec: '00'
// }
// }
// var txt = "pindGoods.djs";
// th.setData({
// obj: obj
// });
// setTimeout(th.countDown2, 1000);
// },
//--定义的保存图片方法,分享团---
saveImageToPhotosAlbum: function () {
var that = this, th = that;
var app = getApp();
// 关闭底部分享弹窗
this.setData({
share_hidden: false,
});
//--先判断会员状态--
var user_info = getApp().globalData.userInfo;
if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) {
//getApp().my_warnning("请先登录",0,this);
// wx.navigateTo({ url: '/pages/togoin/togoin', })
// return false;
}
// if (this.data.share_hidden) {
// this.setData({ share_hidden: false,});
// };
//类型 0普通商品 1秒杀商品 2商家和会员团 3阶梯团 4阶梯团 9幸运购
var type = 9;
// if (type == 6) type = 2;
// if (this.data.prom_act && this.data.prom_act.kttype == 3) type = 3;
wx.showLoading({title: '生成海报中'});
//设置画板显示,才能开始绘图
// that.setData({
// canvasHidden: true
// })
var unit = that.data.screenWidth / 750 * 1.35; //基础单位,
// var path2 = th.data.iurl + th.data.luckyGoInfo.original_img;
var scene = th.data.param.goods_id + '';
scene+="."+9+"."+th.data.luckyGoInfo.id;
var user_id = getApp().globalData.user_id ? getApp().globalData.user_id : 0;
if (user_id > 0) {
scene += "_" + user_id;
};
//-- 如果不是会员分享过来的要分享给别人 --
if(getApp().globalData.room_id && th.data.data.goods_id == getApp().globalData.room_goods_id && !getApp().globalData.room_user_share) {
//固定房间是第3个字符
if (!user_id) scene += "_0";
scene += "_" + getApp().globalData.room_id;
};
///二微码
// var path3 = os.url + "/api/wx/open/app/user/getWeAppEwm/" +
// os.stoid + "?sceneValue=" + scene + "&pageValue=packageC/pages/luckyGo/luckyGo_goodsInfo/luckyGo_goodsInfo";
var path3 = os.url + "/api/wx/open/app/user/getWeAppEwm/" +
os.stoid + "?sceneValue=" + scene + "&pageValue=packageC/pages/luckyGo/luckyGo_goodsInfo/luckyGo_goodsInfo";
// 读取文件成功则OK--
wx.getImageInfo({
src: path3,
success: function (res) {
// 回调写法
th.get_head_temp(th.get_goods_temp, function () {
var vpath = res.path;
var context = wx.createCanvasContext('share');
// 先画背景
var pg_path = "../../../../images/share/share_bg.png";
// context.fillStyle="#FFFFFF";
// context.fillRect(0,0,554 * unit, 899 * unit);
// if(type == 0) {
// this.drawPoster(context);
// return false;
// };
//-- 如果有自定义海报的时候,判断背景的图片 --
// if (th.data.share_b_img) {
// pg_path = th.data.share_b_img;
// }
// context.drawImage(pg_path, 0, 0, 554 * unit, 899 * unit);
// if(type == 0) {
// // 如果是普通商品,绘制新海报
// th.drawPoster(context, unit, th.data.share_goods_img, vpath);
// } else {
context.drawImage(pg_path, 0, 0, 554 * unit, 899 * unit);
// };
// th.drawPoster(context, unit, th.data.share_goods_img, vpath);
//-- 是自定义海报的情况下 --
if(type != 0) {
if (th.data.poster && parseInt(th.data.poster.style) == 2) {
//在线上分享人的情况下
// if (parseInt(th.data.poster.show_headpic)) {
// //获取坐标
// var x = parseFloat(th.data.poster.head_x) * 2;
// var y = parseFloat(th.data.poster.head_y) * 2;
// var x1 = (x + 90) * unit;
// var y1 = (y + 50) * unit;
// //--昵称---
// context.setFontSize(24 * unit)
// context.setFillStyle("black")
// context.fillText(app.globalData.userInfo.nickname, x1, y1);
// var width = 24 * app.globalData.userInfo.nickname.length * unit + 4 * unit;
// //强烈推荐 改许程
// var tj_path = "../../../../images/share/q_tj.png";
// context.drawImage(tj_path, x1 + width, y1 - 22 * unit, 85 * unit, 30 * unit);
// context.setFontSize(16 * unit);
// context.setLineJoin('round'); //交点设置成圆角
// context.setFillStyle("white");
// context.fillText('强烈推荐', x1 + width + 8 * unit, y1 - 1 * unit);
// //context.setFillStyle("black")
// //context.setFontSize(24 * unit)
// //context.fillText(getApp().globalData.config.store_name, 40 * unit, 130 * unit);
// }
} else {
//--昵称---
context.setFontSize(24 * unit);
context.setFillStyle("black");
context.fillText(getApp().globalData.userInfo.nickname, 152 * unit, 60 * unit);
var width = 24 * getApp().globalData.userInfo.nickname.length * unit + 2 * unit;
//强烈推荐 改许程
// var tj_path = "../../../../images/share/q_tj.png";
// let txt_gn = th.data.luckGoInfo.group_num + '人团';
// let width_gn = ut.measureText(txt_gn, 15);
// context.drawImage(tj_path, 152 * unit + width, 54 * unit, (width_gn + 20) * unit, 30 * unit);
// context.setFontSize(16 * unit);
// context.setLineJoin('round'); //交点设置成圆角
// context.setFillStyle("white");
// context.fillText(txt_gn, 149 * unit + width + 15 * unit, 75 * unit);
// 发出幸运购活动邀请
context.setFillStyle("#7f7f7f")
context.setFontSize(21.3 * unit)
context.fillText("向您发出幸运购邀请", 152 * unit, 90 * unit);
}
};
// var share_title = th.data.data.goods_name;
var share_title = th.data.param.goods_name;
// if (th.data.prom_type == 1 || th.data.prom_type == 6 || th.data.prom_type == 4) {
// share_title = th.data.prom_act.share_title;
// if (!share_title) share_title = th.data.prom_act.title;
// if (th.data.prom_type == 4) share_title = th.data.prom_act.name;
// }
//---产品名称---
//文本换行 参数:1、canvas对象,2、文本 3、距离左侧的距离 4、距离顶部的距离 5、6、文本的宽度
if (type != 4 && type != 0) {
context.setFillStyle("black");
context.setFontSize(21.3 * unit);
th.draw_Text(context, share_title,
38 * unit, 180 * unit, 220 * unit, 220 * unit, unit);
//------产品的价格-------
context.setFontSize(23 * unit);
context.setFillStyle("red");
// var pri0 = th.data.data.shop_price;
var pri0 = th.data.luckyGoInfo.group_price/100;
if (th.data.prom_act) pri0 = th.data.prom_act.price;
pri0 = parseFloat(pri0).toFixed(2);
var wd1 = th.data.screenWidth - ut.measureText(pri0, 31 * unit) - 25;
context.fillText("¥", wd1 - 15, 185 * unit);
context.setFontSize(31 * unit);
context.fillText(pri0, wd1, 185 * unit);
var tj_path = "../../../../images/share/q_tj.png";
context.drawImage(tj_path, 315 * unit, 158 * unit, 85 * unit, 30 * unit);
context.setLineJoin('round'); //交点设置成圆角
context.setFontSize(18 * unit);
context.setFillStyle("white");
context.fillText('参团价', 330 * unit, 179 * unit);
//---市场价划掉---
context.setFillStyle("gray");
context.setFontSize(22 * unit);
pri0 = "零售价:¥" + th.data.luckyGoInfo.market_price.toFixed(2);
var wd2 = th.data.screenWidth - ut.measureText(pri0, 22 * unit) - 25;
context.fillText(pri0, wd2, 213 * unit);
context.setStrokeStyle('gray');
context.setLineWidth(1 * unit);
context.moveTo(wd2 - 5, 206 * unit);
context.lineTo(wd2 + ut.measureText(pri0, 22 * unit) + 5, 206 * unit);
context.stroke();
} else if(type == 4 && type != 0) {
context.setFillStyle("black");
context.setFontSize(21.3 * unit);
th.draw_Text(context, share_title,
38 * unit, 170 * unit, 20 * unit, 300 * unit, unit);
//------ 产品的价格 -----
var pri0 = th.data.prom_act.addmoney;
var integral = th.data.prom_act.integral;
var text = "";
if (integral) { text = integral + "积分"; }
if (pri0 && integral) { text += "+"; }
if (pri0) { text += "¥" + pri0; }
if (!pri0 && !integral) { text = "0积分"; }
context.setFillStyle("red");
context.fillText(text, 38 * unit, 235 * unit);
}
//---中间大图---
// if(type != 0) {
// ee.data.share_img_localpath
context.drawImage(that.data.share_img_localpath, 70 * unit, 250 * unit, 408 * unit, 408 * unit);
// wx.getImageInfo({
// src: th.data.iurl + th.data.luckyGoInfo.original_img,
// ssuccess: function (res) {
// //res.path是网络图片的本地地址
// console.log('res.path', res.path);
// context.drawImage(res.path, 70 * unit, 250 * unit, 408 * unit, 408 * unit);
// // ee.data.share_img_localpath = res.path;
// // tt();
// },
// fail: function (res) {
// // context.drawImage('../../../../images/share/default_g_img.gif', 70 * unit, 250 * unit, 408 * unit, 408 * unit);
// // ee.data.share_img_localpath= "../../../../images/share/default_g_img.gif"; //分享的图片不能用网络的
// // tt();
// }
// });
// context.drawImage(th.data.luckyGoInfo.original_img, 70 * unit, 250 * unit, 408 * unit, 408 * unit);
// };
//-------大图后面就不一样了-----------
switch (type) {
case 9:
//---画线---
context.setLineWidth(1 * unit)
context.moveTo(32 * unit, 680 * unit)
context.lineTo(520 * unit, 680 * unit)
context.stroke();
//---文字---
context.setFillStyle("black")
context.setFontSize(24 * unit)
// context.font = 'normal bold 18px';
// context.fillText(th.data.sto_sele_name_1, 40 * unit, 720 * unit);
//还差N人,即可成团
let group_num = th.data.luckyGoInfo.group_num;
let num_joined = th.data.luckyGoInfo.num;
let delta1 = group_num - num_joined;
let width_delta1 = ut.measureText(delta1, 15);
context.setFillStyle("black");
context.setFontSize(21.3 * unit);
context.fillText(group_num + "人团,还差", 40 * unit, 772 * unit);
context.setFillStyle("#FF6768");
context.setFontSize(21.3 * unit);
context.fillText(delta1, 160 * unit, 772 * unit);
context.setFillStyle("black");
context.setFontSize(21.3 * unit);
context.fillText("人,即可成团", (170 + width_delta1) * unit, 772 * unit);
// N人得商品,N人全额退款
let group_win = th.data.luckyGoInfo.group_win;
let delta2 = group_num - group_win;
let width_delta2 = ut.measureText(delta2, 16);
let width_groupNum = ut.measureText(group_num, 15);
let width_groupWin = ut.measureText(group_win, 15);
context.setFillStyle("#FF6768");
context.setFontSize(21.3 * unit);
context.fillText(group_win, 40 * unit, 806 * unit);
context.setFillStyle("black");
context.setFontSize(21.3 * unit);
context.fillText("人得商品,", (54 + width_groupWin) * unit, 806 * unit);
context.setFillStyle("#FF6768");
context.setFontSize(21.3 * unit);
context.fillText(delta2, 160 * unit, 806 * unit);
context.setFillStyle("black");
context.setFontSize(21.3 * unit);
context.fillText("人全额退款", (170 + width_delta2) * unit, 806 * unit);
// 并得帮团惊喜礼品
context.setFillStyle("black")
context.setFontSize(21.3 * unit)
context.fillText("并得帮团", 40 * unit, 840 * unit);
context.setFillStyle("#FF6768")
context.setFontSize(21.3 * unit)
context.fillText("惊喜礼品", 130 * unit, 840 * unit);
context.setFillStyle("black")
context.setFontSize(21.3 * unit)
context.fillText("!", 220 * unit, 840 * unit);
//---二维吗图---
//-- 自定义海报 --
if (th.data.poster) {
var erm_x = parseFloat(th.data.poster.ewm_x) * 2;
var erm_y = parseFloat(th.data.poster.ewm_y) * 2;
context.drawImage(vpath, erm_x * unit, erm_y * unit, 136 * unit, 136 * unit);
} else {
//---二维吗图---
context.drawImage(vpath, 390 * unit, 726 * unit, 136 * unit, 136 * unit);
}
break;
}
//--- 如果是自定义海报的时候 ---
if(type != 0) {
if (th.data.poster && parseInt(th.data.poster.style) == 2) {
//如果显示会员信息的话
if (parseInt(th.data.poster.show_headpic)) {
//获取坐标
var x = parseFloat(th.data.poster.head_x) * 2;
var y = parseFloat(th.data.poster.head_y) * 2;
//---绘制圆形要放在最后----
context.save();
context.beginPath();
var h_x = x * unit;
var h_y = y * unit;
var h_r = 40 * unit;
var cx = h_x + h_r;
var cy = h_y + h_r;
context.arc(cx, cy, h_r, 0, Math.PI * 2, false);
context.closePath();
context.fill();
context.clip();
context.drawImage(th.data.share_head, h_x, h_y, h_r * 2, h_r * 2);
context.restore();
}
} else {
//---绘制圆形要放在最后----
context.save();
context.beginPath();
var h_x = 60 * unit;
var h_y = 24 * unit;
var h_r = 40 * unit;
var cx = h_x + h_r;
var cy = h_y + h_r;
context.arc(cx, cy, h_r, 0, Math.PI * 2, false);
context.closePath();
context.fill();
context.clip();
context.drawImage(th.data.share_head, h_x, h_y, h_r * 2, h_r * 2);
context.restore();
}
};
//把画板内容绘制成图片,并回调 画板图片路径
context.draw(false, function () {
setTimeout(function () {
wx.canvasToTempFilePath({
x: 0,
y: 0,
width: 750,
height: 1217,
destWidth: 1.2 * 750 * 750 / that.data.screenWidth,
destHeight: 1.2 * 1217 * 750 / that.data.screenWidth,
canvasId: 'share',
success: function (res) {
console.log('生成成功');
that.setData({
shareImgPath: res.tempFilePath,
canvasHidden: true
})
if (!res.tempFilePath) {
wx.showModal({
title: '提示',
content: '图片绘制中,请稍后重试',
showCancel: false
})
return false;
}
that.setData({
showPoster: true,
});
wx.hideLoading();
},
fail: function() {
console.log('生成失败');
},
})
}, 500)
});
});
},
fail: function (res) {
// console.log(res);
wx.hideLoading();
}
});
},
//文本换行 参数:1、canvas对象,2、文本 3、距离左侧的距离 4、距离顶部的距离 5、6、文本的宽度
draw_Text: function (ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, unit) {
var lineWidth = 0;
var lastSubStrIndex = 0; //每次开始截取的字符串的索引
var han = 0;
for (let i = 0; i < str.length; i++) {
if (han == 2) return;
//lineWidth += ctx.measureText(str[i]).width;
lineWidth += ut.measureText(str[i], 21.3 * unit);
if (lineWidth > canvasWidth) {
han++;
if (han == 2)
ctx.fillText(str.substring(lastSubStrIndex, i) + '...', leftWidth, initHeight); //绘制截取部分
else
ctx.fillText(str.substring(lastSubStrIndex, i), leftWidth, initHeight);
initHeight += 22; //22为字体的高度
lineWidth = 0;
lastSubStrIndex = i;
titleHeight += 20;
}
if (i == str.length - 1) { //绘制剩余部分
ctx.fillText(str.substring(lastSubStrIndex, i + 1), leftWidth, initHeight);
}
}
},
//c点击打开拼团弹窗
cpd: function() {
console.log("heheh");
this.setData({ pd_xx: 1,})
},
//点击关闭拼团弹窗
close_pt_xx: function() {
this.setData({ pd_xx: 0, })
},
go_goodsinfo:function (e) {
var gid=e.currentTarget.dataset.gid;
var url="/pages/goods/goodsInfo/goodsInfo?goods_id="+gid;
wx.navigateTo({
url: url,
})//跳到非tabbar页
},
gohome:function () {
getApp().goto("/pages/index/index/index");
},
//--获取头像的本地缓存,回调写法--
get_head_temp:function (tt,func) {
var ee=this;
if(ee.data.share_head) {
tt(func);
return false;
}
//---获取分享图片的本地地址,头像和商品图片----
var path2 = getApp().globalData.userInfo.head_pic;
if(path2=="") {
ee.data.share_head ="../../../../images/share/hui_hear_pic.png";
tt(func);
} else {
path2=path2.replace("http://thirdwx.qlogo.cn","https://wx.qlogo.cn");
path2=path2.replace("https://thirdwx.qlogo.cn","https://wx.qlogo.cn");
wx.getImageInfo({
src: path2,
success: function (res) {
//res.path是网络图片的本地地址
ee.data.share_head = res.path;
tt(func);;
},
fail: function (res) {
ee.data.share_head = "../../../../images/share/hui_hear_pic.png"; //分享的图片不能用网络的
tt(func);
}
});
};
},
//--获取商品图片的本地缓存,回调写法--
get_goods_temp:function (tt) {
var ee=this;
if(ee.data.share_img_localpath) {
tt();
return false;
}
var path2 = os.imghost + ee.data.luckyGoInfo.original_img;
//获取商品是分享图信息
wx.getImageInfo({
src: path2,
success: function (res) {
//res.path是网络图片的本地地址
ee.data.share_img_localpath = res.path;
tt();
},
fail: function (res) {
ee.data.share_img_localpath= "../../../../images/share/default_g_img.gif"; //分享的图片不能用网络的
tt();
}
});
},
go_pay_wk:function(){
var url = "/pages/cart/cart_wk/cart_wk?order_id=" + this.data.order.order_id;
getApp().goto(url);
},
img_show_err:function(e){
var err_img = e.currentTarget.dataset.err;
var ob={};
ob[err_img] = this.data.iurl + "/miniapp/images/default_g_img.gif";
this.setData(ob);
},
//------ 分享配置 --------
onShareAppMessage: function (e) {
getApp().globalData.no_clear=1
var pagePath = `packageC/pages/luckyGo/luckyGo_goodsInfo/luckyGo_goodsInfo?goods_id=${this.data.param.goods_id}&prom_type=9&group_id=${this.data.param.group_id}`; //当前页面url
// console.log('pagePath=====xxxxxx>', pagePath);
var imgPath = this.data.iurl + this.data.luckyGoInfo.original_img;
if (pagePath.indexOf('/') != 0) {
pagePath = '/' + pagePath;
}
// if(getApp().globalData.user_id){
// if(pagePath.indexOf("?")>0){
// pagePath+="&first_leader="+getApp().globalData.user_id;
// }else{
// pagePath+="?first_leader="+getApp().globalData.user_id;
// }
// }
return {
title: "邀您一起参加幸运购",
path: pagePath,
imageUrl: imgPath,
}
},
// onShareTimeline() {
// // var store_name = getApp().globalData.config ? getApp().globalData.config.store_name:'';
// // var pagePath = this.route; //当前页面url
// // if(!store_name) store_name = getApp().globalData.setting.appName;
// // if (pagePath.indexOf('/') != 0) {
// // pagePath = '/' + pagePath;
// // }
// // return {
// // title: store_name + '-幸运购活动列表',
// // path: pagePath,
// // }
// },
clickShare() {
this.setData({
share_hidden: true,
});
},
send() {
this.setData({
share_hidden: false,
});
},
cancel() {
this.setData({
share_hidden: false,
});
},
closePoster() {
this.setData({
showPoster: false,
});
},
// 保存图片到手机
savePic() {
console.log('保存图片');
var self = this;
// 获取用户的当前设置,返回值中有小程序已经向用户请求过的权限
this.getSetting().then((res) => {
// 判断用户是否授权了保存到相册的权限,如果没有发起授权
if (!res.authSetting['scope.writePhotosAlbum']) {
this.authorize().then(() => {
// 同意授权后保存下载文件
this.saveImage(self.data.shareImgPath)
.then(() => {
self.setData({
showPoster: false
});
});
})
} else {
// 如果已经授权,保存下载文件
this.saveImage(self.data.shareImgPath)
.then(() => {
self.setData({
showPoster: false
});
});
}
})
},
// 保存图片到系统相册
saveImage(saveUrl) {
var self = this;
return new Promise((resolve, reject) => {
wx.saveImageToPhotosAlbum({
filePath: saveUrl,
success: (res) => {
wx.showToast({
title: '保存成功',
duration: 1000,
});
self.setData({
showPlaybill: 'true'
});
resolve();
},
fail: () => {
wx.showToast({
title: '保存失败',
duration: 1000,
});
}
})
})
},
// 获取用户已经授予了哪些权限
getSetting() {
return new Promise((resolve, reject) => {
wx.getSetting({
success: res => {
resolve(res)
}
})
})
},
// 发起首次授权请求
authorize() {
// isFirst 用来记录是否为首次发起授权,
// 如果首次授权拒绝后,isFirst赋值为1
let isFirst = wx.getStorageSync('isFirst') || 0;
return new Promise((resolve, reject) => {
wx.authorize({
scope: 'scope.writePhotosAlbum',
// 同意授权
success: () => {
resolve();
},
// 拒绝授权,这里是用户拒绝授权后的回调
fail: res => {
if(isFirst === 0) {
wx.setStorageSync('isFirst', 1);
wx.showToast({
title: '保存失败',
icon: 'none',
duration: 1000
})
} else {
this.showModal();
}
console.log('拒绝授权');
reject();
}
})
})
},
// 显示幸运购规则
showRules: function() {
this.setData({
showRules: true,
});
},
// 关闭幸运购规则
closeRules: function() {
this.setData({
showRules: false,
});
},
// 获取幸运购参团情况
async get_team_info () {
var th = this;
var team_id;
var luckyGoInfo;
var user_id = getApp().globalData.user_id;
// 邀请链接待完善
getApp().request.promiseGet("/api/weshop/prom/luckyActivity/page", {
data: {
store_id: o.stoid,
is_end: 0,
timetype: 1,
id: th.data.param.group_id,
}
}).then(res => {
if(res.data.code == 0) {
luckyGoInfo = res.data.data.pageData[0];
// else {
// team_id = luckyGoInfo.team_id;
// // 待完善
// if(luckyGoInfo.team_id == 0) {
// team_id = wx.getStorageSync('team_id');
// };
// };
th.setData({
luckyGoInfo,
});
//参团成功后,检查team_id
//如果team_id为0, 表示当前已开启新的一期,文字提示应改为’参团成功,本期幸运购已开团,中奖结果可点击下方查看参团列表‘
//如果team_id为0,取出之前保存的team_id替换掉,请求上一期已成团的幸运购活动
//如果从会员中心的幸运购列表邀请好友点击进来,不执行storage操作
if(th.data.param.from == 1) return false;
// if(team_id > 0) {
// wx.setStorage({
// key: 'team_id',
// data: team_id,
// });
// console.log('存储team_id', team_id);
// } else {
// let team_id2 = wx.getStorageSync('team_id');
// console.log('获取team_id', team_id2);
// th.setData({
// team_id: team_id2,
// // isSuccess: true,
// });
// };
// th.setData({
// luckyGoInfo,
// team_id,
// });
};
});
if(th.data.param.from == 1) {
team_id = th.data.param.team_id;
} else {
// 单独获取最新的team_id;
await getApp().request.promiseGet("/api/weshop/prom/luckyOrder/getUserOrderLastInfo/" + o.stoid + "/" + user_id + "/" + th.data.param.group_id, {
data: {
}
}).then(res => {
if(res.data.code == 0) {
// if(th.data.param.from == 1) {
// team_id = luckyGoInfo.team_id;
// } else {
// team_id = res.data.data.team_id;
// };
team_id = res.data.data.team_id;
th.setData({
team_id,
});
};
});
};
// wx.removeStorageSync('team_id');
// 幸运购成团成员
await getApp().request.promiseGet("/api/weshop/prom/luckyOrder/page", {
data: {
store_id: o.stoid,
team_id: team_id,
}
}).then(res => {
if(res.data.code == 0) {
console.log('当前参团成员', res, team_id);
let myId = getApp().globalData.userInfo.user_id;
let luckyGoMembers = res.data.data.pageData;
th.setData({
luckyGoMembers,
});
self.isMe(myId, luckyGoMembers);
};
});
},
// 判断自己是否中奖
isMe(myId, list) {
list.some((item, index) => {
if(item.team_status == 2) {
if(item.user_id == myId) {
self.setData({
iWin: true
});
return true;
};
}
});
},
//-----图片失败,默认图片-----
bind_bnerr: function (e) {
var _errImg = e.target.dataset.errorimg;
var _errObj = {};
_errObj[_errImg] = '/miniapp/images/default_g_img.gif';
this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
},
})