select_table_page.dart
7.2 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
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/models/area.dart';
import 'package:one_key/models/notebook.dart';
import 'package:one_key/models/tableOuter.dart';
import 'package:one_key/provider/notebook_model.dart';
import 'package:one_key/provider/select_table_model.dart';
import 'package:one_key/provider/user_model.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/utils/utils.dart';
import 'package:one_key/widgets/app_bar.dart';
import 'package:one_key/widgets/area_item.dart';
import 'package:one_key/widgets/common_button.dart';
import 'package:one_key/widgets/table_item.dart';
import 'package:one_key/models/table.dart' as t;
import 'package:provider/provider.dart';
class SelectTablePage extends StatefulWidget{
final String rid;//预订id
final DateTime dateTime;//日期
final String ddate_slot;//时段
SelectTablePage(this.rid,this.dateTime,this.ddate_slot);
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return new SelectTablePageState();
}
}
class SelectTablePageState extends State<SelectTablePage>{
List<Area> areas=[];//区域列表
List<t.Table> selectTables=[];//选择的桌位
List<TableOuter> tableOuterList=[];//区域-桌位列表
Map<String,List<t.Table>> areaTableMap={};//区域-桌位Map
SelectTableModel selectTableModel=new SelectTableModel();
Map<String,Notebook> tableMap={};//记录已预订桌位对应的订单
String currentArea;//当前选中区域
@override
void initState() {
// TODO: implement initState
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_){
getTableList();
});
}
//获取桌位列表
getTableList() async {
UserModel userModel=Provider.of<UserModel>(context,listen:false);
Map<String,String> params={
"sellerid":userModel.user.sellerid
};
tableOuterList= await selectTableModel.getTableList(context, params);
_getReserveList(userModel.user.sellerid);
}
//获取已预订列表
_getReserveList(String sid) async {
NoteBookModel model = new NoteBookModel();
Map<String, String> params = {
"sid": sid,
"rdate": _getRdate(),
"ddate_solt": widget.ddate_slot,
"y": "200",
"x": "1",
"keywords": "",
"sort": "1"
};
List<Notebook> noteBooks=await model.getReserveList(context, params);
for(Notebook notebook in noteBooks){
if(notebook.tid.isEmpty)continue;
if(notebook.status=="1"||notebook.status=="2"||notebook.status=="5"){//已预订,用餐中,已安排
List<String> tids=notebook.tid.split(",");
for(String tid in tids){
tableMap["$tid"]=notebook;
}
}
}
initData();
}
//初始桌位数据
initData(){
for(TableOuter outer in tableOuterList){
int count=0;
for(t.Table table in outer.list){
if(table.tablestatus=="0"){//没有用餐中
if(tableMap["${table.id}"]!=null){
Notebook notebook=tableMap["${table.id}"];
table.sign=notebook.status;
table.notebookId=notebook.id;
table.reserver=notebook.rnameStr;
}else{
table.sign="";
table.notebookId="";
if(table.enable=="1"){
count++;
}
}
}else{
table.sign="2";
table.notebookId="";
}
}
areaTableMap["${outer.name}"]=outer.list;
Area area=Area();
area.name=outer.name;
area.count=count;
areas.add(area);
}
currentArea=areaTableMap.keys.first;
setState(() {
});
}
//获取一天开始-结束时间字符串
String _getRdate() {
//一天开始时间
double startDay = (DateTime.parse((widget.dateTime.year.toString() +
"-" +
Utils.addZeroNumber(widget.dateTime.month) +
"-" +
Utils.addZeroNumber(widget.dateTime.day) +
" 00:00:00"))
.millisecondsSinceEpoch) /
1000;
//一天结束时间
double endDay = (DateTime.parse((widget.dateTime.year.toString() +
"-" +
Utils.addZeroNumber(widget.dateTime.month) +
"-" +
Utils.addZeroNumber(widget.dateTime.day) +
" 23:59:59"))
.millisecondsSinceEpoch) /
1000;
return startDay.floor().toString() + "-" + endDay.floor().toString();
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return SafeArea(
child: areaTableMap.isEmpty?Container(
width: double.infinity,
height: double.infinity,
color: MyColours.color_ffffff,
):Column(
children: <Widget>[
MyAppBar(
"选择桌位",
showBack: true,
),
Expanded(
child: Container(
color: MyColours.color_ffffff,
child: Row(
children: <Widget>[
Container(
width: ScreenUtil().setWidth(189),
height: double.infinity,
color: MyColours.color_f1f1f1,
child: ListView.builder(itemBuilder: (context,index){
return AreaItem(areas[index],currentArea,(area){
setState(() {
currentArea=(area as Area).name;
});
});
},itemExtent: ScreenUtil().setHeight(207),itemCount: areas.length,),
),
Expanded(
child: Padding(padding: EdgeInsets.symmetric(vertical: ScreenUtil().setHeight(10),horizontal: ScreenUtil().setWidth(9)),child: GridView.builder(gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3,childAspectRatio: 0.8),itemBuilder: (context,index){
return TableItem(areaTableMap[currentArea][index],onSelected:(table){
if((table as t.Table).selected){
selectTables.add(table);
}else{
selectTables.removeWhere((t)=>t.id==table.id);
}
},canSelected: true,);
},itemCount: areaTableMap[currentArea].length,),),
)
],
),
),
),
Container(
width: double.infinity,
height: ScreenUtil().setHeight(100),
alignment: Alignment.center,
decoration: BoxDecoration(
color: MyColours.color_ffffff,
border: Border(top: BorderSide(color: MyColours.color_bfbfbf,width: ScreenUtil().setHeight(1)))
),
child: CommonButton(
content: "确定",
width: 600,
height: 76,
fontSize: 34,
state: 1,
onPress: (){
if(selectTables.length>0){
String tid="";
for(t.Table table in selectTables){
tid+=table.id+",";
}
tid=tid.substring(0,tid.length-1);
Navigator.of(context).pop(tid);
}
},
)
)
],
),
);
}
}