b_setting.js
4.46 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
// pages/book/b_setting.js
var util = require('../../utils/util.js')
var bookOrder=require('../../utils/bookCommon.js')
import App from '../../utils/api';
const {regeneratorRuntime} = global
Page({
/**
* 页面的初始数据
*/
data: {
dateStr:'',
calendarMaskLoad:false,
calendarMask:false,
dayStyle:[
{ month: 'current', day: new Date().getDate(), color: 'white', background: '#AAD4F5' },
{ month: 'current', day: new Date().getDate(), color: 'white', background: '#AAD4F5' }
],
regions:[],
regions_active:'',
time:-1,
},
regions:[],
sellerid:0,
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
let d=new Date()/1000;
let dateStr=util.unixtoTime(d,'MM-DD DAY');
this.setData({
dateStr:dateStr
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: async function () {
this.setData({
height:getApp().system.windowHeight-170,
})
setTimeout(()=>{
this.setData({
calendarMaskLoad:true,
})
},1000);
this.selectComponent('#nav').init();
this.sellerid=util.cache('sellerid');
App.Tables.GetTableListsBySellerId({
sellerid:this.sellerid
}).then((res)=>{
this.regions=res.data[0];
this.getbooklist();
})
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
calendarShow(){
console.log('xxxxx')
this.setData({
calendarMask:true
})
console.log(this.data.calendarMask)
},
dateChange(event){
let cktime=util.timetouUnix(event.detail.year+'/'+event.detail.month+'/'+event.detail.day)
let day0=parseInt(new Date(new Date().setHours(0, 0, 0, 0)) / 1000);
if(cktime<day0){
util.toast('请选择今天之后的日期','none');
return;
}
let clickDay = event.detail.day;
let changeDay = `dayStyle[1].day`;
let changeBg = `dayStyle[1].background`;
this.setData({
dateStr:util.unixtoTime(cktime,'MM-DD `DAY/周WW`'),
[changeDay]: clickDay,
[changeBg]: "#84e7d0",
})
this.getbooklist();
this.calendarClose();
},
calendarClose(){
this.setData({
calendarMask:false
})
},
async getbooklist(){
let obj={};
let formdata={};
formdata.sid=this.sellerid;
formdata.x=1;
formdata.y=200;
let time=0;
if(this.data.time<0){
time=await bookOrder.getTimeSpaceIndex();
obj.time=time;
}else{
time=this.data.time;
}
let rdate=await bookOrder.getTimeSpace(this.data.dateStr,time);
formdata.rdate=rdate;
let tids={};
let reserves=await App.Reserve.GetReserveList(formdata);
if(reserves.data.length>0){
reserves.data.forEach(r=>{
let ts=r.tid.split(',');
ts.forEach(tid=>{
tids[tid]={
rdate:r.rdate,
id:r.id,
status:r.status,
rname:r.rname+(r.sex==1?'先生':'女士'),
}
})
})
}
console.log('tids',tids);
let regions=[];
this.regions.forEach(region=>{
if(region.list.length>0){
region.list.forEach(tb=>{
tb.status_str='';
tb.status_classname='enabled'
if(tids[tb.id]){
console.log('tids',region.name,tb.name);
tb.status_str=tids[tb.id].status==2?'用餐中':'已预订';
tb.status_classname='highlight';
tb.reserve_id=tids[tb.id].id;
tb.reserve_name=tids[tb.id].rname;
}
if(tb.enable!=1){
if(tb.status_str){
tb.status_classname='disabled-highlight';
}else{
tb.status_str='已停用';
tb.status_classname='disabled';
}
}
})
regions.push(region);
}
})
obj.regions=regions
if(!this.data.regions_active){
obj.regions_active=this.regions[0].name
}
this.setData(obj)
},
chooseRegion(e){
this.setData({
regions_active:util.attr(e,'name')
})
},
selectedValue(e){
this.setData({
time:util.attr(e,'value')
})
this.getbooklist();
},
boardEvent(e){
console.log(e);
App.Tables.GetTableListsBySellerId({
sellerid:this.sellerid
},true).then((res)=>{
this.regions=res.data[0];
this.getbooklist();
})
}
})