|
|
|
import 'dart:ffi';
|
|
|
|
|
|
|
|
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/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/select_table_model.dart';
|
|
|
|
import 'package:one_key/provider/user_model.dart';
|
|
...
|
...
|
@@ -14,14 +19,17 @@ 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';
|
|
|
|
import 'dart:convert' as convert;
|
|
|
|
|
|
|
|
class SelectTablePage extends StatefulWidget{
|
|
|
|
|
|
|
|
final String rid;//预订id
|
|
|
|
final DateTime dateTime;//日期
|
|
|
|
final String ddate_slot;//时段
|
|
|
|
class SelectTablePage extends StatefulWidget {
|
|
|
|
final String rid; //预订id
|
|
|
|
final DateTime dateTime; //日期
|
|
|
|
final String ddate_slot; //时段
|
|
|
|
final bool canChoose; //变更预订可以取消原来已预订的选中状态
|
|
|
|
final List<TableList> tableList;
|
|
|
|
|
|
|
|
SelectTablePage(this.rid,this.dateTime,this.ddate_slot);
|
|
|
|
SelectTablePage(this.rid, this.dateTime, this.ddate_slot,
|
|
|
|
{this.canChoose = false, this.tableList});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() {
|
|
...
|
...
|
@@ -30,37 +38,51 @@ class SelectTablePage extends StatefulWidget{ |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class SelectTablePageState extends State<SelectTablePage>{
|
|
|
|
class SelectTablePageState extends State<SelectTablePage> {
|
|
|
|
List<Area> areas = []; //区域列表
|
|
|
|
List<t.Table> selectTables = []; //选择的桌位
|
|
|
|
|
|
|
|
List<Area> areas=[];//区域列表
|
|
|
|
List<t.Table> selectTables=[];//选择的桌位
|
|
|
|
List<TableOuter> tableOuterList = []; //区域-桌位列表
|
|
|
|
|
|
|
|
List<TableOuter> tableOuterList=[];//区域-桌位列表
|
|
|
|
Map<String, List<t.Table>> areaTableMap = {}; //区域-桌位Map
|
|
|
|
|
|
|
|
Map<String,List<t.Table>> areaTableMap={};//区域-桌位Map
|
|
|
|
SelectTableModel selectTableModel = new SelectTableModel();
|
|
|
|
|
|
|
|
SelectTableModel selectTableModel=new SelectTableModel();
|
|
|
|
ChooseTableModel _chooseTableModel;
|
|
|
|
|
|
|
|
Map<String,Notebook> tableMap={};//记录已预订桌位对应的订单
|
|
|
|
Map<String, Notebook> tableMap = {}; //记录已预订桌位对应的订单
|
|
|
|
|
|
|
|
String currentArea;//当前选中区域
|
|
|
|
String currentArea; //当前选中区域
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
// TODO: implement initState
|
|
|
|
super.initState();
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_){
|
|
|
|
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);
|
|
|
|
UserModel userModel = Provider.of<UserModel>(context, listen: false);
|
|
|
|
Map<String, String> params = {"sellerid": userModel.user.sellerid};
|
|
|
|
tableOuterList = await selectTableModel.getTableList(context, params);
|
|
|
|
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;
|
|
|
|
// if (!tableList.contains(item)) {
|
|
|
|
// tableList.add(item);
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_getReserveList(userModel.user.sellerid);
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -76,150 +98,208 @@ class SelectTablePageState extends State<SelectTablePage>{ |
|
|
|
"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;
|
|
|
|
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"){
|
|
|
|
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="";
|
|
|
|
} else {
|
|
|
|
table.sign = "2";
|
|
|
|
table.notebookId = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
areaTableMap["${outer.name}"]=outer.list;
|
|
|
|
Area area=Area();
|
|
|
|
area.name=outer.name;
|
|
|
|
area.count=count;
|
|
|
|
areaTableMap["${outer.name}"] = outer.list;
|
|
|
|
Area area = Area();
|
|
|
|
area.name = outer.name;
|
|
|
|
area.count = count;
|
|
|
|
areas.add(area);
|
|
|
|
}
|
|
|
|
currentArea=areaTableMap.keys.first;
|
|
|
|
setState(() {
|
|
|
|
});
|
|
|
|
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) /
|
|
|
|
"-" +
|
|
|
|
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) /
|
|
|
|
"-" +
|
|
|
|
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
|
|
|
|
_chooseTableModel = Provider.of<ChooseTableModel>(context);
|
|
|
|
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(
|
|
|
|
child: areaTableMap.isEmpty
|
|
|
|
? Container(
|
|
|
|
width: double.infinity,
|
|
|
|
height: double.infinity,
|
|
|
|
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,),
|
|
|
|
)
|
|
|
|
: 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);
|
|
|
|
Map<String, dynamic> temp =
|
|
|
|
modelToJson(table);
|
|
|
|
TableList tableList =
|
|
|
|
TableList.fromJson(temp);
|
|
|
|
widget.tableList.add(tableList);
|
|
|
|
} else {
|
|
|
|
widget.tableList
|
|
|
|
.removeWhere((t) => t.id == table.id);
|
|
|
|
selectTables
|
|
|
|
.removeWhere((t) => t.id == table.id);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
canSelected: true,
|
|
|
|
canChoose: widget.canChoose,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
itemCount: areaTableMap[currentArea].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);
|
|
|
|
),
|
|
|
|
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);
|
|
|
|
Map temp = {'object': widget.tableList, 'tid': tid};
|
|
|
|
Navigator.of(context).pop(temp);
|
|
|
|
}
|
|
|
|
},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);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
modelToJson(t.Table table) {
|
|
|
|
Map res = {
|
|
|
|
'id': table.id,
|
|
|
|
'rid': table.rid,
|
|
|
|
'tid': table.tid,
|
|
|
|
'name': table.name,
|
|
|
|
'tablePnum': table.table_pnum,
|
|
|
|
'sellerid': null,
|
|
|
|
'qrcode': null,
|
|
|
|
'mostPnum': table.most_pnum,
|
|
|
|
'hot': null,
|
|
|
|
'orderO': table.order_o,
|
|
|
|
'status': table.status,
|
|
|
|
'enable': table.enable,
|
|
|
|
'spell': table.spell,
|
|
|
|
'cdate': null,
|
|
|
|
'rname': table.rname,
|
|
|
|
'regionName': null
|
|
|
|
};
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|