team_show.js
39.3 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
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');
Page({
data: {
num: 1, //输入框值 加减之间的值
minusStatus: 'disable', //禁用按钮
ii_endname: 'disable', //吐司的禁用按钮
pd_xx: false, //弹框
buy_start_date: null, //转换完的时间
ssl: null,
yijian: false, //一键参加按钮显示隐藏
//选择门店
qh: true, //取货
xz: false, //选择
one: false, //第一层显示隐藏
se: false, //已选择的值
list: false, //第二层显示隐藏
ssl_child: null, //第二层的值
sele_dl_name: "", //选择的值
end_name: "", //最后显示的值
ii: 0, //选择门店显示隐藏
zk: true, //展开列表显示隐藏
stoid: o.stoid,
hiddenName: false, //收起列表显示隐藏
teamlist: null, //活动主表
teamgroup: null, //活动从表
goods: null, //商品数据
pindGoods: null, //拼单数据
imageurl: os.imghost, //有礼派图片地址
team_id: 0, //支付是否成功
listno: "", //订单编号
//选择的门店id
pick_id:0,
//会员团满团时的判断
tg_arr:null,
//是否显示
is_show:0,
//是不是团结束
is_group_end:0,
//团结束的提示语句
end_text:"",
//是开团或者参团,0参团,1开团(但是,商家团还是参团)
is_kt_or_ct:0,
//判断redis的数组
redis_arr:null,
iurl:os.imghost,
openSpecModal: !1,
openSpecModal_pt: !1, //拼单的弹起,
//门店相关
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,//所有的门店先记录起来
bconfig:null,
def_pick_store: null, // 默认的门店
fir_def_store:null, //客户默认的门店的
lat: null, //维度
lon: null, //经度
is_get_local_ok: 0, //获取坐标是否完成
},
onLoad: function(options) {
wx.setNavigationBarTitle({ title: "拼团订单",})
//var postdata=getApp().globalData.to_group;
var postdata=options;
var tg_id = postdata.tg_id, first_leader=options.first_leader;
//如果tg_id是空的话
if(tg_id==undefined || tg_id==null || tg_id==""){
var tg_id_str=decodeURIComponent(postdata.scene);
tg_id_str=tg_id_str.split("_");
tg_id=tg_id_str[0];
if(tg_id_str.length>1){
first_leader=tg_id_str[1];
}
}
//--判断一下是不是导购--
if(first_leader){
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;
}
})
}
this.setData({tg_id: tg_id });
getApp().globalData.to_group=null;
var th=this;
getApp().getConfig2(function(e) {
th.setData({ bconfig: e,});
th.wait_for_store_config(); //获取默认的门店
})
},
//显示加载
onShow:function(){
var tg_id = this.data.tg_id,th=this;
this.init(tg_id);
},
//c点击打开拼团弹窗
cpd: function() {
this.setData({ pd_xx: true,})
},
//点击关闭拼团弹窗
close_pt_xx: function() {
this.setData({ pd_xx: false, })
},
//按钮点击一键参加团按钮
cyijian: function(e) {
//--先判断会员状态--
var user_info=getApp().globalData.userInfo;
if(user_info==null || user_info.mobile==undefined || user_info.mobile=="" || user_info.mobile==null){
wx.navigateTo({ url: '/pages/togoin/togoin', })
return false;
}
var is_kt_or_ct=e.currentTarget.dataset.isct;
this.setData({
yijian: true,is_kt_or_ct:is_kt_or_ct,
})
},
//关闭展开列表
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,
})
},
//关闭购买页面
cbcou: function(e) {
this.setData({
yijian: false,
})
},
//qh点击取货
cqh: function(e) {
if(this.data.ssl) {
this.setData({
qh: false,
xz: true,
one: true,
})
}else{
this.setData({
qh: false,
xz: true,
one: false,
list:1,
})
}
},
//cxz点击选择门店
cxz: function(e) {
this.setData({
qh: true,
xz: false,
one: false,
})
},
//ccc点击选择的
sel: function(e) {
this.setData({
list: false,
se: false,
one: true,
xz: true,
})
},
//list点击底二层
clist: function(e) {
var i = e.currentTarget.dataset.end;
var pick_id = e.currentTarget.dataset.pick_id;
var pick_dis = e.currentTarget.dataset.pick_dis;
this.setData({
end_name: i,
pick_id: pick_id,
ii: 1,
qh: true,
se: false,
list: false,
pick_dis: pick_dis
})
},
//点击第一层
setchild: function(e) {
var ind = e.currentTarget.dataset.bindex;
var nn = e.currentTarget.dataset.bname;
console.log(nn);
var list = this.data.ssl[ind].s_arr;
this.setData({
ssl_child: list,
sele_dl_name: nn,
xz: false,
one: false,
list: true,
se: true
});
},
//事件处理函数
/*点击减号*/
bindMinus: function() {
var num = this.data.num;
if (num > 1) {
num--;
}
var minusStatus = num > 1 ? 'normal' : 'disable';
this.setData({
num: num,
minusStatus: minusStatus,
})
},
/*点击加号*/
bindPlus: function() {
var th=this;
var num = this.data.num;
var ii = this.data.ii;
var minusStatus = num > 1 ? 'normal' : 'disable';
if (ii == 0) {
getApp().showWarning("请选择门店"); return false;
}
if (ii == 1) {
num++;
//要判断库存数量,限购数量
th.check_num(num,minusStatus);
}
},
async check_num(num,minusStatus){
var gd=this.data.goods;
var th=this;
var user_id=getApp().globalData.user_id;
var promgoodsbuynum=0;
var goodsbuynum=0;
getApp().request.promiseGet("/api/weshop/ordergoods/getUserBuyGoodsNum", {
data: {
store_id: os.stoid,
user_id: user_id,
goods_id: gd.goods_id,
prom_type: gd.prom_type,
prom_id: gd.prom_id
},
}).then(res=>{
var buy_num_data=res.data.data;
if(buy_num_data.promgoodsbuynum) promgoodsbuynum=buy_num_data.promgoodsbuynum;
goodsbuynum=buy_num_data.goodsbuynum;
})
//先判断限购
if (num+goodsbuynum>gd.viplimited && gd.viplimited>0) {
getApp().confirmBox("超出商品限购");
return false;
}
if (num+promgoodsbuynum>th.data.teamlist.buy_limit && th.data.teamlist.buy_limit>0) {
getApp().confirmBox("超出活动限购");
return false;
}
//判断库存
if ( num>gd.store_count) {
getApp().confirmBox("超出商品库存");
return false;
}
var r_num=0;
await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/6/" + th.data.teamlist.id, {
1: 1
}).then(res => {
var em = res;
if (em.data.code == 0) {
r_num=em.data.data;
}
})
//--判断库存---
if ( num>r_num) {
getApp().confirmBox("超出商品库存");
return false;
}
this.setData({
num: num,
minusStatus: minusStatus,
})
},
/*输入框事件*/
bindManual: function(e) {
var num = e.detail.value;
var minusStatus = num > 1 ? 'normal' : 'disable';
this.setData({
num: num,
minusStatus: minusStatus
})
},
//---------------初始化代码----------------
async init(tg_id) {
var goods_id = 0, //商品ID,
pageteam = null, //
original_img = null, //商品图片
ee = this,
ordertx = [],
teamlist = null, //活动表
goods = null, //商品
teamgroup = null, //活動从表
max_num = 0,
min_price = 0,
th=this,
that=th;
//获取活动从表信息team_id,listno团编号(券号)
await getApp().request.promiseGet("/api/weshop/teamgroup/get/"+os.stoid+"/"+tg_id, {
}).then(res => {
if(res.data.code==0 && res.data && res.data.data ) {
teamgroup = res.data.data;
//获取当前时间,并且判断剩余时间
var nt = ut.gettimestamp();
var buy_start_date = ut.formatTime(teamgroup.buy_start_date, "yyyy-MM-dd hh:mm:ss");
ee.setData({
pindGoods: teamgroup,
buy_start_date: buy_start_date
});
if(nt>teamgroup.kt_end_time) {
th.setData({is_group_end:1,end_text:"团期已经结束"})
}
if(teamgroup.state==1) {
th.setData({is_group_end:1,end_text:"团期已经结束"})
}
if(teamgroup.state==3 || teamgroup.state==4 || teamgroup.state==5 ) {
th.setData({is_group_end:2,end_text:"团期已满"})
}
}
})
//判断是不是要继续的开关
var is_ok=1;
//要先读取订单,看自己有没有买过该团的商品
await getApp().request.promiseGet("/api/weshop/order/page", {
data: {
pt_prom_id:teamgroup.team_id,
user_id: oo.user_id,
store_id: os.stoid,
pageSize: 1,
page: 1
}
}).then(res => {
var e=res;
if (e.data.code != 0) {
getApp().showWarning("读取订单失败");
th.go_back();
is_ok=0;
return fasle;
}
//--跳转到已经购买的情况--
if (e.data.data.pageData.length > 0) {
var odr = e.data.data.pageData[0];
//还未支付
if (odr.pt_status == 0 && odr.order_status == 1) {
wx.navigateTo({
url: "/pages/user/order_detail/order_detail?order_id=" + odr.order_id,
});
is_ok=0;
}else if (odr.pt_status == 1 && odr.order_status == 1){
wx.navigateTo({
url: "/pages/team/team_success/team_success?ordersn=" + odr.order_sn,
});
is_ok=0;
}
}
})
if(!is_ok) return false;
//获取活动表的信息根据活动team_id
await getApp().request.promiseGet("/api/weshop/teamlist/get/" + os.stoid + "/" + teamgroup.team_id, {
data: {}
}).then(res => {
if (res.data.code == 0) {
teamlist = res.data.data;
goods_id = res.data.data.goods_id;
//----------查看阶梯团------------
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;
}
}
})
if(!teamlist){
getApp().showWarning("未找到活动");
is_ok=0;
}else{
if(teamlist.is_end==1){
getApp().showWarning("拼单活动已经结束"); is_ok=0;
}
var now=ut.gettimestamp();
if(teamlist.end_time<now && is_ok){
getApp().showWarning("拼单活动已经结束"); is_ok=0;
}
}
if(!is_ok) {
th.go_back();
return false;
}
//多少人参团头像
await getApp().request.promiseGet("/api/weshop/order/pagePtList", {
data: {
store_id: o.stoid,
pt_listno: teamgroup.listno,
}
}).then(res => {
ordertx = res.data.data.pageData;
})
//获取商品信息
await 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
})
//显示商品规格
var gg = "";
if(goods.goods_spec=="null" || goods.goods_spec==null ) goods.goods_spec="";
if(goods.goods_color=="null" || goods.goods_color==null) goods.goods_color="";
if (goods.goods_spec != "" && goods.goods_color != "") {
gg = goods.goods_spec + "/" + goods.goods_color;
} else if (goods.goods_spec != "" || goods.goods_color != "") {
gg = goods.goods_spec + goods.goods_color;
} else {
gg = "规格1";
}
goods.gg = gg;
//只装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);
}
if(th.data.is_group_end==1 || th.data.is_group_end==2 ){
getApp().confirmBox(th.data.end_text);
wx.redirectTo({
url: "/pages/goods/goodsInfo/goodsInfo?goods_id=" + goods.goods_id,
});
return false;
}
//--当是会员团的时候才显示倒计时多久可以参团--
if(teamlist.kttype==2) {
//显示判断多久才能购买商品,获取没有支付的会员
await getApp().request.promiseGet("/api/weshop/teamgroup/getTeamUser/" + os.stoid + "/" + teamgroup.id, {
1: 1
}).then(res => {
var em = res;
if (em.data.code == 0) {
var tg_list = em.data.data.split("|");
var t_obj = {};
t_obj.order_id = tg_list[0];
t_obj.time = parseFloat(tg_list[1]) + 5 * 60; //五分钟后
t_obj.user_name = tg_list[2];
th.setData({tg_arr: t_obj})
}
})
}
//获取大家都在团信息
await getApp().request.promiseGet("/api/weshop/teamlist/pageteam/"+os.stoid, {
data: {
pageSize: 2,
page: 1,
store_id: 1,
is_end: 0,
is_show: 1
}
}).then(res => {
pageteam = res.data.data.pageData;
});
//-- 获取用户的默认门店 --
getApp().get_user_store(function(ee) {
if(!ee) {
th.data.fir_def_store={}; //赋值空对象
return false;
}
//--定时器推迟一下--
setTimeout(function () {
var g_distr_type=th.data.goods.distr_type;
//--如果默认门店的配送方式不对,就不能被选择--
if(ee.distr_type!=0 && g_distr_type!=0 && ee.distr_type!=g_distr_type ){
th.data.fir_def_store={}; //赋值空对象
return false;
}
var appd=getApp().globalData;
var w_time = setInterval(function() {
if (that.data.is_get_local_ok == 0) return false;
clearInterval(w_time);
var distance = null;
var e=JSON.parse(JSON.stringify(ee));
//如果有开启近距离的话,同时距离优不一样了
if (that.data.lat != null) {
//如果经纬度有变化的话
if( appd.lat==that.data.lat && appd.lon==that.data.lon && e.distance>0 ){
that.data.fir_def_store=e;
that.setData({
def_pick_store: e,
sto_sele_name: e.pickup_name,
sto_sele_id: e.pickup_id,
sto_sele_distr: e.distr_type
})
}else{
//要用接口是获取距离,js的计算不准
getApp().request.promiseGet("/api/weshop/pickup/list",{
data:{store_id:os.stoid,pickup_id:e.pickup_id,lat:th.data.lat,lon: th.data.lon},
}).then(res=>{
if(res.data.code==0){
e=res.data.data.pageData[0];
if (e){
appd.pk_store=e;
that.data.fir_def_store=e;
that.setData({
def_pick_store: e,
sto_sele_name: e.pickup_name,
sto_sele_id: e.pickup_id,
sto_sele_distr: e.distr_type
})
}
}
})
}
//e.distance = distance;
appd.lat=that.data.lat;
appd.lon=that.data.lon;
}else{
if (e) {
e.distance = null;
that.data.fir_def_store=e;
that.setData({
def_pick_store: e,
sto_sele_name: e.pickup_name,
sto_sele_id: e.pickup_id,
sto_sele_distr: e.distr_type
})
}
}
}, 500)
},1000)
});
//获取下redis长度,如果团已经弄完,或者拼单已经卖完
//设置值
ee.setData({
ordertx2: ordertx2,
ordertx: ordertx,
teamlist: teamlist,
teamgroup: teamgroup,
goods: goods,
pageteam: pageteam,
image: original_img,
is_show:1,
sf_arr: sf_arr
});
ee.countDown2();
//---设置门店---
ee.get_sto();
//---定时设置一下待支付的订单---
ee.time_out();
},
onHide:function(){
this.setData({is_show:0,});
},
go_back:function(){
if(getCurrentPages()>1)
wx.navigateBack({delta: 1})
else
wx.navigateTo({
url: "/pages/index/index/index"
});
},
//---小于10的格式化函数----
timeFormat(param) {
return param < 10 ? '0' + param : param;
},
countDown2() {
var th = this;
// 获取当前时间,同时得到活动结束时间数组
var newTime = ut.gettimestamp();
var o = this.data.pindGoods;
var endTime = o.kt_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);
},
//------去支付,购买-------
go_pay:function () {
var th=this;
var def_pick_store=this.data.def_pick_store;
if(def_pick_store) {
th.data.pick_id=def_pick_store.pickup_id; //选择门店
th.data.end_name=def_pick_store.pickup_name;
}
if (th.data.pick_id == 0) return s.my_warnning("请选择门店", 0, th);
//----判断起购数----
var qnum=parseFloat(th.data.teamlist.minbuynum);
if(qnum>0 && qnum>th.data.num ){
getApp().confirmBox("拼团商品至少要买"+qnum+"件!");
return false;
}
//先判断团的redis数量
this.buy_check_redis(function () {
var arr=th.data.redis_arr;
if(th.data.num>arr[0]){
if(arr[0]>0){
getApp().showWarning("超出活动库存");
}else{
getApp().showWarning("拼单已经抢光");
}
return false;
}
if(th.data.teamlist.kttype==2 && 1>arr[1]){
getApp().showWarning("拼团已满");
return false;
}
//--------------此时操作的数据------------
var newd = {
goods_id: th.data.goods.goods_id,
goods_num: th.data.num,
pick_id: th.data.pick_id,
user_id: oo.user_id,
store_id: th.data.stoid,
goods_name: th.data.goods.goods_name,
goods_sn: th.data.goods.goods_sn,
};
//---是不是从收藏夹出来的---
if(th.data.c_guide_id){
newd['guide_id'] = th.data.c_guide_id;
newd['guide_type']=2;
}else{
if(getApp().globalData.guide_id){
newd['guide_id'] = getApp().globalData.guide_id;
newd['guide_type']=0;
}
}
//-----拼团-----
newd.goods_price = th.data.teamlist.price;
newd.prom_type = 6;
newd.prom_id = th.data.teamlist.id;
newd.kt_type = th.data.teamlist.kttype; //开团类型
newd.is_pt_tz = 0;
newd.pick_name = th.data.end_name;
newd.pick_dis = 1;
newd.is_normal = 0;
//判断开团还是参团
switch (th.data.is_kt_or_ct) {
case "0":
//如果不是商家团,就要带团期号
if(th.data.teamlist.kttype>1){
newd.qh=th.data.teamgroup.listno;
}
break;
case "1":
//阶梯团和会员团都要设置is_pt_tz
if (newd.kt_type > 1) {
newd.is_pt_tz = 1; //开团类型
}
break;
}
newd['pick_dis'] = th.data.pick_dis;
if(getApp().globalData.guide_id){
newd['guide_id'] = getApp().globalData.guide_id;
newd['guide_type']=0;
}
s.set_b_now(newd);
wx.navigateTo({
url: "/pages/cart/cart2_pt/cart2_pt?is_bnow=1&goods_id=" + th.data.goods.goods_id,
});
});
},
//购买前的判断redis
async buy_check_redis(func){
//获取redis中的数量
var r_num=0,prom_type=6,prom_id=this.data.teamlist.id;
await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/" + prom_type + "/" + prom_id, {
1: 1
}).then(res => {
var em = res;
if (em.data.code == 0) {
r_num=em.data.data;
}
})
//只有会员团要判断团的人数
var gr_num=0,grp_id=this.data.teamgroup.id;
if(this.data.teamlist.kttype==2){
await getApp().request.promiseGet("/api/weshop/activitylist/getActTuanLen/" + os.stoid + "/" + grp_id, {
1: 1
}).then(res => {
var em = res;
if (em.data.code == 0) {
gr_num=em.data.data;
}
})
}
var arr=[];arr.push(r_num);arr.push(gr_num);
this.data.redis_arr=arr;
func();
},
//定时设置一下待支付的订单
time_out:function () {
var list=this.data.tg_arr,th=this;
if(!list) return false;
// 获取当前时间,同时得到活动结束时间数组
var newTime = ut.gettimestamp();
var endTime = list.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: th.timeFormat(day),
hou: th.timeFormat(hou),
min: th.timeFormat(min),
sec: th.timeFormat(sec)
}
} else {
//活动已结束,全部设置为'00'
obj = {
day: '00',
hou: '00',
min: '00',
sec: '00'
}
//调用接口清理订单,并且返回redis数量
th.back_order(function () {
th.setData({ tg_arr: null});
});
return false;
}
var txt = "pindGoods.djs";
th.setData({
r_obj: obj
});
setTimeout(th.time_out, 1000);
},
//清理订单,并且返回redis数量ss
back_order:function (func) {
var th=this;
//---取消订单---
getApp().request.delete("/api/weshop/order/cancelTeamOrder/"+th.data.stoid+"/"+th.data.tg_arr.order_id,{
data:{},
success: function(t) {
if(t.data.code==0){
th.setData({tg_arr:null})
}
},
})
},
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");
},
//-----图片失败,默认图片-----
bind_bnerr: function (e) {
var _errImg = e.target.dataset.errorimg;
var _errObj = {};
_errObj[_errImg] = this.data.iurl + "/miniapp/images/default_g_img.gif";
this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
},
//------ 分享配置 --------
onShareAppMessage: function (e) {
var curPage=this;
var pagePath = curPage.route; //当前页面url
if (pagePath.indexOf('/') != 0) {
pagePath = '/' + pagePath;
}
var url=pagePath;
//--分享图片--
img=th.data.iurl+th.data.teamlist.share_imgurl;
//--把会员分享出去--
if(getApp().globalData.user_id){
if(url.indexOf("?")>0)
url+="&first_leader="+getApp().globalData.user_id;
else
url+="?first_leader="+getApp().globalData.user_id;
}
return {
path:url,
title: "商品分类",
imageUrl: img,
}
},
closeSpecModal: function() {
this.setData({
yijian: false
});
},
close_popup: function() {
this.setData({
showStore: true
});
},
//-- 选择门店。此时的门店选择与门店有关系 --
choice_store: function(ee) {
var th = this;
var bconfig = th.data.bconfig;
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();
th.get_sto();
},
fail: function(res) {
//th.onShow();
th.data.is_get_local_ok = 1;
th.get_sto();
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;
th.get_sto();
}
this.setData({
store: 1,
yijian: false,
})
},
//选择更多门店
more_store: function() {
this.setData({ sort_store: 1});
},
// 返回按钮
returns: function() {
this.setData({
sort_store: 0,choice_sort_store: 0
});
},
//-- 等待获取定位系统 --
wait_for_store_config: function() {
var th = this;
var t_time = setInterval(function() {
if (th.data.bconfig == null) false;
var e = th.data.bconfig;
if (e && e.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;
},
fail: function(res) {
if (res.errCode == 2) {
th.setData({
is_gps: 0
});
if (th.data.is_gps == 0) {
getApp().confirmBox("请开启GPS定位", null, 10000, !1);
}
} else {
th.setData({
is_gps: "3"
});
}
th.data.is_get_local_ok = 1;
}
})
} else {
th.data.is_get_local_ok = 1;
}
clearInterval(t_time);
}, 500)
},
//---------拿出门店分类和门店------------
get_sto(e) {
var th = this,that=this;
var timer_get = setInterval(function() {
if (th.data.is_get_local_ok == 0) return false;
var dd = null,
i = getApp().request;
var g_distr_type = th.data.goods.distr_type;
if (g_distr_type != 0) {
dd = {
store_id: o.stoid,
distr_type: g_distr_type,
isstop: 0,
pageSize: 2000
}
} else {
dd = {
store_id: o.stoid,
isstop: 0,
pageSize: 2000
}
}
//如果有距离的话
if (th.data.lat != null) {
dd.lat = th.data.lat;
dd.lon = th.data.lon;
}
clearInterval(timer_get);
if(th.data.def_pick_store && g_distr_type!=0 && th.data.def_pick_store.distr_type!=0 && th.data.def_pick_store.distr_type!=g_distr_type ){
th.setData({def_pick_store:null});
}
//----------获取门店----------------
getApp().request.promiseGet("/api/weshop/pickup/list", {
data: dd,
}).then(res => {
var e = res;
if (e.data.code == 0) {
//如果有开启距离的功能,没有设置默认门店,要用最近的门店作为默认门店
if(dd.lat && !th.data.def_pick_store && th.data.bconfig && th.data.bconfig.is_sort_storage){
th.setData({
def_pick_store:e.data.data.pageData[0],
sto_sele_name: e.data.data.pageData[0].pickup_name,
sto_sele_id: e.data.data.pageData[0].pickup_id,
sto_sele_distr: e.data.data.pageData[0].distr_type
});
th.data.fir_def_store=e.data.data.pageData[0];
}
//-- 如果有默认选择门店的时候,要把默认门店放在第一位 --
if (th.data.def_pick_store && (th.data.def_pick_store.distr_type==0 || th.data.def_pick_store.distr_type==g_distr_type )){
for (var k = 0; k < e.data.data.pageData.length; k++) {
if (e.data.data.pageData[k].pickup_id == th.data.def_pick_store.pickup_id) {
e.data.data.pageData.splice(k, 1); //删除
break;
}
}
e.data.data.pageData.splice(0, 0, th.data.def_pick_store); //添加
}
th.setData({all_pick_list:e.data.data.pageData});
setTimeout(function(){
th.deal_pickup(e); //--普通门店排版--
},800)
}
})
}, 200)
},
//------------处理门店,拼团活动只有线上库存---------------
deal_pickup(e){
var th=this;
var g_distr_type=th.data.goods.distr_type;
//单总量超出5个的时候
if (e.data.data.total > 5) {
getApp().request.get("/api/weshop/storagecategory/page", {
data: {
store_id: o.stoid,
is_show: 1,
pageSize: 1000,
orderField:"sort",
orderType:'asc',
},
success: function(ee) {
if (ee.data.code == 0) {
if (ee.data.data && ee.data.data.pageData && ee.data.data.pageData.length > 0) {
var def_arr = new Array();
var ishas = 0;
//-- 开始就看5个门店 --
for (var k = 0; k < 5; k++) {
if (k == e.data.data.pageData.length) break;
def_arr.push(e.data.data.pageData[k]);
}
th.setData({
def_pickpu_list: def_arr,
pickpu_list: ee.data.data.pageData
});
var sto_cate = ee.data.data.pageData;
var sto_arr = e.data.data.pageData;
var newarr = new Array();
var qita = new Array();
//----要进行门店分组--------
for (var i = 0; i < sto_arr.length; i++) {
//找一下这个门店有没有在分类数组内
var find2 = 0,find2name = "",sort=0;
for (var m = 0; m < sto_cate.length; m++) {
if (sto_arr[i].category_id == sto_cate[m].cat_id) {
find2 = sto_cate[m].cat_id;
find2name = sto_cate[m].cat_name;
sort=sto_cate[m].sort;
break;
}
}
if (newarr.length > 0) {
var find = 0;
//如果有找到,那门店就在这个分组内,否则,分类就要排在其他
if (find2 != 0) {
for (var ii = 0; ii < newarr.length; ii++) {
if (sto_arr[i].category_id == newarr[ii].cat_id) {
newarr[ii].s_arr.push(sto_arr[i]);
find = 1;
break;
}
}
if (find == 0) {
var arr0 = new Array();
arr0.push(sto_arr[i]);
var item = {
cat_id: find2,
name: find2name,
sort:sort,
s_arr: arr0
};
newarr.push(item);
}
} else {
qita.push(sto_arr[i]);
}
} else {
//如果有找到,那门店就在这个分组内,否则,分类就要排在其他
if (find2 != 0) {
var arr0 = new Array();
arr0.push(sto_arr[i]);
var item = {
cat_id: find2,
name: find2name,
sort:sort,
s_arr: arr0
};
newarr.push(item);
} else {
qita.push(sto_arr[i]);
}
}
}
//门店分类要排序下
function compare(property){
return function(a,b){
var value1 = a[property];
var value2 = b[property];
return value1 - value2;
}
}
if(newarr.length>0)
newarr.sort(compare("sort"));
//----安排其他的分类-----
if (qita.length > 0) {
var item = {
cat_id: -1,
name: "其他",
s_arr: qita
};
newarr.push(item);
}
th.setData({
is_show_sto_cat: 1,
all_sto: newarr
});
} else {
th.setData({
is_show_sto_cat: -1,
only_pk: e.data.data.pageData
});
//-----如果没有默认门店,要取第一个门店作为默认店.此时没有门店分类的情况------
if (!th.data.def_pick_store) {
th.setData({def_pick_store:e.data.data.pageData[0]})
}
}
} else {
th.setData({
is_show_sto_cat: -1,
only_pk: e.data.data.pageData
});
//-----如果没有默认门店,要取第一个门店作为默认店.此时没有门店分类的情况------
if (!th.data.def_pick_store) {
th.setData({def_pick_store:e.data.data.pageData[0]})
}
}
}
});
} else {
th.setData({
is_show_sto_cat: 0,
only_pk: e.data.data.pageData
});
//-----如果没有默认门店,要取第一个门店作为默认店------
if (!th.data.def_pick_store && th.data.bconfig && th.data.bconfig.is_sort_storage) {
th.setData({
def_pick_store:e.data.data.pageData[0],
sto_sele_name: e.data.data.pageData[0].pickup_name,
sto_sele_id: e.data.data.pageData[0].pickup_id,
sto_sele_distr: e.data.data.pageData[0].distr_type
})
}
}
},
//---选择分类门店---
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_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
})
},
//---点击二级之后的选择---
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为选择的门店
sure_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[index]; //当没有门店分类的时候
}
} else {
var index = th.data.sec_pick_index;
item = th.data.sec_sto.s_arr[index];
}
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
});
th.setData({
yijian: 1, //打开拼团购买界面
store: 0, //关闭门店
choice_sort_store: 0, //关闭门店2级
sort_store: 0, //关闭门店2级
});
},
//把选择的门店设置成默认的门店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[index]; //当没有门店分类的时候
}
} else {
var index = th.data.sec_pick_index;
item = th.data.sec_sto.s_arr[index];
}
var store_id = o.stoid;
var user_id = getApp().globalData.user_id;
var def_pickup_id = item.pickup_id;
getApp().request.put('/api/weshop/users/update', {
data: {
user_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)
}
}
});
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
});
//4就是拼团
th.setData({
yijian: 1, //打开拼团购买界面
store: 0, //关闭门店
choice_sort_store: 0, //关闭门店2级
sort_store: 0, //关闭门店2级
});
},
//-- 关闭选择门店 --
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,
yijian: 1, //打开拼团购买界面
})
},
})