select_table_page.dart
25.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
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
import 'dart:ffi';
import 'package:dotted_border/dotted_border.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/constant/state.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/models/table_list.dart';
import 'package:one_key/provider/choose_table_model.dart';
import 'package:one_key/provider/notebook_detail_change_model.dart';
import 'package:one_key/provider/notebook_model.dart';
import 'package:one_key/provider/user_model.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/utils/dialog_util.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/page_exception.dart';
import 'package:one_key/widgets/table_item.dart';
import 'package:one_key/models/table.dart' as t;
import 'package:one_key/widgets/v_empty_view.dart';
import 'package:provider/provider.dart';
import 'dart:convert' as convert;
class SelectTablePage extends StatefulWidget {
final String rid; //预订id
final DateTime dateTime; //日期
final String ddate_slot; //时段
final bool canChoose; //变更预订可以取消原来已预订的选中状态
final List<TableList>? tableList;
final String? fromPage;
final String? tid;
SelectTablePage(this.rid, this.dateTime, this.ddate_slot,
{this.canChoose = false, this.tableList, this.fromPage, this.tid});
@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
late ChooseTableModel _chooseTableModel;
Map<String, Notebook> tableMap = {}; //记录已预订桌位对应的订单
String? currentArea; //当前选中区域
List<String> personNumList = [];
int selectNum = 0;
@override
void initState() {
// TODO: implement initState
super.initState();
for (int i = 1; i < 31; i++) {
personNumList.add(i.toString());
}
WidgetsBinding.instance.addPostFrameCallback((_) {
getTableList();
});
}
//获取桌位列表
getTableList({needLoading = true}) async {
UserModel userModel = Provider.of<UserModel>(context, listen: false);
Map<String, String?> params = {"sellerid": userModel.user!.sellerid};
tableOuterList = await _chooseTableModel.getTableList(context, params,
needLoading: needLoading);
for (TableOuter item in tableOuterList) {
// if (item.name == "推荐") {
// itemModelList.remove(item);
// }
for (var item in item.list!) {
for (var table in widget.tableList!) {
if (item.id == table.id) {
item.selected = true;
selectNum++;
// if (!tableList.contains(item)) {
// tableList.add(item);
// }
}
}
}
}
if (tableOuterList.isEmpty) {
_chooseTableModel.pageState = PageState.Success;
_chooseTableModel.notifyListeners();
} else {
_getReserveList(userModel.user!.sellerid, needLoading: needLoading);
}
// if (_chooseTableModel.pageState == PageState.Success) {
// }
}
refreshTable(context) async {
await getTableList(needLoading: false);
// if (temp.length > 0) {
// _getReserveList(context, needLoading: false);
// } else {
// // pageState = PageState.Empty;
// _chooseTableModel.pageState = PageState.Success;
// _chooseTableModel.notifyListeners();
// }
}
//获取已预订列表
_getReserveList(String? sid, {needLoading = true}) 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, needLoading: needLoading);
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;
}
}
}
print(tableMap);
if (needLoading) {
initData();
} else {
initData(needRetain: true);
}
}
//初始桌位数据
initData({bool needRetain = false}) {
areas.clear();
areaTableMap.clear();
for (TableOuter outer in tableOuterList) {
int count = 0;
for (t.Table table in outer.list!) {
if (widget.tid != '' && table.id == widget.tid) {
table.selected = true;
currentArea = outer.name;
}
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;
area.rid = outer.list!.length == 0 ? outer.rid : outer.list![0].rid;
area.orderId = outer.orderId;
areas.add(area);
}
if (widget.tid == '') {
if (!needRetain) {
currentArea = areaTableMap.keys.first;
}
if (areas.length == 1) {
currentArea = areaTableMap.keys.first;
}
}
_chooseTableModel.pageState = PageState.Success;
_chooseTableModel.notifyListeners();
}
//获取一天开始-结束时间字符串
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) {
_chooseTableModel = Provider.of<ChooseTableModel>(context);
return Scaffold(
body: SafeArea(
child: Column(
children: <Widget>[
MyAppBar(
"选择桌位",
showBack: true,
),
Expanded(
child: Consumer<ChooseTableModel>(builder: (context, model, _) {
if (model.pageState != PageState.Success) {
return ExceptionPage(
pageState: model.pageState,
callback: () {
getTableList();
},
emptyMsg: "暂时没有桌位哦",
emptyImg: "empty_search",
showMsg: "加载中,请稍候...",
);
} else {
return Container(
color: MyColours.color_ffffff,
child: Row(
children: <Widget>[
Container(
width: ScreenUtil().setWidth(170),
height: double.infinity,
color: MyColours.color_f1f1f1,
child: ListView.builder(
itemBuilder: (context, index) {
if (areas.isEmpty || index == areas.length) {
return InkWell(
onTap: () async {
//添加区域弹框
await DialogUtil.openCreateAreaDialog(context,
onTap: (value) async {
print(value);
//添加区域
bool success = await _chooseTableModel
.addTableAreas(context, value as String?);
print(success);
if (success) {
Utils.showToast('添加成功!');
await getTableList(needLoading: false);
}
});
},
child: Center(
child: Image.asset(
Utils.getImgPath('add_area'),
width: ScreenUtil().setWidth(32)),
),
);
} else {
return AreaItem(areas[index], currentArea,
(area) {
setState(() {
currentArea = (area as Area).name;
});
});
}
},
itemExtent: ScreenUtil().setHeight(207),
itemCount: areas.length + 1,
),
),
Expanded(
child: Padding(
padding: EdgeInsets.symmetric(
vertical: ScreenUtil().setHeight(10),
horizontal: ScreenUtil().setWidth(9)),
child: Column(
children: [
Expanded(
child: GridView.builder(
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
childAspectRatio: 8 / 9),
itemBuilder: (context, index) {
if (index ==
areaTableMap[currentArea]!.length ||
areaTableMap[currentArea]!.length == 0) {
return InkWell(
onTap: () async {
List<String?> areasTemp = [];
for (int i = 0;
i < areas.length;
i++) {
areasTemp.add(areas[i].name);
}
//添加桌位弹框
await DialogUtil
.openCreateTableDialog(
context,
areasTemp,
areasTemp
.indexOf(currentArea),
personNumList, onTap:
(Map<String, String?>
value) async {
print(value);
// 'areaname':
// areas[currentAreaIndex],
// 'name': controller.text,
// 'pnumMin': pnumMin,
// 'pnumMax': pnumMax
//添加桌位 接口参数带整合???
// 以下是旧的不去,明天添加桌位接口
String? rid;
for (Area item in areas) {
if (item.name ==
value['areaname']) {
rid = item.rid;
}
}
Map<String, String?> params = {
'rid': rid,
'name': value['name'],
};
if (value['pnumMin'] != '') {
params['pnum'] =
value['pnumMin'];
}
if (value['pnumMax'] != '') {
params['most_pnum'] =
value['pnumMax'];
}
bool success =
await _chooseTableModel
.addTable(
context, params);
print(success);
if (success) {
Utils.showToast('添加成功!');
refreshTable(context);
}
});
},
child: Container(
margin: EdgeInsets.all(
ScreenUtil().setWidth(15)),
child: DottedBorder(
dashPattern: [5, 5, 5, 5],
borderType: BorderType.RRect,
radius: Radius.circular(
ScreenUtil().setWidth(10)),
// padding: EdgeInsets.all(ScreenUtil().setWidth(70)),
color: MyColours.color_199095,
strokeWidth:
ScreenUtil().setWidth(2),
child: ClipRRect(
borderRadius: BorderRadius
.all(Radius.circular(
ScreenUtil()
.setWidth(10))),
child: Container(
height: ScreenUtil()
.setWidth(90 * 2),
width: ScreenUtil()
.setWidth(80 * 2),
child: Column(
mainAxisAlignment:
MainAxisAlignment
.center,
children: [
Image.asset(
Utils.getImgPath(
'add_area'),
width: ScreenUtil()
.setWidth(32)),
],
),
),
),
)));
} else {
return TableItem(
areaTableMap[currentArea]![index],
onSelected: (t.Table table) {
if (widget.fromPage == 'tablePhoto') {
for (String item
in areaTableMap.keys) {
for (t.Table item
in areaTableMap[item]!) {
item.selected = false;
selectNum = 0;
if (table.id == item.id) {
item.selected = true;
selectTables = [];
selectNum++;
selectTables.add(table);
}
}
}
setState(() {});
} else {
if ((table).selected!) {
selectTables.add(table);
selectNum++;
widget.tableList!
.add(tableToTableList(table));
} else {
widget.tableList!.removeWhere(
(t) => t.id == table.id);
selectNum--;
selectTables.removeWhere(
(t) => t.id == table.id);
}
setState(() {});
}
},
canSelected: true,
fromPage: widget.fromPage,
tableMap: tableMap,
rid: widget.rid);
}
},
itemCount: currentArea == null
? 0
: areaTableMap[currentArea]!.length + 1,
)),
Container(
width: double.infinity,
height: ScreenUtil().setHeight(84),
margin: EdgeInsets.only(
bottom: ScreenUtil().setWidth(50)),
padding: EdgeInsets.symmetric(
horizontal: ScreenUtil().setWidth(31)),
alignment: Alignment.center,
color: MyColours.color_ffffff,
child: CommonButton(
content: widget.fromPage == 'tablePhoto'
? '确定'
: "已选${selectNum}个 确定",
width: 500,
height: 84,
fontSize: 34,
state: 1,
onPress: () {
if (widget.fromPage == "tablePhoto") {
Map temp = {
'tid': selectTables.length > 0
? selectTables[0].id
: '',
'tname': selectTables.length > 0
? selectTables[0].name
: ''
};
Navigator.of(context).pop(temp);
} else {
if (widget.canChoose) {
// if (widget.tableList.length > 0) {
String tid = "";
for (TableList table
in widget.tableList!) {
tid += table.id! + ",";
}
if (widget.tableList!.length > 0) {
tid = tid.substring(
0, tid.length - 1);
}
Map temp = {
'object': widget.tableList,
'tid': tid
};
Navigator.of(context).pop(temp);
// }
} else {
if (selectTables.length > 0) {
String tid = "";
for (t.Table table
in selectTables) {
tid += table.id! + ",";
}
if (selectTables.length > 0) {
tid = tid.substring(
0, tid.length - 1);
}
Map temp = {
'object': widget.tableList,
'tid': tid
};
Navigator.of(context).pop(temp);
}
}
}
},
)),
],
)),
)
],
),
);
}
}),
),
],
),
));
}
tableToTableList(t.Table table) {
TableList _tableList = TableList(
'', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '');
_tableList.id = table.id;
_tableList.rid = table.rid;
_tableList.tid = table.tid;
_tableList.name = table.name;
_tableList.tablePnum = table.table_pnum;
_tableList.sellerid = null;
_tableList.qrcode = null;
_tableList.mostPnum = table.most_pnum;
_tableList.hot = null;
_tableList.orderO = table.order_o;
_tableList.status = table.status;
_tableList.enable = table.enable;
_tableList.spell = table.spell;
_tableList.cdate = null;
_tableList.rname = table.rname;
_tableList.regionName = table.rname;
_tableList.selected = true;
return _tableList;
}
}