reservation.js
35.8 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
// pack-book/pages/reservation/reservation.js
import util from '../../../utils/util';
import App from '../../../utils/api';
import {
jump
} from '../../../components/calendar/main.js';
Page({
/**
* 页面的初始数据
*/
data: {
threeText: '今天', //今天、明天、后天
barHeight: '',
date: '',
date1: '',
week: '',
lunchDinnerList: [],
mealTime: '',
ddate_solt: '',
activeSolt: '',
allDay: null, //获取预订列表需要传当天0:00到23:59的时间戳
timeList: [],
allfloorList: [],
activeIndex: '1', //选中的区域id id为1 代表全部
floorList: [],
allList: [],
homeList: [],
successInfo: [], //预订详情传参
objpush: [], //勾选的桌位
basicInfo: {}, //宴会详情数据
todayVal: '', //当前需展示的预订条数
startTime: null, //当前时间归属的餐段开始时间
addOverInfo: true, //是否允许新建当天当前餐段之前的订单
calendarConfig: {
showLunar: true,
autoChoosedWhenJump: true, // 设置默认日期及跳转到指定日期后是否需要自动选中
defaultDay: new Date(),
},
},
getDateBox: '', //日历弹框
getBook: '', //已预订桌位弹框
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
console.log('options---', options);
let obj = {}
if (options.seller_id) util.cache('sellerid', options.seller_id)
if (options.seller_id && options.manager_id && options.seller_openid) {
obj = {
seller_id: options.seller_id,
manager_id: options.manager_id,
seller_openid: options.seller_openid,
}
util.cache('enter_params', obj)
}
this.getDateBox = this.selectComponent("#getDate");
this.getBook = this.selectComponent("#getBook");
let info = util.cache('enter_params') ? util.cache('enter_params') : obj;
console.log('infoinfo---', info);
App.Reserve.SellerInfo(info).then(res => {
let role_name = res.data.seller_user.role_name;
util.cache('roleName', role_name)
})
let systemInfo = wx.getSystemInfoSync();
let reg = /ios/i;
let pt = 20; //导航状态栏上内边距
let h = 44; //导航状态栏高度
if (reg.test(systemInfo.system)) {
pt = systemInfo.statusBarHeight;
h = 44;
} else {
pt = systemInfo.statusBarHeight;
h = 48;
}
this.setData({
barHeight: pt + h,
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
this.closeBookModal()
this.getDateFun()
this.getManagerList()
console.log('show-------------');
jump()
},
regainToday() {
this.calendar.jump();
this.setData({
threeText: '今天'
})
this.getDateFun()
this.closeDateModal()
},
// 仅占座
occupySeat(event) {
const type = event.currentTarget.dataset['type'];
let objpush = this.data.objpush;
let tid = objpush.map((item) => item.id).join(",")
const reserveDate = this.getNewDate(this.data.date);
let reserveTime =
reserveDate.getFullYear() +
"-" +
(reserveDate.getMonth() + 1) +
"-" +
reserveDate.getDate();
let ddate =
this.getNewDate(
reserveTime + " " + this.data.timeList[0] + ":00"
).getTime() / 1000;
let obj = {
sid: util.cache('sellerid'),
tid,
rdate: this.data.reserveRdate,
uid: util.cache('sellerInfo')['id'],
note_name: util.cache('sellerInfo')['account'],
ddate_solt: this.data.activeSolt,
ddate,
channel: '4',
reserve_type: '普通用餐',
rname: '',
sex: '1'
}
console.log('obj预订参数----', obj);
App.Reserve.SetReserveInfo({
...obj
}).then(res => {
var objRow = res.data.row;
if (objRow == null) {
util.toast('预订失败,请稍后再试!', 'none')
this.closeBookModal()
} else {
if (type == '1') {
let url = util.http_build_query({
id: objRow.id,
date1: this.data.date1,
week: this.data.week,
threeText: this.data.threeText,
}, '/pack-book/pages/reservation/noticePage')
wx.navigateTo({
url,
})
} else {
util.toast('占座成功', 'none')
this.closeBookModal()
this.getReversList()
}
}
})
},
// 获取所有员工人员列表
getManagerList() {
App.Seller.GetAuthUserLists({
sellerid: util.cache('sellerid'),
}).then(res => {
let data = res.data;
var temp = [];
let id = util.cache('enter_params')['manager_id']
for (let e in data) {
data[e].forEach((item, index) => {
temp.push(item);
});
}
let obj = temp.filter(i => {
return i.id == id
})
if (obj && obj.length > 0) {
let i = obj[0]
util.cache('sellerInfo', {
nick_name: i.nick_name,
account: i.account,
id: i.id,
phone: i.phone,
user_name: i.user_name,
})
}
this.setData({
people: temp
})
})
},
getDateFun(newValue) {
newValue = newValue ? newValue : new Date();
console.log('newValue--------', newValue);
let year = newValue.getFullYear();
let month = newValue.getMonth() + 1;
let day = newValue.getDate();
let hours = new Date().getHours();
let minutes = new Date().getMinutes();
let seconds = new Date().getSeconds();
let day2 = `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}`
let day1 = `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day} ${hours < 10 ? '0' + hours : hours}:${minutes < 10 ? '0' + minutes : minutes}:${seconds < 10 ? '0' + seconds : seconds}`;
let dateTime = new Date(day1 + " GMT+0800");
this.setData({
dateTime,
lunchDinnerList: [],
date: day2,
})
this.getMealSectionByDayFun(dateTime, day2)
},
// 切换餐段
lunchFun(event) {
this.closeBookModal()
const ddate = event.currentTarget.dataset['ddate'];
const mname = event.currentTarget.dataset['mname'];
this.setData({
activeSolt: ddate,
mealTime: mname,
activeIndex: '1'
})
this.getLocalLunchTimeFun()
},
// 获取店铺设置的餐段
getLocalLunchTimeFun() {
let lunchDis = this.data.lunchDinnerList;
let obj = lunchDis.filter(item => {
return item.ddate_solt == this.data.activeSolt
})
let times = '';
let timeList = []
if (obj.lnegth == '0') return false;
if (obj && obj[0]) {
times = obj[0].mdate.split("-");
timeList = this.computeHour(times[0], times[1], 15)
} else {
times = lunchDis[0].mdate.split("-");
timeList = this.computeHour(times[0], times[1], 15)
}
const reserveDate = this.getNewDate(this.data.date);
let reserveTime =
reserveDate.getFullYear() +
"-" +
(reserveDate.getMonth() + 1) +
"-" +
reserveDate.getDate();
let reserveStartDate = reserveTime + " " + timeList[0] + ":00"; //开始时间
let reserveEndDate =
reserveTime + " " + timeList[timeList.length - 1] + ":00"; //结束时间
let reserveRdate =
this.getNewDate(reserveStartDate).getTime() / 1000 +
"-" +
this.getNewDate(reserveEndDate).getTime() / 1000;
let date1 = reserveTime + " 00:00"; //开始时间
let date2 =
reserveTime + " 23:59"; //结束时间
//当天一整天的时间戳(获取预订列表)
let allDay =
this.getNewDate(date1).getTime() / 1000 +
"-" +
this.getNewDate(date2).getTime() / 1000;
//拼接时间-转时间戳
this.setData({
reserveRdate,
allDay,
timeList,
})
setTimeout(() => {
this.getReversList()
this.getSellerInfo() //获取是否开启预订允许不录入客户电话、是否允许新建过去订单
}, 500);
},
// 切换区域
floorClick(event) {
const items = event.currentTarget.dataset['item'];
this.setData({
activeIndex: items.id
})
let list = []
if (items.name === "全部") {
this.getReversList();
this.setData({
homeList: [],
})
} else {
let allfloorList = this.data.allfloorList;
let obj = allfloorList.filter(i => {
return i.id == items.id
})
if (obj && obj.length > 0 && obj[0]) {
let item = obj[0]
if (item.id && item.tableList && item.tableList.length > 0) {
item.tableList.forEach(i => {
list.push(i)
})
}
}
this.setData({
allList: list,
homeList: list
})
}
},
// 已预订列表
getReversList() {
let reverseParams = {
sid: util.cache('sellerid'),
rdate: this.data.allDay, //传当天的0:00到23:59
x: "1",
y: "200",
sort: "1",
ddate_solt: this.data.activeSolt,
};
App.Reserve.GetTableListOrReserve({
...reverseParams
}).then(res => {
if (res.data && res.ret == 200) {
let data = res.data;
this.setData({
allfloorList: data
})
let list = []
let floorList = [{
name: "全部",
id: '1'
}]
let arr = []
data.forEach(item => {
if (item.id && item.tableList && item.tableList.length > 0) {
floorList.push({
name: item.name,
id: item.id
})
item.tableList.forEach(i => {
if (i.reserveList && i.reserveList) {
arr.push(i.reserveList.id)
let todayVal = this.data.todayVal;
if (todayVal && todayVal > 0) {
arr = [...new Set(arr)].splice(0, todayVal)
}
if (todayVal && todayVal != '0' && (arr.length > todayVal || arr.indexOf(i.reserveList.id) == -1)) {
delete i.reserveList
}
if (i.reserveList) i.reserveList.tid.split(',').length > 1 ? i.tableMultiple = '1' : i.tableMultiple = '0'
}
list.push(i)
})
this.setData({
floorList,
})
}
})
let activeIndex = this.data.activeIndex
// 选择了区域,获取区域下的桌位预订信息
if (activeIndex && activeIndex == '1') {
this.setData({
allList: list,
})
} else {
let regionList = []
if (activeIndex && activeIndex != '1') {
let obj = data.filter(i => {
return i.id == activeIndex
})
if (obj && obj.length > 0 && obj[0]) {
let item = obj[0]
if (item.id && item.tableList && item.tableList.length > 0) {
item.tableList.forEach(i => {
regionList.push(i)
})
}
}
this.setData({
allList: regionList,
})
}
}
this.setData({
homeList: list
})
}
})
},
// 当前桌子被别的桌子锁了
lockClick(items, indexs) {
console.log('当前桌子被别的桌子锁了', {
...items
});
if (items.reserveLock == '1' || items.lockstitch) {
return false
}
let roles = util.roles.addBook;
let role = util.cache('roleName')
if (items.reserveList) {
if (role == '迎宾') {
return util.toast('您没有查看预订的权限!', 'none')
}
let info = {
id: items.reserveList.id,
date1: this.data.date1,
week: this.data.week,
threeText: this.data.threeText,
}
let url = util.http_build_query({
...info
}, '/pack-book/pages/reservation/bookDetails')
wx.navigateTo({
url: url,
})
return false
}
// 宴会 || 锁定的
if (items.banquetList && items.banquetList.length > 0) {
const reserveDate = this.getNewDate(items.banquetList[0].ddate * 1000);
let ddateStr =
reserveDate.getFullYear() +
"-" +
reserveDate.getMonth() + 1 +
"-" +
reserveDate.getDate();
this.setData({
basicInfo: {
...items.banquetList[0],
ddateStr
}
})
return false
}
if (roles.indexOf(role) == -1) {
return util.toast('您没有新建预订的权限!', 'none')
}
if (!this.data.addOverInfo) {
return util.toast('不允许新建过去餐段的订单!', 'none')
}
let homeList = this.data.homeList;
let lockObjs = homeList.filter((item) => item.id == items.lock_tid);
let lockObj = lockObjs.length > 0 ? lockObjs[0] : ''
let lockObjTids = lockObj.tids ? lockObj.tids.split(',') : '';
homeList[indexs].show = !homeList[indexs].show
if (items.is_lock == '1' && items.lock_tid && lockObjTids.length > 0) {
let lockIndex = homeList.findIndex((item) => item.id == items.lock_tid);
let s = 0
lockObjTids.forEach(i => {
let obj = homeList.filter((item) => item.id == i)
if (obj && obj.length > 0 && obj[0].show) {
s += 1
}
})
if ((s < lockObjTids.length || s == lockObjTids.length) && !lockObj.is_dong) {
homeList[lockIndex].lockstitch = true
}
if (s == 0 && !lockObj.is_dong) {
homeList[lockIndex].lockstitch = false
}
}
let objpush = homeList.filter((item) => item.show == true)
this.setData({
homeList,
objpush,
})
if (objpush.length > 0) {
this.showBookModal()
} else {
this.closeBookModal()
}
},
// 当前桌子锁了别的桌子
mergeClick(items, indexs) {
console.log('当前桌子锁了别的桌子', {
...items
}, indexs);
if (items.reserveLock == '1' || items.lockstitch) {
return false
}
let roles = util.roles.addBook;
let role = util.cache('roleName')
if (items.reserveList) {
if (role == '迎宾') {
return util.toast('您没有查看预订的权限!', 'none')
}
let info = {
id: items.reserveList.id,
date1: this.data.date1,
week: this.data.week,
threeText: this.data.threeText,
}
let url = util.http_build_query({
...info
}, '/pack-book/pages/reservation/bookDetails')
wx.navigateTo({
url: url,
})
return false
}
// 宴会 || 锁定的
if (items.banquetList && items.banquetList.length > 0) {
const reserveDate = this.getNewDate(items.banquetList[0].ddate * 1000);
let ddateStr =
reserveDate.getFullYear() +
"-" +
reserveDate.getMonth() + 1 +
"-" +
reserveDate.getDate();
this.setData({
basicInfo: {
...items.banquetList[0],
ddateStr
}
})
return false
}
if (roles.indexOf(role) == -1) {
return util.toast('您没有新建预订的权限!', 'none')
}
if (!this.data.addOverInfo) {
return util.toast('不允许新建过去餐段的订单!', 'none')
}
let homeList = this.data.homeList;
if (items.is_merge == '1' && items.tids) {
let shows = !homeList[indexs].show
homeList[indexs].show = shows
let lockObjTids = items.tids.split(',');
lockObjTids.forEach(i => {
let obj = homeList.filter((item) => item.id == i)
if (obj && obj.length > 0) {
obj[0].lockstitch = shows
}
})
}
let objpush = homeList.filter((item) => item.show == true)
this.setData({
homeList,
objpush,
})
console.log('选中的桌子2---', objpush);
if (objpush.length > 0) {
this.showBookModal()
} else {
this.closeBookModal()
}
},
// 选了没有锁的桌子
homeClick(obj, indexs) {
console.log("选了没有锁的桌子", {
...obj
});
let roles = util.roles.addBook;
let role = util.cache('roleName')
if (obj.reserveList) {
if (role == '迎宾') {
return util.toast('您没有查看预订的权限!', 'none')
}
let info = {
id: obj.reserveList.id,
date1: this.data.date1,
week: this.data.week,
threeText: this.data.threeText,
}
let url = util.http_build_query({
...info,
}, '/pack-book/pages/reservation/bookDetails')
wx.navigateTo({
url: url,
})
} else if (obj.banquetList && obj.banquetList.length > 0) {
const reserveDate = this.getNewDate(obj.banquetList[0].ddate * 1000);
let ddateStr =
reserveDate.getFullYear() +
"-" +
reserveDate.getMonth() + 1 +
"-" +
reserveDate.getDate();
this.setData({
basicInfo: {
...obj.banquetList[0],
ddateStr
}
})
} else {
if (roles.indexOf(role) == -1) {
return util.toast('您没有新建预订的权限!', 'none')
}
if (!this.data.addOverInfo) {
return util.toast('不允许新建过去餐段的订单!', 'none')
}
let homeList = this.data.homeList;
let shows = !homeList[indexs].show
homeList[indexs].show = shows
let objpush = homeList.filter((item) => item.show == true)
this.setData({
homeList,
objpush,
})
console.log('选中的桌子3---', objpush);
if (objpush.length > 0) {
this.showBookModal()
} else {
this.closeBookModal()
}
}
},
getTapHandler(event) {
const item = event.currentTarget.dataset['item'];
const index = event.currentTarget.dataset['index'];
if (item.is_lock && item.is_lock == '1') {
this.lockClick(item, index)
} else if (item.is_merge && item.is_merge == '1') {
this.mergeClick(item, index)
} else {
this.homeClick(item, index)
}
},
// 日历初次渲染(显示农历日期)
afterCalendarRender(e) {
const detail = this.calendar.getSelectedDay()[0]
this.setData({
date1: detail.lunar.IMonthCn + detail.lunar.IDayCn,
week: detail.lunar.ncWeek
})
},
// 选择日期
afterTapDay(e) {
let detail = e.detail;
console.log('选择日期--', {
...detail
});
let date = `${detail.year}-${detail.month < 10 ? '0' + detail.month : detail.month}-${detail.day < 10 ? '0' + detail.day : detail.day}`
let hours = new Date().getHours();
let minutes = new Date().getMinutes();
let seconds = new Date().getSeconds();
let day1 = `${detail.year}-${detail.year < 10 ? '0' + detail.year : detail.year}-${detail.year < 10 ? '0' + detail.year : detail.year} ${hours < 10 ? '0' + hours : hours}:${minutes < 10 ? '0' + minutes : minutes}:${seconds < 10 ? '0' + seconds : seconds}`;
let dateTime = new Date(day1 + " GMT+0800");
let year = new Date().getFullYear();
let month = new Date().getMonth() + 1;
let day = new Date().getDate();
let threeText = '';
if (year == detail.year && month == detail.month && day == detail.day) {
threeText = "今天"
} else if (year == detail.year && month == detail.month && day + 1 == detail.day) {
threeText = "明天"
} else if (year == detail.year && month == detail.month && day + 2 == detail.day) {
threeText = "后天"
} else {
threeText = '';
}
this.setData({
dateTime,
lunchDinnerList: [],
date,
date1: detail.lunar.IMonthCn + detail.lunar.IDayCn,
week: detail.lunar.ncWeek,
threeText
})
this.closeDateModal()
this.getMealSectionByDayFun(dateTime, date)
},
getMealSectionByDayFun(dateTime, day) {
App.Seller.getMealSectionByDay({
sellerid: util.cache('sellerid'),
day
}).then(res => {
let data = res.data;
let lunchDinnerList = [];
if (data.length <= 3 && !data[0].ddate_solt) {
data.forEach(i => {
if (i.mname == '早餐') {
lunchDinnerList.push({
mname: "早餐",
mdate: i.mdate,
ddate_solt: 1,
})
}
if (i.mname == '午餐') {
lunchDinnerList.push({
mname: "午餐",
mdate: i.mdate,
ddate_solt: 2,
})
}
if (i.mname == '晚餐') {
lunchDinnerList.push({
mname: "晚餐",
mdate: i.mdate,
ddate_solt: 3,
})
}
})
} else {
lunchDinnerList = data;
}
this.setData({
lunchDinnerList,
})
this.getLocalLunchTime(lunchDinnerList, dateTime)
})
},
// 打开日历弹框
showDateModal() {
this.closeBookModal()
this.getDateBox.showModal()
let homeList = this.data.homeList;
homeList.forEach(i => {
i.show = false;
})
this.setData({
objpush: [],
homeList
})
},
// 关闭日历弹框
closeDateModal() {
this.getDateBox.closeModal()
},
// 打开桌位弹框
showBookModal() {
this.getBook.showModal()
},
// 关闭桌位弹框
closeBookModal() {
this.getBook.closeModal()
},
// 获取店铺设置的餐段,判断当前时间是哪个餐段
getLocalLunchTime(lunchDis, dateTime) {
const currentHours = dateTime.getHours();
const currentMinutes = dateTime.getMinutes();
const currentTimeInMinutes = currentHours * 60 + currentMinutes;
let currentMeal = null;
let nextMeal = null;
for (let i = 0; i < lunchDis.length; i++) {
const item = lunchDis[i];
const [start, end] = item.mdate.split('-');
const [startHours, startMinutes] = start.split(':').map(Number);
const [endHours, endMinutes] = end.split(':').map(Number);
const startTimeInMinutes = startHours * 60 + startMinutes;
const endTimeInMinutes = endHours * 60 + endMinutes;
if (currentTimeInMinutes >= startTimeInMinutes && currentTimeInMinutes < endTimeInMinutes) {
currentMeal = item.ddate_solt;
break;
}
}
// 如果当前时间不在任何餐段,显示下一个餐段
if (!currentMeal) {
console.log('当前时间不在任何餐段,显示下一个餐段');
let y = lunchDis.find((item, index) => {
const [start] = item.mdate.split('-');
const [startHours, startMinutes] = start.split(':').map(Number);
const startTimeInMinutes = startHours * 60 + startMinutes;
return currentTimeInMinutes < startTimeInMinutes;
})
nextMeal = y ? y.ddate_solt : lunchDis[0].ddate_solt; // 如果没有找到下一个餐段,默认返回第一个餐段
} else {
nextMeal = lunchDis[(lunchDis.findIndex(item => item.ddate_solt === currentMeal) + 1) % lunchDis.length].ddate_solt;
}
currentMeal = currentMeal ? currentMeal : nextMeal
console.log(`当前时间处于${currentMeal || '未在任何餐段'},下个餐段是${nextMeal}`);
let lunchDinnerList = this.data.lunchDinnerList;
let obj = lunchDinnerList.filter(i => {
return i.ddate_solt == currentMeal
})
let timeList = []
// 有多个餐段
if (obj.length > 0 && obj[0].ddate_solt) {
let i = obj[0].ddate_solt;
let mealTime = obj[0].mname
let times = obj[0].mdate.split("-");
timeList = this.computeHour(times[0], times[1], 15)
this.setData({
activeSolt: i,
mealTime,
timeList
})
} else { //没有多个餐段
lunchDinnerList.forEach((meal, index) => { //为每个餐段添加对应的 ddate_solt 属性
if (meal.mname === "早餐") {
lunchDinnerList[index].ddate_solt = 1;
} else if (meal.mname === "午餐") {
lunchDinnerList[index].ddate_solt = 2;
} else if (meal.mname === "晚餐") {
lunchDinnerList[index].ddate_solt = 3;
}
});
let activeSolt = ''
switch (currentMeal) {
case '早餐':
activeSolt = '1'
break;
case '午餐':
activeSolt = '2'
break;
case '晚餐':
activeSolt = '3'
break;
}
console.log('当前餐段', activeSolt);
this.setData({
lunchDinnerList,
activeSolt,
mealTime: currentMeal
})
}
//初始化全局预订rdate时间戳
const reserveDate = this.getNewDate(this.data.date);
let reserveTime =
reserveDate.getFullYear() +
"-" +
(reserveDate.getMonth() + 1) +
"-" +
reserveDate.getDate();
let reserveStartDate = reserveTime + " " + timeList[0] + ":00"; //开始时间
let reserveEndDate =
reserveTime + " " + timeList[timeList.length - 1] + ":00"; //结束时间
let date1 = reserveTime + " 00:00"; //开始时间
let date2 =
reserveTime + " 23:59"; //结束时间
let reserveRdate = this.getNewDate(reserveStartDate).getTime() / 1000 +
"-" +
this.getNewDate(reserveEndDate).getTime() / 1000
let allDay = this.getNewDate(date1).getTime() / 1000 +
"-" +
this.getNewDate(date2).getTime() / 1000
//拼接时间-转时间戳
this.setData({
reserveRdate,
allDay, //当天一整天的时间戳(获取预订列表)
})
this.getSellerHideConfFun()
this.getSellerInfo()
},
// 获取商家隐藏订单日期配置列表
getSellerHideConfFun() {
App.Seller.GetSellerHideConf().then(res => {
if (res.data && res.ret == 200) {
let arr = res.data;
const foundItem = arr.find(item => item.sid == util.cache('sellerid'));
const today = new Date();
today.setHours(0, 0, 0, 0); // 归零时分秒毫秒
const inputDate = this.getNewDate(this.data.date);
inputDate.setHours(0, 0, 0, 0);
if (foundItem && inputDate.getTime() != today.getTime() && inputDate.getTime() < today.getTime()) {
let str = foundItem.str.split('-')
const time = inputDate.getDay();
let todayVal = (time >= 1 && time <= 4) ? str[0] : str[1];
this.setData({
todayVal
})
} else {
this.setData({
todayVal: null
})
}
this.getReversList()
}
})
},
//获取是否开启预订允许不录入客户电话、是否允许新建过去订单
getSellerInfo() {
App.Seller.GetDzSellerConf({
sid: util.cache('sellerid')
}).then(res => {
if (res.data && res.ret == 200) {
let data = res.data;
let addOver = data.is_add_over;
let startTime = this.data.startTime;
let timeList = this.data.timeList;
if (!startTime && timeList.length > 0) { //获取当前时间所属于餐段的开始时间 (只获取一次)
const [hour, minute] = timeList[0].split(':');
startTime = (hour && minute) ? new Date().setHours(hour, minute, 0, 0) : '';
util.cache('sellerStartTime', startTime)
this.setData({
startTime,
})
}
let addOverInfo = true;
if (addOver == '0' && timeList.length > 0) { //是否允许新建过去订单 1 允许 0 不允许
let time = timeList[timeList.length - 1];
const [hour1, minute1] = time.split(':');
let date = this.data.date;
let endTime = (hour1 && minute1) ? this.getNewDate(date).setHours(hour1, minute1, 0, 0) : '';
// 在当前餐段之前,不能预定
addOverInfo = (endTime < startTime || endTime == startTime) ? false : true
}
this.setData({
addOverInfo
})
}
})
},
// 清空选座
clearSeat() {
let homeList = this.data.homeList;
homeList.forEach(item => {
item.show = false;
})
this.setData({
homeList,
objpush: [],
})
this.closeBookModal()
},
// 删除某一个座位
clearSeatItem(event) {
const items = event.currentTarget.dataset['item'];
let homeList = this.data.homeList;
let indexs = homeList.findIndex((item) => item.id == items.id);
homeList[indexs].show = false
let objpush = homeList.filter((item) => item.show == true)
this.setData({
homeList,
objpush,
})
if (objpush.length > 0) {
this.showBookModal()
} else {
this.closeBookModal()
}
},
//根据起始时间(获取时间时间段)
computeHour(time1, time2, interval) {
//time1 开始时间 time2结束时间 interval间隔时长
function getTimeList(time1, time2, interval) {
var timeList = [];
time1 = time1.split(":");
time2 = time2.split(":");
time1 = new Date(0, 0, 0, time1[0], time1[1], 0);
time2 = new Date(0, 0, 0, time2[0], time2[1], 0);
interval = interval * 60 * 1000;
while (time1 <= time2) {
timeList.push(time1.format("hh:mm"));
time1 = new Date(time1.getTime() + interval);
}
return timeList;
}
Date.prototype.format = function (format) {
var date = {
"M+": this.getMonth() + 1,
"d+": this.getDate(),
"h+": this.getHours(),
"m+": this.getMinutes(),
"s+": this.getSeconds(),
"q+": Math.floor((this.getMonth() + 3) / 3),
S: this.getMilliseconds(),
};
if (/(y+)/.test(format))
format = format.replace(
RegExp.$1,
(this.getFullYear() + "").substr(4 - RegExp.$1.length)
);
for (var k in date)
if (new RegExp("(" + k + ")").test(format))
format = format.replace(
RegExp.$1,
RegExp.$1.length == 1 ?
date[k] :
("00" + date[k]).substr(("" + date[k]).length)
);
return format;
};
return getTimeList(time1, time2, interval);
},
// ios 部分机型不兼容new Date() 转换字符串
getNewDate(data) {
if (typeof data === 'string') {
let arr = data.split(/[- : \/]/)
if (arr[1] !== undefined || arr[1] !== null) {
arr[1] = arr[1] - 1
}
return new Date(...arr)
}
return new Date(data || new Date())
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})