giftpacklist.js
21.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
var e = getApp(),
a = e.globalData.setting,
os = a,
t = e.request,
d = e.globalData;
var ut = require("../../../utils/util.js");
var com = require("../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
},
onLoad: function (options) {
this.setData({
params:options,
})
},
init(){
let options = this.data?.params;
var th = this;
this.setData({
getUserID: d.user_id,
getStorageID: a.stoid,
})
this.setData({
isBuy: options.isBuy,
getGiftID: options.lbId,
orderSn: options.orderSn,
})
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;
}
})
}
th.close();
if (this.data.isBuy == 0) {
this.GetMyGiftList();
} else {
this.GetBuyGiftList();
}
},
onShow: function () {
getApp().check_can_share();
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('/pages/togoin/togoin');
return false;
}
this.init();
})
},
GetBuyPrice: function (e) {
var that = this.data;
var th = this;
//如果还没有开始的话
if (th.data.isStart != 1) {
getApp().my_warnning("活动还没有开始", 0, th);
return false;
}
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) {
th.setData({
giftImage: th.data.iurl + res.data.data.lbUrl,
giftTitle: res.data.data.giftTitle,
default_color: res.data.data.bgcolor
})
if (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();
if (res.data.data.goodsUseState) th.setData({
c_state: 1
})
else if (t_date <= t_now)
th.setData({
c_state: 2
})
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;
}
}
} else {
getApp().my_warnning(res.data.msg, 0, th);
return false;
}
}
});
},
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
},
success: function success(res) {
if (res.data.code == 0) {
_this2.setData({
giftImage: th.iurl + 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"')
})
}
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
})
var sele_g=res.data.data;
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);
return false;
}
}
});
},
//显示核销码
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("礼包", "/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 curPage = this;
var pagePath = curPage.route; //当前页面url
if (pagePath.indexOf('/') != 0) {
pagePath = '/' + pagePath;
}
pagePath += "?isBuy=1" + "&lbId=" + this.data.lbId + "&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,
}
},
//免费领取
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) {
var th = this;
var ind = ee.currentTarget.dataset.ind;
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();
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_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[index]; //当没有门店分类的时候
}
} else {
var index = th.data.sec_pick_index;
item = th.data.sec_sto.s_arr[index];
}
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[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,
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)
}
});