giftpacklist.js
46.1 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
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
var e = getApp(),
a = e.globalData.setting,
os = a,
t = e.request,
d = e.globalData;
var ut = require("../../../../utils/util.js");
var com = require("../../../../pages/giftpack/public/buy_com.js");
Page({
data: {
url: a.url, //接口网址
iurl: a.imghost, //图片前缀网址
isBuy: 0,
getGiftID: '', //礼包id
giftImage: '',
giftTitle: '',
giftDate: '',
giftPrice: '',
giftIntegral: '',
giftPosPrice: '',
giftQty: '',
giftRemark: '',
giftType: '',
actTitle: '',
getUrl: '',
wareCard: [],
orderSn: "", //订单编号
lbId: "",
code: "", //核销码
c_state: "0", //判断是否已经使用, 0正常 1已使用 2已过期
is_lb: 0, //是否有礼包
default_color: null,
first_leader: e.globalData.first_leader || 0, // 推荐人ID
//门店相关
ismend: 0,
is_sec_mend: 0,
sto_sele_name: "", //选中的门店名称
sto_sele_id: "", //选中的门店id
sto_sele_distr: "", //选择的门店的配送方式
is_show_sto_cat: 1, //是否显示门店分类
only_pk: null,
all_sto: null,
sec_sto: null, //选择了的门店分类
pickpu_list: null, //读出的所有门店list
def_pickpu_list: null, //一开始5个门店list
sec_pick_index: 0, //第二级门店选择ID
fir_pick_index: 0, //第一级门店选择ID
all_pick_list: null,//所有的门店先记录起来
select_store: 0, //选择更多
index: 1,
more_store: 0, //选择门店
sort_store: 0, //门店分类
choice_sort_store: 0, //选择分类门店
new_user: 0, //新用户
def_pick_store: null, // 默认的门店
fir_def_store: null, //客户默认的门店的
lat: null, //维度
lon: null, //经度
is_get_local_ok: 0, //获取坐标是否完成
region_name: "门店分类", //区域的名字
is_gps: 1,
open_ind_store: 0, //哪里打开的门店列表的控制属性
default_store: {}, //创建添加默认门店地址的对象
store: 0,
openSpecModal: 0,
sto_sele_name_1: '',
share_goods_img:'', //礼包的分享图
giftImageCover:null,
canvasHidden:true,
screenWidth: 0,
submit:0,
is_detail:1, //是详情页面的购买
keyword:'', //门店搜索
sec_i:-1,//选中分类门店 下标
},
onLoad: function (options) {
if(options.transfer){
let obj=getApp().globalData.ts_trans_data;
options= JSON.parse(JSON.stringify(obj));
getApp().globalData.ts_trans_data=null;
}
//定义第一次进入
this.data.fir_in=1;
var th = this;
this.setData({
params: options,
})
getApp().getConfig(function (e) {
th.setData({sto_sele_name_1: e.store_name})
})
getApp().getConfig2(function (e) {
var json_d = JSON.parse(e.switch_list);
th.setData({
bconfig: e,
sys_switch: json_d,
is_retail_price: json_d.is_retail_price || 0
});
})
//获取用户设备信息,屏幕宽度
wx.getSystemInfo({
success: res => {
th.setData({
screenWidth: res.screenWidth
})
}
});
},
init() {
let options = this.data?.params; // this.data == null ? undefined:this.data.params
var th = this;
this.setData({
getUserID: d.user_id,
getStorageID: a.stoid,
})
if(!options.lbId && options.scene){
var gid_str = decodeURIComponent(options.scene);
gid_str = gid_str.split("_");
options.lbId=gid_str[0];
options.first_leader=gid_str[1];
options.isBuy=1;
}
this.setData({
isBuy: options.isBuy,
getGiftID: options.lbId,
orderSn: options.orderSn,
flag: options.flag, // 如果从商品详情页的促销处点击专享礼包跳转到此页,则flag为1
})
if (options.lbId) th.data.lbId = options.lbId;
//-- 获取分享人的ID --
var first_leader = options.first_leader || getApp().globalData.first_leader;
if (first_leader) {
this.setData({
first_leader,
})
//-- user_id代过来免登录 --
getApp().globalData.first_leader = first_leader;
//调用接口判断是不是会员
getApp().request.promiseGet("/api/weshop/shoppingGuide/get/" + os.stoid + "/" + first_leader, {}).then(res => {
if (res.data.code == 0) {
getApp().globalData.guide_id = res.data.data.id;
getApp().globalData.guide_pick_id= res.data.data.pickup_id
}
})
}
th.close();
if (this.data.flag == 1) {
this.getZxlbDetails();
} else {
if (this.data.isBuy == 0) {
this.GetMyGiftList();
} else if (this.data.isBuy == 1) {
this.GetBuyGiftList();
}
}
},
onShow: function () {
this.setData({submit:0})
var th=this;
//判断是不是第一次进入
if(this.data.fir_in){
this.data.fir_in=0;
}else{
//富友支付插件的判断
ut.fy_back('',0);
com.set_py_fir();
if(th.data.ok_order_sn){
//-- 通联的第三方支付的返回优化 --
var money=th.data.payMoney;
var back_url = "/packageF/pages/giftpack/payment/payment?money=" + money + "&order_sn=" + th.data.ok_order_sn;
ut.is_pay_ok(th.data.ok_order_sn,back_url,'none',function (){
if(!th.data.ok_order_sn) return false;
getApp().request.promiseGet("/api/weshop/marketing/my/giftbag/detail/get",
{data:{storeId:os.stoid,orderSn:th.data.ok_order_sn,userId:getApp().globalData.user_id}}).then(res=>{
th.data.ok_order_sn=null;
if(res.data.code==0 && res.data.data){
var item=res.data.data;
if(item.payState==1){
//支付支付,返回首页
ut.m_toast('支付成功');
setTimeout(()=>{
getApp().goto(back_url);
},1000)
}else{
//支付支付,返回首页
ut.m_toast('支付失败');
}
}
})
},null,null,1);
th.data.ok_order_sn=null;
}
}
getApp().check_can_share(this);
getApp().is_Single_page(this, function () {
//--先判断会员状态--
var user_info = getApp().globalData.userInfo;
if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) {
getApp().goto('/packageE/pages/togoin/togoin');
return false;
}
this.init();
})
this.setData({ submit:0})
},
//获取搜索门店输入的值
input_store: function(e) {
this.setData({
keyword: e.detail.value
})
},
//搜索门店
searchfn(){
let choice_sort_store = this.data.choice_sort_store
if (choice_sort_store==0) { //全局搜索
let all_pick_list = this.data.all_pick_list
let def_pickpu_list = this.data.def_pickpu_list
let keyword = this.data.keyword
if (keyword) {
let arr=all_pick_list.filter( item =>{
let i = item.pickup_name.indexOf(keyword)
if (i > -1) {
return true
}else{
return false
}
})
if (arr && arr.length>0) {
if(this.data.is_show_sto_cat==1){
this.setData({
def_pickpu_list:arr
})
}else{
this.setData({
only_pk:arr
})
}
}else{
wx.showToast({
title: '没有搜索到门店',
icon: 'none',
duration: 2000
})
}
}else{
if (this.data.is_show_sto_cat==1) {
this.setData({
def_pickpu_list:all_pick_list.slice(0,10)
})
}else{
this.setData({
only_pk:all_pick_list
})
}
}
}else{ //分类下搜索
let sec_i=this.data.sec_i
let all_sto = this.data.all_sto
let old_all_sto = this.data.old_all_sto
if (!old_all_sto) {
this.setData({
old_all_sto:JSON.parse(JSON.stringify(all_sto))
})
}
let sec_sto= this.data.sec_sto
let sec_arr = this.data.old_all_sto[sec_i].s_arr
let keyword = this.data.keyword
let text='sec_sto.s_arr'
if (keyword) {
let arr=sec_arr.filter( item =>{
let i = item.pickup_name.indexOf(keyword)
if (i > -1) {
return true
}else{
return false
}
})
if (arr && arr.length>0) {
this.setData({
[text]:arr
})
}else{
wx.showToast({
title: '没有搜索到门店',
icon: 'none',
duration: 2000
})
}
}else{
if(this.data.old_all_sto){
this.setData({
[text]: this.data.old_all_sto[sec_i].s_arr
})
}else{
this.setData({
[text]: all_sto[sec_i].s_arr
})
}
}
}
},
GetBuyPrice: function (e) {
var that = this.data;
var th = this;
//如果还没有开始的话
if (th.data.isStart != 1) {
getApp().my_warnning("活动还没有开始", 0, th);
return false;
}
this.data.payMoney = th.data.sele_g.payMoney;
th.setData({buyType: 2})
if (th.data.sele_g.is_pickup) {
th.setData({
openSpecModal: 1
})
} else {
var my_confirm = th.selectComponent("#my_confirm"); //组件的id
my_confirm.open(
"是否确定购买该礼包",
"取消",
"确定",
function () {
my_confirm.open_cancel(0);
},
function () {
my_confirm.open_cancel(0);
com.buy_libao(th)
}
)
}
},
GetBuyIntegral: function (e) {
var that = this.data;
var th = this;
//如果还没有开始的话
if (th.data.isStart != 1) {
getApp().my_warnning("活动还没有开始", 0, th);
return false;
}
th.setData({buyType: 1});
if (th.data.sele_g.is_pickup) {
th.setData({
openSpecModal: 1
})
} else {
var my_confirm = th.selectComponent("#my_confirm"); //组件的id
my_confirm.open(
"是否确定兑换该礼包",
"取消",
"确定",
function () {
my_confirm.open_cancel(0);
},
function () {
my_confirm.open_cancel(0);
com.buy_libao(th)
})
}
},
GetMyGiftList: function () {
var _this = this;
var th = this;
getApp().request.get('/api/weshop/marketing/my/giftbag/detail/get', {
isShowLoading: true,
data: {
"storeId": a.stoid, //商家ID
"userId": d.user_id, //用户ID
"orderSn": th.data.orderSn
},
success: function (res) {
if (res.data.code == 0) {
console.log('商品------++')
console.log(res)
th.setData({
giftImage: th.data.iurl + res.data.data.lbUrl,
giftImageCover: th.data.iurl + (th.data.params.cover_img ? th.data.params.cover_img: res.data.data.lbUrl),
giftTitle: res.data.data.giftTitle,
default_color: res.data.data.bgcolor
})
if (res.data.data.iswarelbtype == 1) {
th.setData({iswarelbtype: 1})
}
if (!res.data.data.giftRemark || res.data.data.giftRemark == '') {
th.setData({
giftRemark: '暂无详情......'
})
} else {
th.setData({
giftRemark: res.data.data.giftRemark.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block"')
})
}
//---获取日期的时间戳---
var t_endtime = res.data.data.endTime;
t_endtime = t_endtime.replace(/-/g, '/');
var t_date = new Date(t_endtime) / 1000;
var t_now = ut.gettimestamp();
var t_starttime = res.data.data.starTime;
t_starttime = t_starttime.replace(/-/g, '/');
var t_sdate = new Date(t_starttime) / 1000;
if (res.data.data.goodsUseState) th.setData({
c_state: 1
})
else if (t_date <= t_now)
th.setData({
c_state: 2
})
else if (t_sdate > t_now)
th.setData({
c_state: -1
})
th.setData({
giftDate: res.data.data.endTime,
giftPosPrice: res.data.data.giftPosPrice,
giftQty: res.data.data.giftQty,
giftIntegral: res.data.data.payIntegral,
giftPrice: res.data.data.payMoney,
giftType: res.data.data.actType,
actTitle: res.data.data.actTitle,
wareCard: res.data.data.wareCard,
lbId: res.data.data.lbId
})
//判断是否有礼包
for (var i = 0; i < res.data.data.wareCard.length; i++) {
if (res.data.data.wareCard[i].lbType == 1) {
th.setData({
is_lb: 1
})
break;
}
}
if (res.data.data.pickup_id) {
getApp().request.get("/api/weshop/pickup/get/" + os.stoid + "/" + res.data.data.pickup_id, {
success: function (res) {
if (res.data.code == 0) {
th.setData({pick_up: res.data.data});
}
}
});
}
} else {
getApp().my_warnning(res.data.msg, 0, th);
return false;
}
}
});
},
check_guide(func){
var first_leader=this.data.first_leader;
if(!first_leader){
func();
return false;
}
if(this.data.is_geted_guide_pick){
func();
return false;
}
if(getApp().globalData.guide_pick_id){
func();
return false;
}
var th=this;
getApp().request.promiseGet("/api/weshop/shoppingGuide/get/" + os.stoid + "/" + first_leader, {}).then(res => {
if (res.data.code == 0) {
getApp().globalData.guide_pick_id= res.data.data.pickup_id;
}
th.data.is_geted_guide_pick=1;
func();
})
},
GetBuyGiftList: function () {
var _this2 = this;
var th = this.data;
getApp().request.get('/api/weshop/marketing/giftbag/detail/get', {
isShowLoading: true,
data: {
"storeId": a.stoid, //商家ID
"userId": d.user_id, //用户ID
"giftBagId": th.getGiftID,
isnNewUserLb:1
},
success: function success(res) {
if (res.data.code == 0) {
_this2.setData({
giftImage: th.iurl + res.data.data.lbUrl,
giftImageCover: th.iurl + (_this2.data.params.cover_img ? _this2.data.params.cover_img: res.data.data.lbUrl),
giftTitle: res.data.data.giftTitle,
default_color: res.data.data.bgcolor
})
if (res.data.data.giftRemark == '') {
_this2.setData({
giftRemark: '暂无详情......'
})
} else {
_this2.setData({
giftRemark: res.data.data.giftRemark.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block"')
})
}
//-- 如果只限定链接的时候,要取消分享按钮 --
if(res.data.data.is_share){
wx.hideShareMenu();
wx.offCopyUrl()
//替换掉复制链接
wx.onCopyUrl(() => {
setTimeout(()=>{
wx.setClipboardData({
data: '暂不支持分享',
success (res) { }
})
},500)
return { query: 'a=1&b=2' }
})
}
var isStart = 0;
var now = ut.gettimestamp();
var str = res.data.data.starTime.replace(/-/g, '/');
var start = Date.parse(new Date(str));
start = start / 1000;
if (start < now) isStart = 1;
_this2.setData({
giftDate: res.data.data.endTime,
giftStart: res.data.data.starTime,
giftPosPrice: res.data.data.giftPosPrice,
giftQty: res.data.data.giftQty,
giftIntegral: res.data.data.payIntegral,
giftPrice: res.data.data.payMoney,
giftType: res.data.data.actType,
actTitle: res.data.data.actTitle,
wareCard: res.data.data.wareCard,
isStart: isStart,
sele_g: res.data.data,
is_share:res.data.data.is_share
})
var sele_g = res.data.data;
//需不需要门店,不需要门店返回
if (!sele_g.is_pickup) return false;
//-- 检测一下有没有门店 --
_this2.check_guide(function (){
com.wait_for_store_config(_this2);
com.set_user_mo_store(_this2, os, function () {
if (sele_g.pickup_list && _this2.data.def_pick_store) {
com.check_def_pk(_this2);
}
});
com.get_sto(_this2, os);
})
} else {
getApp().my_warnning(res.data.msg, 0, _this2);
setTimeout(()=>{
getApp().goto('/pages/index/index/index')
},2000)
return false;
}
}
});
},
getZxlbDetails: function () {
var th = this;
getApp().request.get('/api/weshop/marketing/giftbag/detail/getNew', {
isShowLoading: true,
data: {
"storeId": a.stoid, //商家ID
//"userId": d.user_id, //用户ID
"giftBagId": th.data.lbId
},
success: function (res) {
if (res.data.code == 0) {
th.setData({
giftImage: th.data.iurl + res.data.data.lbUrl,
giftImageCover: th.data.iurl + (th.data.params.cover_img ? th.data.params.cover_img: res.data.data.lbUrl),
giftTitle: res.data.data.lbTitle,
default_color: res.data.data.bgcolor
})
if (res.data.data.lbIntro == '') {
th.setData({
giftRemark: '暂无详情......'
})
} else {
th.setData({
giftRemark: res.data.data.lbIntro.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block"')
})
}
//---获取日期的时间戳---
let exchangeType = res.data.data.exchangeType;
let exchangeDay = res.data.data.exchangeDay;
let exchangeStartTime = res.data.data.exchangeStartTime;
let exchangeEndTime = res.data.data.exchangeEndTime;
// let t_endtime;
if (exchangeType == 2) {
if (exchangeStartTime == 0 || !exchangeStartTime) {
exchangeStartTime = ut.gettimestamp();
}
exchangeStartTime = ut.formatTime(exchangeStartTime, 0);
exchangeEndTime = ut.formatTime(exchangeEndTime, 0);
}
th.setData({
// giftDate: t_endtime,
giftPosPrice: res.data.data.oldPrice,
giftQty: res.data.data.lbNum,
giftIntegral: res.data.data.exchangeIntegral,
giftPrice: res.data.data.lbPrice,
giftType: res.data.data.actType,
actTitle: res.data.data.actTitle,
wareCard: res.data.data.wareCard,
lbId: res.data.data.lbId,
exchangeType: exchangeType,
exchangeDay: exchangeDay,
exchangeStartTime: exchangeStartTime,
exchangeEndTime: exchangeEndTime,
})
//判断是否有礼包
for (var i = 0; i < res.data.data.wareCard.length; i++) {
if (res.data.data.wareCard[i].lbType == 1) {
th.setData({
is_lb: 1
})
break;
}
}
} else {
getApp().my_warnning(res.data.msg, 0, th);
return false;
}
}
});
},
onUnload:function(){
wx.offCopyUrl()
},
onHide: function() {
wx.offCopyUrl()
},
//显示核销码
code_show: function (e) {
var th = this;
//--获取成功的时候--
var no = th.data.code;
var qc_com = th.selectComponent("#qc_com"); //组件的id
var obj = {
val: no,
content: "请将二维码展示给核销员,收货更快捷"
};
qc_com.open(obj)
},
//获取核销码
getcode: function (e) {
var th = this;
var orderSn = th.data.orderSn; //订单号
let codeId = e.currentTarget.dataset.codeid;
var json = {
"storeId": a.stoid,
"orderSn": orderSn,
}
if (codeId && codeId !== "") {
json.id = codeId
}
var data = JSON.stringify(json);
var url = th.data.url + "/api/weshop/marketing/gift/goods/verify/code/get"; //预约接口地址
getApp().request.json_post(url, json,
function (res) {
if (res.data.code == 0) {
th.setData({
code: res.data.data
})
th.code_show();
} else {
getApp().my_warnning(res.data.msg, 0, th);
}
},
function (res) {
},
"put"
)
},
//界面跳转
goto: function (e) {
var th = this;
var url = e.currentTarget.dataset.url;
getApp().goto(url);
},
//图片失败,默认图片
bind_bnerr2: function (e) {
var _errImg = e.target.dataset.errorimg;
var _errObj = {};
_errObj[_errImg] = "/miniapp/images/giftbag/gift01.png";
this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
},
//图片失败,默认图片
bind_bnerr: function (e) {
var _errImg = e.target.dataset.errorimg;
var _errObj = {};
_errObj[_errImg] = this.data.iurl + "miniapp/images/big_back.jpg";
this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
//this.setData({ giftImage: this.data.iurl + "/miniapp/images/giftbag/gift01.png"});
},
//关闭导航
close: function () {
var th = this;
var nav_b = th.selectComponent("#nav_b"); //组件的id
nav_b.close_box();
nav_b.set_name("礼包", "/packageF/pages/giftpack/buygiftpack/giftpackbuy");
},
//--- 分享设置 --
onShareAppMessage: function (e) {
getApp().globalData.no_clear = 1;
var curPage = this;
var pagePath = curPage.route; //当前页面url
if (pagePath.indexOf('/') != 0) {
pagePath = '/' + pagePath;
}
pagePath += "?isBuy=1" + "&lbId=" + this.data.getGiftID + "&first_leader=" + this.data.getUserID;
// if (this.data.isBuy == 0) {
// pagePath += "&orderSn=" + this.data.orderSn;
// } else {
// pagePath += "&lbId=" + this.data.getGiftID;
// }
// console.log('pagePath', pagePath);
return {
title: "礼包详情",
path: pagePath,
}
},
/**
* 用户分享朋友圈
*/
onShareTimeline() {
getApp().globalData.no_clear = 1;
var pagePath = "&isBuy=1" + "&lbId=" + this.data.lbId + "&first_leader=" + this.data.getUserID;
var user_id = getApp().globalData.user_id;
if (!user_id) user_id = 0;
return {
title: "礼包详情",
query: 'first_leader=' + user_id + pagePath
}
},
//免费领取
GetFree: function (e) {
var that = this.data;
var th = this;
//如果还没有开始的话
if (th.data.isStart != 1) {
getApp().my_warnning("活动还没有开始", 0, th);
return false;
}
th.setData({buyType: 3});
if (th.data.sele_g.is_pickup) {
th.setData({
openSpecModal: 1
})
} else {
// var id = e.currentTarget.dataset.id;//活动id
var my_confirm = th.selectComponent("#my_confirm"); //组件的id
my_confirm.open(
"是否确定领取该礼包",
"取消",
"确定",
function () {
my_confirm.open_cancel(0);
},
function () {
my_confirm.open_cancel(0);
com.buy_libao(th)
})
}
},
//--- 设置一下默认库存的数量 ----
set_def_storage(ee) {
var that = this, th = this;
that.data.fir_def_store = ee;
that.setData({
def_pick_store: ee,
sto_sele_name: ee.pickup_name,
sto_sele_id: ee.pickup_id,
sto_sele_distr: ee.distr_type
})
},
// 选择门店
choice_store: function (ee) {
this.setData({
keyword:''
})
//--先判断会员状态--
var user_info = getApp().globalData.userInfo;
if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) {
wx.navigateTo({
url: '/packageE/pages/togoin/togoin',
})
return false;
}
var th = this;
var ind = ee.currentTarget.dataset.ind;
var bconfig = th.data.bconfig;
//如果开启了,则不在选择门店
if (this.data.sys_switch.is_pricing_open_store && getApp().globalData.pk_store) {
return false;
}
if (!th.data.only_pk && !th.data.def_pickpu_list) {
getApp().confirmBox("门店库存不足", null, 25000, !1);
return false;
}
if (th.data.only_pk && !th.data.only_pk.length) {
getApp().confirmBox("门店库存不足", null, 25000, !1);
return false;
}
if (th.data.def_pickpu_list && !th.data.def_pickpu_list.length) {
getApp().confirmBox("门店库存不足", null, 25000, !1);
return false;
}
if (bconfig && bconfig.is_sort_storage) {
wx.getLocation({
type: 'gcj02',
success: function (res) {
th.data.lat = res.latitude;
th.data.lon = res.longitude;
th.data.is_get_local_ok = 1;
th.setData({
is_gps: 1
});
//th.onShow();
com.get_sto(th, os);
},
fail: function (res) {
//th.onShow();
th.data.is_get_local_ok = 1;
com.get_sto(th, os);
if (res.errCode == 2) {
th.setData({
is_gps: 0
});
if (th.data.is_gps == 0) {
getApp().confirmBox("请开启GPS定位", null, 25000, !1);
}
} else {
th.setData({
is_gps: "3"
});
}
}
})
} else {
th.data.is_get_local_ok = 1;
com.get_sto(th, os);
}
if (ind != undefined && ind != null) {
this.setData({
open_ind_store: ind,
store: 1,
openSpecModal: !1,
openSpecModal_pt: !1,
openSpecModal_flash_normal: !1,
})
} else {
this.setData({
store: 1,
openSpecModal: !1,
openSpecModal_pt: !1,
openSpecModal_flash_normal: !1
})
}
},
//关闭选择门店
close_popup: function (e) {
var th = this;
this.setData({
store: 0,
choice_sort_store: 0,
sort_store: 0,
fir_pick_index: 0,
sec_pick_index: 0
})
var openindstore = this.data.open_ind_store;
if (openindstore == 1) {
th.setData({
openSpecModal: !0,
openSpecModal_ind: openindstore,
});
} else if (openindstore == 2) {
th.setData({
openSpecModal: !0,
openSpecModal_ind: openindstore,
});
} else if (openindstore == 4) { //4就是拼团
th.setData({
openSpecModal_pt: 1, //打开拼团购买界面
store: 0, //关闭门店
choice_sort_store: 0, //关闭门店2级
sort_store: 0, //关闭门店2级
});
} else {
th.setData({
store: 0,
choice_sort_store: 0,
sort_store: 0
})
}
},
//选择更多门店
more_store: function () {
this.setData({
sort_store: 1
});
},
// 返回按钮
returns: function () {
this.setData({
sort_store: 0,
choice_sort_store: 0
});
},
//---选择分类门店---
choice_sort_store: function (e) {
var index = e.currentTarget.dataset.index;
var region_name = e.currentTarget.dataset.region;
var item = this.data.all_sto[index];
this.setData({
region_name: region_name,
sort_store: 0,
choice_sort_store: 1,
sec_i:index,
sec_sto: item,
sec_pick_index: 0
});
},
choose_for_store_fir: function (e) {
var index_c = e.currentTarget.dataset.ind;
var th = this;
th.setData({
fir_pick_index: index_c
})
},
//确定def_pick为选择的门店
sure_pick: function (e) {
var th = this;
var item = null;
var openindstore = th.data.open_ind_store;
if (th.data.choice_sort_store == 0) {
var index = th.data.fir_pick_index;
if (th.data.is_show_sto_cat == 1) {
item = th.data.def_pickpu_list[index];
} else {
item = th.data.only_pk?th.data.only_pk[index]:null; //当没有门店分类的时候
}
} else {
var index = th.data.sec_pick_index;
item = th.data.sec_sto.s_arr[index];
}
if(!item) return false;
if (!th.data.sele_g) return false;
th.setData({
def_pick_store: item,
sto_sele_name: item.pickup_name,
sto_sele_id: item.pickup_id,
sto_sele_distr: item.distr_type,
store: 0,
choice_sort_store: 0,
fir_pick_index: 0,
openSpecModal: !0,
});
},
//---点击二级之后的选择---
choose_for_store: function (e) {
var index_c = e.currentTarget.dataset.ind;
var th = this;
th.setData({
sec_pick_index: index_c,
fir_pick_index: index_c
})
},
//把选择的门店设置成默认的门店def_pick
set_def_pick: function (e) {
var th = this;
var item = null;
if (th.data.choice_sort_store == 0) {
var index = th.data.fir_pick_index;
if (th.data.is_show_sto_cat == 1) {
item = th.data.def_pickpu_list[index];
} else {
item = th.data.only_pk?th.data.only_pk[index]:null; //当没有门店分类的时候
}
} else {
var index = th.data.sec_pick_index;
item = th.data.sec_sto.s_arr[index];
}
if(!item) return false;
th.setData({
def_pick_store: item,
sto_sele_name: item.pickup_name,
sto_sele_id: item.pickup_id,
sto_sele_distr: item.distr_type,
store: 0,
choice_sort_store: 0,
openSpecModal: !0,
});
var user_id = getApp().globalData.user_id;
var def_pickup_id = item.pickup_id;
getApp().request.put('/api/weshop/users/update', {
data: {
user_id: user_id,
def_pickup_id: def_pickup_id
},
success: function (res) {
if (res.data.code == 0) {
if (th.data.choice_sort_store == 0) th.setData({
fir_pick_index: 0
});
getApp().globalData.pk_store = item;
} else {
getApp().my_warnning("设置默认门店地址失败", 0, th)
}
}
});
},
closeSpecModal: function () {
this.setData({openSpecModal: 0});
},
buy_libao: function () {
com.buy_libao(this)
},
clickShare() {
// if (!getApp().globalData.user_id) {
// getApp().goto("/packageE/pages/togoin/togoin");
// return false;
// }
this.setData({
share_hidden: true,
});
},
send() {
this.setData({
share_hidden: false,
});
},
cancel() {
this.setData({
share_hidden: false,
});
},
//--定义的保存图片方法,分享团---
saveImageToPhotosAlbum: function () {
//--先判断会员状态--
// 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: '/packageE/pages/togoin/togoin',})
// return false;
// }
if (this.data.share_hidden) {
this.setData({share_hidden: false,});
}
wx.showLoading({title: '生成中...',})
var that = this, th = that;
//设置画板显示,才能开始绘图
that.setData({
canvasHidden: false
})
var app = getApp();
var unit = that.data.screenWidth / 750 * 1.35; //基础单位,
var scene = th.data.lbId + "";
var user_id = getApp().globalData.user_id ? getApp().globalData.user_id : 0;
if (user_id > 0) {
scene += "_" + user_id;
}
///二微码
var path3 = os.url + "/api/wx/open/app/user/getWeAppEwm/" +
os.stoid + "?sceneValue=" + scene + "&pageValue=packageF/pages/giftpack/giftpacklist/giftpacklist";
// 读取文件成功则OK--
wx.getImageInfo({
src: path3,
success: function (res) {
th.get_goods_temp(function () {
var vpath = res.path;
var context = wx.createCanvasContext('share');
// let share_goods_img = th.params.cover_img
th.drawPoster(context, unit, th.data.share_goods_img, vpath, 0);
//把画板内容绘制成图片,并回调 画板图片路径
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) {
that.setData({
shareImgPath: res.tempFilePath,
canvasHidden: true
})
if (!res.tempFilePath) {
wx.showModal({
title: '提示',
content: '图片绘制中,请稍后重试',
showCancel: false
})
return false;
}
that.setData({
showPoster: true,
});
wx.hideLoading();
}
})
}, 800)
});
})
},
fail: function (res) {
console.log(res);
wx.hideLoading();
}
});
},
//-- 小程序绘制海报 --
drawPoster(context, unit, img, vpath, type) {
// 1.灰色背景
context.setFillStyle('#f2f1f6');
context.rect(0, 0, 554 * unit, 899 * unit);
context.fill();
// 2.商城名称
let shopName = this.data.sto_sele_name_1;
context.setTextAlign('center');
context.setFontSize(26 * unit);
context.setFillStyle('black');
context.fillText(shopName, 277 * unit, 60 * unit);
// 3.推荐来源
let fromText = `来自${getApp().globalData.userInfo.nickname}的推荐`;
context.setTextAlign('center');
context.setFontSize(22 * unit);
context.setFillStyle('#96959a');
context.fillText(fromText, 277 * unit, 105 * unit);
// 4.海报背景
context.setFillStyle('white');
context.fillRect(37 * unit, 157 * unit, 480 * unit, 673 * unit);
// 5.商品图片
// 图片的x坐标
let bg_x = 37 * unit
// 图片的y坐标
let bg_y = 157 * unit
// 图片宽度
let bg_w = 480 * unit
// 图片高度
let bg_h = 474 * unit
// 图片圆角
let bg_r = 4
// 绘制海报背景图片圆角
context.save()
context.beginPath()
context.arc(bg_x + bg_r, bg_y + bg_r, bg_r, Math.PI, Math.PI * 1.5)
context.arc(bg_x + bg_w - bg_r, bg_y + bg_r, bg_r, Math.PI * 1.5, Math.PI * 2)
context.arc(bg_x + bg_w, bg_y + bg_h, bg_r, 0, Math.PI * 0.5)
context.arc(bg_x, bg_y + bg_h, 0, Math.PI * 0.5, Math.PI)
context.clip()
context.drawImage(img, bg_x, bg_y, bg_w, bg_h);
context.restore();
// 6.强烈推荐
let src = '';
context.beginPath();
if (type == 0) { // 普通
src = '../../../images/share/q_tj.png';
context.drawImage(src, 54 * unit, 648 * unit, 85 * unit, 30 * unit);
context.setFontSize(16 * unit)
context.setFillStyle("white")
context.setTextAlign('left');
context.fillText('强烈推荐', 64 * unit, 668 * unit);
}
let price = this.data.giftPrice;
let giftIntegral = this.data.giftIntegral;
context.setFontSize(32 * unit);
context.setFillStyle('#DE1117');
var price_txt="";
if(price || giftIntegral){
if(price){
price_txt='¥' + price;
if(giftIntegral) price_txt+='+';
}
if(giftIntegral) price_txt+=giftIntegral+'积分';
}else{
price_txt="¥0";
}
context.fillText(price_txt, 54 * unit, 735 * unit);
var wp= 62 * unit;
var hp=765 * unit
this.draw_pos_price(context,wp,hp,this.giftPosPrice,unit);
// 8.商品标题
context.setFontSize(20 * unit);
context.setFillStyle('#898989');
getApp().draw_Text(context, this.data.giftTitle, 54 * unit, 800 * unit, 240 * unit, 280 * unit, unit, 1);
// 9.小程序码
context.drawImage(vpath, 375 * unit, 660 * unit, 120 * unit, 120 * unit);
context.setFontSize(16 * unit);
context.setFillStyle('#777');
context.fillText('长按识别二维码', 378 * unit, 810 * unit);
// 10.竖线
context.beginPath();
context.setFillStyle('#eee');
context.rect(354 * unit, 670 * unit, 1 * unit, 130 * unit);
context.fill();
},
//---市场价划掉---
draw_pos_price(context,w,h,market_price,unit){
if(!this.is_retail_price) return false;
context.setFillStyle("gray")
context.setFontSize(22 * unit)
var pri0 = "¥" + market_price.toFixed(2);
context.fillText(pri0, w, h);
var c_h=h-6;
context.setStrokeStyle('gray');
context.setLineWidth(1 * unit);
context.moveTo(w - 5, c_h);
context.lineTo(w + ut.measureText(pri0, 22 * unit) + 5, c_h);
context.stroke();
},
//--获取商品图片的本地缓存,回调写法--
get_goods_temp: function (tt) {
var ee = this;
if (ee.data.share_goods_img) {
tt();
return false;
}
var img_url = ee.data.giftImageCover ? ee.data.giftImageCover : ee.data.giftImage;
//获取商品是分享图信息
wx.getImageInfo({
src: img_url,
success: function (res) {
//res.path是网络图片的本地地址
ee.data.share_goods_img = res.path;
tt();
},
fail: function (res) {
//获取默认空白图
wx.getImageInfo({
src: ee.data.iurl+'/miniapp/images/default_g_img.gif',
success: function(res) {
ee.data.share_goods_img = res.path; //分享的图片不能用网络的
tt();
}
})
}
});
},
closePoster() {
this.setData({
showPoster: false,
});
},
// 保存图片到手机
savePic() {
getApp().savePic(this);
},
// 预览海报
previewPoster() {
getApp().globalData.no_clear=1;
wx.previewImage({
current: this.data.shareImgPath, // 当前显示图片的http链接
urls: [this.data.shareImgPath] ,// 需要预览的图片http链接列表
});
},
});