|
|
|
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';
|
|
...
|
...
|
@@ -12,6 +13,7 @@ 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';
|
|
...
|
...
|
@@ -19,6 +21,7 @@ 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;
|
|
|
|
|
|
...
|
...
|
@@ -52,24 +55,26 @@ class SelectTablePageState extends State<SelectTablePage> { |
|
|
|
Map<String, Notebook> tableMap = {}; //记录已预订桌位对应的订单
|
|
|
|
|
|
|
|
String currentArea; //当前选中区域
|
|
|
|
List<String> personNumList = [];
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
// TODO: implement initState
|
|
|
|
super.initState();
|
|
|
|
for (int i = 1; i < 31; i++) {
|
|
|
|
personNumList.add(i.toString());
|
|
|
|
}
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
getTableList();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//获取桌位列表
|
|
|
|
getTableList() async {
|
|
|
|
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,
|
|
|
|
);
|
|
|
|
tableOuterList = await _chooseTableModel.getTableList(context, params,
|
|
|
|
needLoading: needLoading);
|
|
|
|
for (TableOuter item in tableOuterList) {
|
|
|
|
// if (item.name == "推荐") {
|
|
|
|
// itemModelList.remove(item);
|
|
...
|
...
|
@@ -85,17 +90,30 @@ class SelectTablePageState extends State<SelectTablePage> { |
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (tableOuterList.length == 0) {
|
|
|
|
_chooseTableModel.pageState = PageState.Empty;
|
|
|
|
if (tableOuterList.isEmpty) {
|
|
|
|
_chooseTableModel.pageState = PageState.Success;
|
|
|
|
_chooseTableModel.notifyListeners();
|
|
|
|
} else {
|
|
|
|
_getReserveList(userModel.user.sellerid, needLoading: needLoading);
|
|
|
|
}
|
|
|
|
if (_chooseTableModel.pageState == PageState.Success) {
|
|
|
|
_getReserveList(userModel.user.sellerid);
|
|
|
|
}
|
|
|
|
// 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) async {
|
|
|
|
_getReserveList(String sid, {needLoading = true}) async {
|
|
|
|
NoteBookModel model = new NoteBookModel();
|
|
|
|
Map<String, String> params = {
|
|
|
|
"sid": sid,
|
|
...
|
...
|
@@ -106,7 +124,8 @@ class SelectTablePageState extends State<SelectTablePage> { |
|
|
|
"keywords": "",
|
|
|
|
"sort": "1"
|
|
|
|
};
|
|
|
|
List<Notebook> noteBooks = await model.getReserveList(context, params);
|
|
|
|
List<Notebook> noteBooks =
|
|
|
|
await model.getReserveList(context, params, needLoading: needLoading);
|
|
|
|
for (Notebook notebook in noteBooks) {
|
|
|
|
if (notebook.tid.isEmpty) continue;
|
|
|
|
if (notebook.status == "1" ||
|
|
...
|
...
|
@@ -120,11 +139,17 @@ class SelectTablePageState extends State<SelectTablePage> { |
|
|
|
}
|
|
|
|
}
|
|
|
|
print(tableMap);
|
|
|
|
initData();
|
|
|
|
if (needLoading) {
|
|
|
|
initData();
|
|
|
|
} else {
|
|
|
|
initData(needRetain: true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//初始桌位数据
|
|
|
|
initData() {
|
|
|
|
initData({bool needRetain = false}) {
|
|
|
|
areas.clear();
|
|
|
|
areaTableMap.clear();
|
|
|
|
for (TableOuter outer in tableOuterList) {
|
|
|
|
int count = 0;
|
|
|
|
for (t.Table table in outer.list) {
|
|
...
|
...
|
@@ -151,10 +176,18 @@ class SelectTablePageState extends State<SelectTablePage> { |
|
|
|
Area area = Area();
|
|
|
|
area.name = outer.name;
|
|
|
|
area.count = count;
|
|
|
|
area.rid = outer.list.length == 0 ? outer.rid : outer.list[0].rid;
|
|
|
|
areas.add(area);
|
|
|
|
}
|
|
|
|
currentArea = areaTableMap.keys.first;
|
|
|
|
setState(() {});
|
|
|
|
if (!needRetain) {
|
|
|
|
currentArea = areaTableMap.keys.first;
|
|
|
|
}
|
|
|
|
if (areas.length == 1) {
|
|
|
|
currentArea = areaTableMap.keys.first;
|
|
|
|
}
|
|
|
|
|
|
|
|
_chooseTableModel.pageState = PageState.Success;
|
|
|
|
_chooseTableModel.notifyListeners();
|
|
|
|
}
|
|
|
|
|
|
|
|
//获取一天开始-结束时间字符串
|
|
...
|
...
|
@@ -214,14 +247,41 @@ class SelectTablePageState extends State<SelectTablePage> { |
|
|
|
color: MyColours.color_f1f1f1,
|
|
|
|
child: ListView.builder(
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
return AreaItem(areas[index], currentArea, (area) {
|
|
|
|
setState(() {
|
|
|
|
currentArea = (area as Area).name;
|
|
|
|
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);
|
|
|
|
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,
|
|
|
|
itemCount: areas.length + 1,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
...
|
...
|
@@ -238,26 +298,127 @@ class SelectTablePageState extends State<SelectTablePage> { |
|
|
|
crossAxisCount: 3,
|
|
|
|
childAspectRatio: 8 / 9),
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
return TableItem(
|
|
|
|
areaTableMap[currentArea][index],
|
|
|
|
onSelected: (table) {
|
|
|
|
if ((table as t.Table).selected) {
|
|
|
|
selectTables.add(table);
|
|
|
|
widget.tableList
|
|
|
|
.add(tableToTableList(table));
|
|
|
|
} else {
|
|
|
|
widget.tableList.removeWhere(
|
|
|
|
(t) => t.id == table.id);
|
|
|
|
selectTables.removeWhere(
|
|
|
|
(t) => t.id == table.id);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
canSelected: true,
|
|
|
|
fromPage: 'change',
|
|
|
|
tableMap: tableMap,
|
|
|
|
rid: widget.rid);
|
|
|
|
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: (table) {
|
|
|
|
if ((table as t.Table).selected) {
|
|
|
|
selectTables.add(table);
|
|
|
|
widget.tableList
|
|
|
|
.add(tableToTableList(table));
|
|
|
|
} else {
|
|
|
|
widget.tableList.removeWhere(
|
|
|
|
(t) => t.id == table.id);
|
|
|
|
selectTables.removeWhere(
|
|
|
|
(t) => t.id == table.id);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
canSelected: true,
|
|
|
|
fromPage: 'change',
|
|
|
|
tableMap: tableMap,
|
|
|
|
rid: widget.rid);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
itemCount: areaTableMap[currentArea].length,
|
|
|
|
itemCount: currentArea == null
|
|
|
|
? 0
|
|
|
|
: areaTableMap[currentArea].length + 1,
|
|
|
|
)),
|
|
|
|
Container(
|
|
|
|
width: double.infinity,
|
...
|
...
|
|