task_assistance.js
47 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
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
var auth = require("../../../utils/auth.js"),
rq = require("../../../utils/request.js");
var e = getApp(),
app = e,
i = require("../../../utils/util.js"),
ut = i,
s = e.globalData.setting,
os = s,
app_d = e.globalData;
var invalidSetTime = null
var regeneratorRuntime = require('../../../utils/runtime.js');
var com = require("../../giftpack/public/buy_com.js");
Page({
/**
* 页面的初始数据
*/
data: {
swpie_img: s.imghost + "/miniapp/images/user_index_powder.jpg",
defaultAvatar: s.imghost + "/miniapp/images/no-head.jpg",//助力头像的默认图
sw_index: 0, //轮播的下标控制
url: s.url, //接口网址
iurl: s.imghost,
endDate: "", //活动结束时间
activity_data: "25:20:59", //活动剩余时间
task_number: 0, //任务数
giftQty:0, //库存设置数
is_task: 0, //历史记录与任务
aitem: "", //活动的轮播图数据
switch_head: 0, //0:我的任务,1:记录
help_id: "", //活动的id canvasHidden: 0, //分享图片是否已经生成
gid: "",
timer: null, //全局的定时器
user_task_list: [], //会员列表
taskid: "", //任务id
usercount: 0, //参与的人数
dismantle: [], //帮拆记录数据集
is_user_task: null, //判断是不是领取的任务
zzjx_id: "", //真正进行的任务id
is_show: 0, //任务的加载更多
is_bc_show: 0, //帮拆的加载更多
bc_page: 1, //帮拆的页码
rw_page: 1, //任务的页码
block: 0, //阻断助力的我的任务在当前位置多次点击
is_dismantle: 0, //阻断助力的帮拆记录在当前位置多次点击
is_clik: 0,//点击的时候控制划动
is_dis_list: 0,//多个数据的时候
is_user_list: 0,//我的任务点击加载更多的后
//*********************************************start钱
canvasHidden: 1, //分享图片是否已经生成
is_share: 0, //是否显示画布
shareImgPath: [], //生成的图片
screenWidth: "", //用户的屏幕宽度
gid: "",
images: ["miniapp/images/friendhelp/help.png", "miniapp/images/friendhelp/background.png", "miniapp/images/friendhelp/no_check.png",
"miniapp/images/friendhelp/check.png", "miniapp/images/friendhelp/unfinished.png", "miniapp/images/xc_ellipsis.png"
], //固的分享图片
dynamic: null, //已助力的微信头像数组
head_pic_arr: [], //助力的头像
share_lb_img: "", //分享的礼包图片
is_generate: 0, //是否重复点击拆一拆
already: 0, //已有几人助力
lack: 0, //还差几人助力
zltime: "", //助力时间
djs: "", //定时器的显示
//*********************************************end
//距离失效------
invalidTime:0,
invalidState:true,
invalidObj:{
h:'00',
m:'00',
s:'00'
},
//--------------
// Hei: 0,
max_sw_height: 0,
imageUrl:'',
btn_color:'',
bg_color:'',
font_color:'',
//-- 屏幕实际的高度 --
r_heght:'',
//门店相关
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,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var th = this;
var help_id = options.help_id;
var nav_b = th.selectComponent("#nav_b"); //组件的id
nav_b.set_name("助力", "/pages/user/assistance/assistance");
th.setData({
help_id: help_id,
buyType:4
});
//start 钱
if (options.gid != undefined) {
th.setData({
gid: options.gid
})
}
if (options.taskid != undefined) {
th.setData({taskid:options.taskid})
}
//-- 获取分享人的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
}
})
}
console.log('aaaa');
th.syinfo();
th.close();
th.imageinfo();
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
});
})
},
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();
})
},
//选中任务
add_onlicke:function (e){
this.data.tg_dd=e;
var th=this;
if(this.data.is_nd_pk){
th.setData({ openSpecModal: 1 })
th.pp_bacK_func=th.add_onlicke_next; //设置回调函数
}else{
add_onlicke_next();
}
},
//选中任务保存下一步
add_onlicke_next: function () {
if(!this.data.tg_dd){
return false;
}
let e=JSON.parse(JSON.stringify(this.data.tg_dd));
this.data.tg_dd=null;
var th = this;
var taskid = e.target.dataset.taskid;
var help_id = th.data.help_id;
var user_id = getApp().globalData.user_id;
var stoid = os.stoid
var insert_dd={
helpId: help_id,
userId: user_id,
storeId: stoid,
taskId: taskid
};
//-- 如果需要门店的时候 --
if( th.data.is_nd_pk==1){
insert_dd.pickupId=th.data.def_pick_store.pickup_id;
}
getApp().request.json_post("/api/weshop/marketing/help/help/task/insert", insert_dd,
function (res) {
if (res.data.code == 0) {
getApp().my_warnning(res.data.data, 1, th);
//判断是不是领取的任务
th.get_user_task();
//会员任务列表
th.user_task_list();
} else {
getApp().my_warnning(res.data.msg, 0, th);
}
th.setData({submit:0})
th.closeSpecModal();
}
)
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
getApp().check_can_share();
//--先判断会员状态--
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.data.is_timer = 1;
var th = this;
var help_id = th.data.help_id;
var user_id = getApp().globalData.user_id;
/*-----助力活动(判断)-----*/
rq.get("/api/weshop/marketing/help/act/judge", {
data: {
userId: user_id,
storeId: os.stoid
},
success: function (res) {
if (res.data.code == 0) {
var help_data = res.data.data;
help_data.giftTitle=help_data.actName;
help_data.lbUrl=help_data.imageUrl;
let sData={
endDate: help_data.endDate,
btn_color: help_data.btn_color,
bg_color: help_data.bg_color,
font_color: help_data.font_color,
imageUrl: help_data.imageUrl,
sele_g:help_data
};
if(help_data.is_pickup){
sData.pickup_list=help_data.pickup_list;
}
th.setData(sData);
/*-----获取助力活动的任务-----*/
rq.get("/api/weshop/marketing/help/help/task/page", {
data: {
helpId: help_id,
storeId: os.stoid
},
success: function (su) {
var data = su.data;
if (data.code != 0) {
getApp().my_warnning(data.msg, 0, th);
return false;
}
if (data.code == 0 && data.data && data.data.pageData && data.data.pageData.length>0) {
//轮播图的数据
var data_aissa = data.data.pageData;
//当前时间戳
var nt = ut.gettimestamp();
data_aissa.forEach(function (val, ind) {
//已开始
if (val.start_time < nt && val.end_time > nt) data_aissa[ind].status = 0;
//未开始
else if (val.start_time > nt && val.end_time > nt) data_aissa[ind].status = 1;
//已结束
else if (val.start_time < nt && val.end_time < nt) data_aissa[ind].status = 2;
});
var task_number = data_aissa[0].giftQty - data_aissa[0].useGiftQty;
var taskid = data_aissa[0].id;
if(th.data.taskid) {
th.setData({
aitem: data_aissa,
task_number: task_number,
giftQty:data_aissa[0].giftQty,
});
th.go_to_task(th.data.taskid);
}else{
th.setData({
aitem: data_aissa,
task_number: task_number,
taskid: taskid,
giftQty:data_aissa[0].giftQty,
});
//判断是不是领取的任务
th.get_user_task();
th.get_user_task_num();
}
}
}
})
//任务时间 设置全局定时器
th.setData({
timer: setInterval(function () {
th.countDown();
}, 1000)
})
}
}
});
//会员任务列表
this.user_task_list();
//获取助力活动参与的人数
},
//记录加载更多
dismantle_record_list: function () {
this.setData({ is_dismantle: 0 });
this.dismantle_record();
},
dismantle_record_click(){
if(this.data.switch_head==1) return false;
this.setData({ is_dismantle: 0 });
this.dismantle_record();
},
//帮拆记录的
dismantle_record: function (e) {
//优化
if (this.data.is_dismantle == 1) {
return false;
}
var aitem = this.data.aitem; //任务的数据集
var sw_index = this.data.sw_index; //轮播的下标
//任务id
var taskid = aitem[sw_index].id;
var th = this;
var index = 1; //获取当前选择的是任务还是活动说明
var is_task = this.data.is_task; //0任务,1帮拆
if (is_task == undefined || is_task == null) {
is_task = 1;
}
var switch_head = this.data.switch_head;
if (switch_head == undefined || switch_head == null) {
switch_head = 1;
}
this.setData({
is_task: 1,
switch_head: 1,
block: 0,
});
var bc_page = th.data.bc_page;
rq.get("/api/weshop/marketing/help/help/task/involve/page", {
data: {
page: bc_page,
pageSize: 5,
taskId: taskid,
userId: getApp().globalData.user_id,
storeId: os.stoid
},
success: function (res) {
if (res.data.code == 0) {
th.setData({ is_dismantle: 1 });
var dismantle = res.data.data.pageData[0].zlHelpUser;
if (res.data.data.total > 5) {
var bc_page = th.data.bc_page + 1;
var dismantle_s = th.data.dismantle.concat(dismantle);
th.setData({
bc_page: bc_page,
is_bc_show: 1,
dismantle: dismantle_s,
is_dis_list: 1
})
} else {
th.setData({
dismantle: dismantle,
is_dis_list: 0
});
}
var dis_len = th.data.dismantle.length;
if (res.data.data.total == dis_len) {
th.setData({
is_dis_list: 0,
})
}
th.setData({
is_clik: 0,
});
} else {
th.setData({
dismantle: null
});
}
}
})
},
// 领取礼包
get_libao: function (e) {
var libao_id = e.currentTarget.dataset.libaoid; //礼包id
var taskid = e.currentTarget.dataset.taskid;
var taskingid = e.currentTarget.dataset.taskingid;
getApp().goto("/pages/user/assistance/giftpacklist?help_id=" + this.data.help_id + "&is_libao=" + 1 + "&taskId=" + taskid + "&id=" + taskingid);
},
//查看礼包id
select_libao: function (e) {
var orderSn = e.currentTarget.dataset.ordersn;
getApp().goto("/pages/user/assistance/giftpacklist?orderSn=" + orderSn);
},
//划动的时候监听
onSli: function (e) {
var arr = [];
this.setData({
dismantle: arr
});
var th = this;
var ind = e.detail.current;
var aitem = this.data.aitem;
var task_number = aitem[ind].giftQty - aitem[ind].useGiftQty;
var task_id = aitem[ind].id;
th.setData({
sw_index: ind,
task_number: task_number,
taskid: task_id,
is_dismantle: 0,
bc_page: 1,
giftQty:aitem[ind].giftQty,
});
if (this.data.switch_head == 1 && th.data.is_clik == 0) {
//判断有没有帮拆记录
this.dismantle_record();
}
//判断是不是领取的任务
th.get_user_task();
th.get_user_task_num();
},
//导航球
close: function () {
var th = this;
var nav_b = th.selectComponent("#nav_b"); //组件的id
nav_b.close_box();
},
//我的任务点击加载更多
task_list: function () {
this.setData({ block: 0 });
this.user_task_list();
},
// 获取会员的参与的任务列表 我的任务
user_task_list: function (e) {
var th = this;
//防止已经当前位置的时候多次点击
if (th.data.block == 1) { return false; }
th.data.block=1;
var index = 0;
var is_task = this.data.is_task; //0任务,1帮拆
if (is_task == undefined || is_task == null) {
is_task = 0;
}
var switch_head = this.data.switch_head;
if (switch_head == undefined || switch_head == null) {
switch_head = 0;
}
this.setData({
is_task: index,
switch_head: index,
user_task_list:[],
});
var help_id = th.data.help_id;
var user_id = getApp().globalData.user_id;
var rw_page = th.data.rw_page;
if(rw_page==1)th.data.zl_user_list=[];
var r=Math.random()*100;
rq.get("/api/weshop/marketing/help/help/user/page", {
data: {
page: rw_page,
pageSize: 5,
helpId: help_id,
storeId: os.stoid,
userId: user_id,
r:r,
},
success: function (su) {
th.data.block=0
if (su.data.code == 0) {
if (su.data.data.total > 5) {
var rw_page = th.data.rw_page + 1;
th.setData({
rw_page: rw_page,
is_show: 1
})
}
var user_list = su.data.data.pageData;
var user_lists = th.data.user_task_list.concat(user_list);
th.setData({
user_task_list: user_lists
});
} else {
th.setData({ is_user_list: 1 });
//getApp().my_warnning(su.data.msg, 0, th);
}
}
})
},
//判断是否有领取任务 获取正在进行中的任务
get_user_task: function () {
invalidSetTime ? clearTimeout(invalidSetTime) :''
this.setData({
invalidObj:{ h:'00', m:'00',s:'00'},
invalidState:true,
invalidTime:0
})
var user_id = getApp().globalData.user_id;
var th = this;
var aitem = th.data.aitem;
var sw_index = th.data.sw_index;
var taskid = aitem[sw_index].id
//-- 判断一下要不要弹出框,选择门店,只有在礼包含有礼品的时候 --
getApp().promiseGet('/api/weshop/marketing/help/help/task/getlbtype?storeId='+os.stoid+'&Id='+taskid,{}).then(gNew=>{
if(gNew && gNew.data.code==0 && gNew.data.data){
if(th.data.pickup_list && gNew.data.data.lb_type.indexOf(',1,')>-1){
th.data.is_nd_pk=1;
//-- 检测一下有没有门店 --
th.check_guide(function (){
com.wait_for_store_config(th);
com.set_user_mo_store(th, os, function () {
if (sele_g.pickup_list && th.data.def_pick_store) {
com.check_def_pk(th);
}
});
com.get_sto(th, os);
})
}
}
})
rq.get("/api/weshop/marketing/help/help/task/get", {
data: {
storeId: os.stoid,
userId: user_id,
taskId: taskid
},
success: function (res) {
console.log('任务---------------------------------------');
console.log(res);
if (res.data.code == 0) {
var is_usertask = res.data.data;
th.setData({
is_user_task: is_usertask,
});
th.getInvalidTime(taskid)
}
}
})
},
//获取失效时间
getInvalidTime(taskid){
let th = this;
let _this2=this;
rq.get("/api/weshop/marketing/giftbag/helpinfo/get", {
data: {
storeId: os.stoid,
// userId: user_id,
taskId: taskid,
helpId:th.data.help_id
},
success:async function (res) {
console.log('获取失效时间------');
console.log(res);
if (res.data.code == 0) {
let openTime =th.data.is_user_task ? th.data.is_user_task.openTime : 0
let validTime=res.data.data.validTime
let invalidTime =0
if (openTime && validTime > 0) {
invalidTime = openTime*1 + validTime*60*60
}
th.setData({
invalidTime
});
th.invalid_count_down() //失效倒计时
}
}
})
},
// 距离失效倒计时
invalid_count_down(){
let invalidTime = this.data.invalidTime
let nowTime = parseInt((new Date().getTime())/1000)
if (invalidTime) {
let disTime = invalidTime - nowTime
if (disTime>0) {
let h = parseInt(disTime/(60*60))
h = h*1 < 10 ? '0'+ h : h
let m= parseInt((disTime/60)%60)
m = m*1 < 10 ? '0' + m : m
let s = disTime % 60
s = s*1 < 10 ? '0'+s : s
this.setData({
'invalidObj.h':h,
'invalidObj.m':m,
'invalidObj.s':s,
})
invalidSetTime=setTimeout(this.invalid_count_down,1000)
}else{
this.setData({
invalidObj:{ h:'00', m:'00',s:'00'},
invalidState:false
})
}
}else{
this.setData({
invalidObj:{h:'00', m:'00',s:'00'}
})
}
},
//获取助力活动参与的人数
get_user_task_num: function () {
var th = this;
var help_id = th.data.help_id;
var aitem = this.data.aitem; //任务的数据集
var sw_index = this.data.sw_index; //轮播的下标
//任务id
var taskid = aitem[sw_index].id;
rq.get("/api/weshop/marketing/help/involve/help/act/people/count", {
data: {
helpId: help_id,
storeId: os.stoid,
taskId: taskid
},
success: function (su) {
if (su.data.code == 0) {
var usercount = su.data.data.countAll;
th.setData({
usercount: usercount
});
}
}
})
},
//轮播卡死的重置
changeGoodsSwip: function (detail) {
if (detail.detail.source == "touch") {
//当页面卡死的时候,current的值会变成0
if (detail.detail.current == 0) {
//有时候这算是正常情况,所以暂定连续出现3次就是卡了
let swiperError = this.data.swiperError
swiperError += 1
this.setData({
swiperError: swiperError
})
if (swiperError >= 3) { //在开关被触发3次以上
this.setData({
sw_index: this.data.preIndex
}); //,重置current为正确索引
this.setData({
swiperError: 0
})
}
} else { //正常轮播时,记录正确页码索引
this.setData({
preIndex: detail.detail.current
});
//将开关重置为0
this.setData({
swiperError: 0
})
}
}
},
// 轮播图点击左边
click_pre: function () {
var arr = [];
this.setData({
dismantle: arr
});
var index = this.data.sw_index;
index--;
if (index < 0) return;
var aitem = this.data.aitem;
var task_number = aitem[index].giftQty - aitem[index].useGiftQty;
var task_id = aitem[index].id;
this.setData({
sw_index: index,
task_number: task_number,
taskid: task_id,
is_dismantle: 0,
is_clik: 1,
bc_page: 1,
giftQty:aitem[index].giftQty
})
if (this.data.switch_head == 1) {
//判断有没有帮拆记录
console.log("往左点////////////////////");
this.dismantle_record();
}
if (this.data.switch_head == 0) {
//判断有没有领取任务
this.get_user_task();
}
},
//轮播图点击右边
click_next: function () {
var arr = [];
this.setData({
is_clik: 1,
dismantle: arr
});
var index = this.data.sw_index;
index++;
if (index >= this.data.aitem.length) return;
var aitem = this.data.aitem;
var task_number = aitem[index].giftQty - aitem[index].useGiftQty;
var task_id = aitem[index].id;
this.setData({
sw_index: index,
task_number: task_number,
taskid: task_id,
is_dismantle: 0,
bc_page: 1,
giftQty:aitem[index].giftQty
})
if (this.data.switch_head == 1) {
this.dismantle_record();
}
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
//--清理定时器--
clearInterval(this.data.timer);
},
//----助力任务的时间-----
countDown() {
if (!this.data.is_timer) return false;
var th = this;
// 获取当前时间,同时得到活动结束时间数组
var newTime = ut.gettimestamp();
// 对结束时间进行处理渲染到页面
// var o = endTimeList[i];
var endTime = th.data.endDate;
// if (o.status == 0) endTime = o.start_time
var obj = null;
// 如果活动未结束,对时间进行处理
if (endTime - newTime > 0) {
var time = (endTime - newTime);
// 获取天、时、分、秒
var day = parseInt(time / (60 * 60 * 24));
var hou = parseInt(time % (60 * 60 * 24) / 3600);
var min = parseInt(time % (60 * 60 * 24) % 3600 / 60);
var 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 = "aitem[" + 0 + "].djs";
th.setData({
[txt]: obj
});
},
//---小于10的格式化函数----
timeFormat(param) {
return param < 10 ? '0' + param : param;
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () { getApp().globalData.no_clear=1
},
preview: function () {
var th = this;
var shareImgPath = th.data.shareImgPath;
getApp().globalData.no_clear=1;
wx.previewImage({
url: shareImgPath[0],
urls: shareImgPath
})
},
//关闭分享显示
close_share: function () {
var th = this;
th.setData({
is_share: 0
})
},
syinfo: function () {
console.log('bbb----------');
var th = this;
//获取用户设备信息,屏幕宽度
wx.getSystemInfo({
success: res => {
var rpxR = 750 / res.screenWidth;
var r_height=res.windowHeight*rpxR;
console.log(r_height,'11111')
th.setData({
screenWidth: res.screenWidth,
r_heght:r_height
})
}
})
},
//************************ */
shareFrends: function (e) {
var th = this;
if (th.data.is_generate) return;
th.data.is_generate = 1;
th.setData({canvasHidden:0});
var scene = this.data.is_user_task.id;
///二微码
var path3 = os.url + "/api/wx/open/app/user/getWeAppEwm/" +
os.stoid + "?sceneValue=" + scene + "&pageValue=pages/user/assistance/friend_assistance";
console.log('二维码路径');
console.log(path3);
//读取文件成功则OK--
wx.getImageInfo({
src: path3,
success: function (res) {
var ewm_path = res.path; //
//var act_time="2019.06.26 - 2019.07.02"; //活动的时间
var bg_time = ut.formar_no_full(th.data.dynamic.beginDate,'.');
var end_time = ut.formar_no_full(th.data.dynamic.endDate,'.');
var act_time = bg_time + "-" + end_time;
var iurl = th.data.iurl; //图片地址前缀
const ctx = wx.createCanvasContext('share_id'); //绘图上下文
var unit = th.data.screenWidth / 750 * (750/445);
var numsize = 20 * unit; //几人助力字体大小
var head_list_img = th.data.head_pic_arr;
var num = th.data.head_pic_arr.length; //已有几位好友助力
var aitem = th.data.aitem; //任务的数据集
var sw_index = th.data.sw_index; //轮播的下标
//任务id
var help_num = aitem[sw_index].helpNum;
var q_num = help_num - num; //还差几位好友助力
var already = num.toString().length + 1; //已有几位好友助力
var lack = q_num.toString().length + 1; //还差几位好友助力
var size = 15 * unit;
var imagesize = 40 * unit; //助力人的图片大小
var left = 74 * unit; //助力人头像跟左边的距离
var spacing = 12 * unit; //助力人图片间距
var images = th.data.images;
ctx.drawImage(images[0], 0, 0, 445 * unit, 1200 * th.data.screenWidth / 750); //分享的背景图片
ctx.drawImage(images[1], 37 * unit, 185 * unit, 370 * unit, 377 * unit); //分享的背景图片
console.log(111);
console.log(th.data.share_lb_img);
ctx.drawImage(th.data.share_lb_img, 90 * unit, 231 * unit, 266 * unit, 160 * unit); //分享的礼包的背景图片
ctx.setFillStyle("rgb(221,153,116)");
ctx.setFontSize(size)
ctx.fillText("已有", 77 * unit, 430 * unit);
ctx.setFillStyle("#FF4746");
ctx.setFontSize(numsize)
ctx.fillText(num + "位", 108 * unit, 430 * unit);
ctx.setFillStyle("rgb(221,153,116)");
ctx.setFontSize(size)
ctx.fillText("好友助力,还差", 116 * unit + already * numsize * unit, 430 * unit);
ctx.setFillStyle("#FF4746");
ctx.setFontSize(numsize);
ctx.fillText(q_num + "位", 223 * unit + already * numsize * unit, 430 * unit);
ctx.setFillStyle("rgb(221,153,116)");
ctx.setFontSize(size);
ctx.fillText("达成助力", 230 * unit + lack * numsize * unit + already * numsize * unit, 430 * unit);
var c = num / help_num;
ctx.drawImage(images[2], 65 * unit, 445 * unit, 320 * unit, 12 * unit);
ctx.drawImage(images[3], 65 * unit, 445 * unit, 320 * unit * c, 12 * unit);
var head_list_num = 30;
var is_head_list = 0;
//当需要助力人数小与6个
if (help_num < 6) {
var pos_arr = ut.get_box_arr(help_num, 225.25 * unit, 505 * unit, spacing, imagesize / 2);
var now_ind = 0;
//--判断已助力的人数--
for (var a = 0; a < head_list_img.length; a++) {
var pos = pos_arr[now_ind];
ut.draw_circle(ctx, pos.x, pos.y, imagesize / 2, head_list_img[a], 'red', unit);
now_ind++;
}
//--显示还差的人数--
if (help_num - head_list_img.length > 0) {
var neednum = help_num - head_list_img.length;
//这个是还未助力的位置
for (var i = 0; i < neednum; i++) {
var pos = pos_arr[now_ind];
now_ind++;
// 助力人的头像
ctx.drawImage(images[4], pos.x - imagesize / 2, pos.y - imagesize / 2, imagesize, imagesize); //分享的背景图片
}
}
} else if (help_num > 7) {
//助力头像数量, 是不是要显示省略图
var zl_head = 0, is_sheng = 0;
if (head_list_img.length >= 6) {
zl_head = 5; is_sheng = 1;
} else {
zl_head = head_list_img.length;
}
//判断已助力的人数
for (var a = 0; a < zl_head; a++) {
//绘制头像
ut.draw_circle(ctx, left + imagesize / 2, 505 * unit, imagesize / 2, head_list_img[a], 'red', unit);
left += imagesize + spacing;
}
//如果是省略号的话
if (is_sheng) {
ctx.drawImage(images[5], left, 505 * unit - imagesize / 2, imagesize, imagesize); //头像的省略图片
} else {
//这个是还未助力的位置
for (var i = 0; i < 6 - head_list_img.length; i++) {
// 助力人的头像
ctx.drawImage(images[4], left, 505 * unit - imagesize / 2, imagesize, imagesize); //分享的?号图片
left += imagesize + spacing;
}
}
} else {
// 判断已助力的人数
for (var a = 0; a < head_list_img.length; a++) {
ctx.save();
ctx.beginPath(); //开始绘制
ctx.arc(left + imagesize / 2, 505 * unit, imagesize / 2, 0, 2 * Math.PI);
ctx.setLineWidth(4 * unit);
ctx.setStrokeStyle('red');
ctx.setFillStyle("white");
ctx.fill();
ctx.clip();
ctx.drawImage(head_list_img[a], left, 505 * unit - imagesize / 2, imagesize, imagesize);
ctx.restore();
left += imagesize + spacing;
}
if (6 - head_list_img.length > 0) {
var neednum = 6 - head_list_img.length;
if(neednum>6) neednum=6;
//这个是还未助力的位置
for (var i = 0; i < neednum; i++) {
// 助力人的头像
ctx.drawImage(images[4], left, 505 * unit - imagesize / 2, imagesize, imagesize); //分享的背景图片
left += imagesize + spacing;
}
}
}
ctx.setFillStyle("rgb(255,255,255)");
ctx.setFontSize(size);
ctx.fillText("优惠乐翻天,精彩就在你身边!", 37 * unit, 595 * unit);
ctx.setFillStyle("rgb(255,255,255)");
ctx.setFontSize(size);
ctx.fillText(act_time, 37 * unit, 620 * unit); //绘制活动是时间
ctx.setFillStyle("rgb(255,255,255)");
ctx.setFontSize(size);
ctx.fillText("长按识别二维码,可帮我助力!", 37 * unit, 660 * unit);
ctx.drawImage(ewm_path, 325 * unit, 585 * unit, 77 * unit, 77 * unit); //分享的背景图片
ctx.save();
//读取文件成功则OK--
// wx.getImageInfo({
// src: path3,
// success: function (res) {
//把画板内容绘制成图片,并回调 画板图片路径
ctx.draw(false, function () {
setTimeout(function () {
wx.canvasToTempFilePath({
x: 0,
y: 0,
width: 750,
height: 1200,
destWidth:1.2* 750 * 750 / th.data.screenWidth,
destHeight:1.2 *1200* 750 / th.data.screenWidth,
canvasId: 'share_id',
success: function (res) {
wx.hideLoading();
var shareImgPath = th.data.shareImgPath;
shareImgPath[0] = res.tempFilePath;
th.setData({
shareImgPath: shareImgPath,
canvasHidden: 1,
is_share: 1,
is_generate: 0,
})
if (!res.tempFilePath) {
wx.showModal({
title: '提示',
content: '图片绘制中,请稍后重试',
showCancel: false
})
return false;
}
},
fail(r) {
}
}, 500)
})
})
}
})
},
preview: function () {
var th = this;
var shareImgPath = th.data.shareImgPath;
getApp().globalData.no_clear=1;
wx.previewImage({
url: shareImgPath[0],
urls: shareImgPath
})
th.setData({
is_share: 0
})
},
//关闭分享显示
close_share: function () {
var th = this;
wx.hideLoading();
th.setData({
is_share: 0
})
},
//把固定的图片加载到本地
imageinfo: async function () {
var th = this;
var images = th.data.images;
var iurl = th.data.iurl;
for (var i in images) {
var img_path = iurl + images[i];
await getApp().request.promise_downimg(img_path).then(res => {
images[i] = res;
})
}
th.data.images = images;
},
//好友猜一猜
save_share: function (e) {
if (!this.data.invalidState) {
getApp().showWarning("该任务已失效");
return
}
var th = this;
var aitem = this.data.aitem; //任务的数据集
var sw_index = this.data.sw_index; //轮播的下标
var sw_item = aitem[sw_index];
//任务id
var taskid = sw_item.id;
th.setData({
is_share: 1
})
wx.showLoading({
title: "加载中",
})
var url = "/api/weshop/marketing/help/help/task/involve/page";
getApp().request.promiseGet(url, {
isShowLoading: false,
data: {
storeId: os.stoid,
taskId: taskid,
userId: getApp().globalData.user_id
}
}).then(res => {
if (res.data.code == 0) {
var data = res.data.data.pageData; //帮拆数组
if (data.length > 0) {
th.data.dynamic = data[0];
var path = th.data.iurl + (sw_item.giftBagUrl?sw_item.giftBagUrl:'/miniapp/images/no-head.jpg');
//先获取礼包分享时的本地路径
getApp().request.promise_downimg(path).then(res => {
th.data.share_lb_img = res;
//先获取会员的头像
th.info_head(th.shareFrends);
});
}
} else {
wx.hideLoading();
getApp().my_warnning(res.data.msg, 0, th);
}
})
},
//把已助力好友头像下载到本地
info_head: async function (func) {
var th = this;
var images = th.data.dynamic.zlHelpUser;
var arr = new Array();
var block = th.data.block;
if (images) {
th.data.head_pic_arr.length = 0;
for (var i in images) {
var img_path = images[i].headPic;
img_path=img_path.replace("http://thirdwx.qlogo.cn", "https://wx.qlogo.cn");
img_path=img_path.replace("https://thirdwx.qlogo.cn", "https://wx.qlogo.cn");
await getApp().request.promise_downimg(img_path).then(res => {
th.data.head_pic_arr.push(res);
})
}
}
func();
},
//立即兑换
redeem_now: function (e) {
var libao_id = e.currentTarget.dataset.libaoid;
var sw_index = this.data.sw_index;
var aitem = this.data.aitem;
var taskid = aitem[sw_index].id;
var taskingid = e.currentTarget.dataset.taskingid;
getApp().goto("/pages/user/assistance/giftpacklist?help_id=" + this.data.help_id + "&is_libao=" + 1 + "&taskId=" + taskid + "&id=" + taskingid);
},
//礼包的详情 轮播图
libao_details: function (e) {
var th = this;
var help_id = th.data.help_id; //活动id
var taskId = e.currentTarget.dataset.taskid; //任务id
getApp().goto("/pages/user/assistance/giftpacklist?help_id=" + help_id + "&is_libao=" + 0 + "&taskId=" + taskId);
},
user_task_list_click:function(){
if (this.data.switch_head==0) return false;
this.data.block=0;
this.user_task_list();
},
go_task:function(e){
var taskid=e.currentTarget.dataset.taskid;
this.go_to_task(taskid);
},
go_to_task(task_id){
var index = 0;
var aitem = this.data.aitem;
for(var i=0;i<aitem.length;i++){
if(aitem[i].id==task_id){
index=i;break;
}
}
//当是助力首页跳转过来的
if(index==this.data.sw_index){
this.get_user_task();
}
this.setData({
sw_index: index,
taskid: task_id,
is_dismantle: 0,
bc_page: 1,
})
this.get_user_task_num();
},
//--测试用--
test:function(){
var ind=this.data.sw_index;
var aitem = this.data.aitem;
var task_id = aitem[ind].id;
getApp().goto("/pages/test/zhuli_test?taskId="+task_id);
},
imageLoad: function(e) {
var winWid = wx.getSystemInfoSync().windowWidth;
var imgwidth = e.detail.width;
var imgheight = e.detail.height;
//宽高比
var ratio = imgwidth / imgheight;
//计算的高度值
var viewHeight = winWid / ratio * 0.8;
if (this.data.max_sw_height < viewHeight) {
this.setData({
max_sw_height: viewHeight
});
};
},
buy_libao: function () {
com.buy_libao(this)
},
//-- 选择门店 --
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});
},
//获取搜索门店输入的值
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
})
}
}
}
},
})