|
|
|
|
|
|
|
|
|
|
|
import 'package:common_utils/common_utils.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:one_key/constant/constant.dart';
|
|
...
|
...
|
@@ -19,8 +17,7 @@ import 'package:provider/provider.dart'; |
|
|
|
|
|
|
|
import 'notebook_model.dart';
|
|
|
|
|
|
|
|
class TableManagerModel with ChangeNotifier{
|
|
|
|
|
|
|
|
class TableManagerModel with ChangeNotifier {
|
|
|
|
List<Area> areas = []; //区域列表
|
|
|
|
|
|
|
|
List<t.Table> selectTables = []; //选择的桌位
|
|
...
|
...
|
@@ -28,13 +25,13 @@ class TableManagerModel with ChangeNotifier{ |
|
|
|
List<TableOuter> tableOuterList = []; //区域-桌位列表
|
|
|
|
|
|
|
|
Map<String, List<t.Table>> areaTableMap = {}; //区域-桌位Map
|
|
|
|
List<t.Table> currentTables=[];//当前显示的区域-桌位
|
|
|
|
List<t.Table> currentTables = []; //当前显示的区域-桌位
|
|
|
|
|
|
|
|
Map<String, Notebook> tableMap = {}; //记录已预订桌位对应的订单
|
|
|
|
|
|
|
|
String currentArea; //当前选中区域
|
|
|
|
|
|
|
|
DateTime dateTime=DateTime.now();
|
|
|
|
DateTime dateTime = DateTime.now();
|
|
|
|
|
|
|
|
String dateText = ""; //当前显示日期时间
|
|
|
|
int currTimeIndex = 1; //当前选中时间段
|
|
...
|
...
|
@@ -51,18 +48,25 @@ class TableManagerModel with ChangeNotifier{ |
|
|
|
initTime(BuildContext context) async {
|
|
|
|
userModel = Provider.of<UserModel>(context, listen: false);
|
|
|
|
dateTime = DateTime.now();
|
|
|
|
dateText = "${dateTime.year}年 "+Utils.addZeroNumber(dateTime.month) +
|
|
|
|
dateText = "${dateTime.year}年 " +
|
|
|
|
Utils.addZeroNumber(dateTime.month) +
|
|
|
|
"月" +
|
|
|
|
Utils.addZeroNumber(dateTime.day) +
|
|
|
|
"日" +
|
|
|
|
" 今天";
|
|
|
|
morning =
|
|
|
|
userModel.user.morning.isEmpty ? "00:00-00:00" : userModel.user.morning;
|
|
|
|
userModel.user.morning.isEmpty ? "00:00-00:00" : userModel.user.morning;
|
|
|
|
noon = userModel.user.noon.isEmpty ? "00:00-00:00" : userModel.user.noon;
|
|
|
|
night = userModel.user.night.isEmpty ? "00:00-00:00" : userModel.user.night;
|
|
|
|
userModel.user.morning.isEmpty?dailyMap.putIfAbsent("morning", ()=>""):dailyMap.putIfAbsent("morning", () => _getHourAndMinute(morning,1));
|
|
|
|
userModel.user.noon.isEmpty?dailyMap.putIfAbsent("noon", ()=>""):dailyMap.putIfAbsent("noon", () => _getHourAndMinute(noon,2));
|
|
|
|
userModel.user.night.isEmpty?dailyMap.putIfAbsent("night", ()=>""):dailyMap.putIfAbsent("night", () => _getHourAndMinute(night,3));
|
|
|
|
userModel.user.morning.isEmpty
|
|
|
|
? dailyMap.putIfAbsent("morning", () => "")
|
|
|
|
: dailyMap.putIfAbsent("morning", () => _getHourAndMinute(morning, 1));
|
|
|
|
userModel.user.noon.isEmpty
|
|
|
|
? dailyMap.putIfAbsent("noon", () => "")
|
|
|
|
: dailyMap.putIfAbsent("noon", () => _getHourAndMinute(noon, 2));
|
|
|
|
userModel.user.night.isEmpty
|
|
|
|
? dailyMap.putIfAbsent("night", () => "")
|
|
|
|
: dailyMap.putIfAbsent("night", () => _getHourAndMinute(night, 3));
|
|
|
|
if (dateTime.isBefore(DateTime.parse(dateTime.year.toString() +
|
|
|
|
"-" +
|
|
|
|
Utils.addZeroNumber(dateTime.month) +
|
|
...
|
...
|
@@ -74,13 +78,13 @@ class TableManagerModel with ChangeNotifier{ |
|
|
|
//未过早市
|
|
|
|
currTimeIndex = 1;
|
|
|
|
} else if (dateTime.isAfter(DateTime.parse(dateTime.year.toString() +
|
|
|
|
"-" +
|
|
|
|
Utils.addZeroNumber(dateTime.month) +
|
|
|
|
"-" +
|
|
|
|
Utils.addZeroNumber(dateTime.day) +
|
|
|
|
" " +
|
|
|
|
morning.split("-")[1] +
|
|
|
|
":00")) &&
|
|
|
|
"-" +
|
|
|
|
Utils.addZeroNumber(dateTime.month) +
|
|
|
|
"-" +
|
|
|
|
Utils.addZeroNumber(dateTime.day) +
|
|
|
|
" " +
|
|
|
|
morning.split("-")[1] +
|
|
|
|
":00")) &&
|
|
|
|
dateTime.isBefore(DateTime.parse(dateTime.year.toString() +
|
|
|
|
"-" +
|
|
|
|
Utils.addZeroNumber(dateTime.month) +
|
|
...
|
...
|
@@ -92,13 +96,13 @@ class TableManagerModel with ChangeNotifier{ |
|
|
|
//过了早市,未过午市
|
|
|
|
currTimeIndex = 2;
|
|
|
|
} else if (dateTime.isAfter(DateTime.parse(dateTime.year.toString() +
|
|
|
|
"-" +
|
|
|
|
Utils.addZeroNumber(dateTime.month) +
|
|
|
|
"-" +
|
|
|
|
Utils.addZeroNumber(dateTime.day) +
|
|
|
|
" " +
|
|
|
|
noon.split("-")[1] +
|
|
|
|
":00")) &&
|
|
|
|
"-" +
|
|
|
|
Utils.addZeroNumber(dateTime.month) +
|
|
|
|
"-" +
|
|
|
|
Utils.addZeroNumber(dateTime.day) +
|
|
|
|
" " +
|
|
|
|
noon.split("-")[1] +
|
|
|
|
":00")) &&
|
|
|
|
dateTime.isBefore(DateTime.parse(dateTime.year.toString() +
|
|
|
|
"-" +
|
|
|
|
Utils.addZeroNumber(dateTime.month) +
|
|
...
|
...
|
@@ -113,52 +117,72 @@ class TableManagerModel with ChangeNotifier{ |
|
|
|
//过了晚市
|
|
|
|
currTimeIndex = 3;
|
|
|
|
}
|
|
|
|
await getTableList(context);
|
|
|
|
getReserveList(context);
|
|
|
|
List temp = await getTableList(context);
|
|
|
|
if (temp.length > 0) {
|
|
|
|
getReserveList(context);
|
|
|
|
} else {
|
|
|
|
pageState = PageState.Empty;
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getCurrDdateStr(){
|
|
|
|
String currSelectTime="";
|
|
|
|
int timeMillsNow=DateTime.now().millisecondsSinceEpoch;
|
|
|
|
if(currTimeIndex==1){
|
|
|
|
List<String> mornings=_getHourAndMinute(morning, 1);
|
|
|
|
for(String temp in mornings){
|
|
|
|
if(timeMillsNow<=DateUtil.getDateMsByTimeStr(DateUtil.formatDate(dateTime).replaceRange(11,19, "$temp:00"))){
|
|
|
|
currSelectTime=temp;
|
|
|
|
getCurrDdateStr() {
|
|
|
|
String currSelectTime = "";
|
|
|
|
int timeMillsNow = DateTime.now().millisecondsSinceEpoch;
|
|
|
|
if (currTimeIndex == 1) {
|
|
|
|
List<String> mornings = _getHourAndMinute(morning, 1);
|
|
|
|
for (String temp in mornings) {
|
|
|
|
if (timeMillsNow <=
|
|
|
|
DateUtil.getDateMsByTimeStr(DateUtil.formatDate(dateTime)
|
|
|
|
.replaceRange(11, 19, "$temp:00"))) {
|
|
|
|
currSelectTime = temp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else if(currTimeIndex==2){
|
|
|
|
List<String> noons=_getHourAndMinute(noon, 2);
|
|
|
|
for(String temp in noons){
|
|
|
|
if(timeMillsNow<=DateUtil.getDateMsByTimeStr(DateUtil.formatDate(dateTime).replaceRange(11,19, "$temp:00"))){
|
|
|
|
currSelectTime=temp;
|
|
|
|
if(noons.contains("12:30")&&DateUtil.getDateMsByTimeStr(DateUtil.formatDate(dateTime).replaceRange(11,19, "$temp:00"))<DateUtil.getDateMsByTimeStr(DateUtil.formatDate(dateTime).replaceRange(11,19, "12:30:00"))){
|
|
|
|
currSelectTime="12:30";
|
|
|
|
} else if (currTimeIndex == 2) {
|
|
|
|
List<String> noons = _getHourAndMinute(noon, 2);
|
|
|
|
for (String temp in noons) {
|
|
|
|
if (timeMillsNow <=
|
|
|
|
DateUtil.getDateMsByTimeStr(DateUtil.formatDate(dateTime)
|
|
|
|
.replaceRange(11, 19, "$temp:00"))) {
|
|
|
|
currSelectTime = temp;
|
|
|
|
if (noons.contains("12:30") &&
|
|
|
|
DateUtil.getDateMsByTimeStr(DateUtil.formatDate(dateTime)
|
|
|
|
.replaceRange(11, 19, "$temp:00")) <
|
|
|
|
DateUtil.getDateMsByTimeStr(DateUtil.formatDate(dateTime)
|
|
|
|
.replaceRange(11, 19, "12:30:00"))) {
|
|
|
|
currSelectTime = "12:30";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
List<String> nights=_getHourAndMinute(night, 3);
|
|
|
|
for(String temp in nights){
|
|
|
|
if(timeMillsNow<=DateUtil.getDateMsByTimeStr(DateUtil.formatDate(dateTime).replaceRange(11,19, "$temp:00"))){
|
|
|
|
currSelectTime=temp;
|
|
|
|
if(nights.contains("18:30")&&DateUtil.getDateMsByTimeStr(DateUtil.formatDate(dateTime).replaceRange(11,19, "$temp:00"))<DateUtil.getDateMsByTimeStr(DateUtil.formatDate(dateTime).replaceRange(11,19, "18:30:00"))){
|
|
|
|
currSelectTime="18:30";
|
|
|
|
} else {
|
|
|
|
List<String> nights = _getHourAndMinute(night, 3);
|
|
|
|
for (String temp in nights) {
|
|
|
|
if (timeMillsNow <=
|
|
|
|
DateUtil.getDateMsByTimeStr(DateUtil.formatDate(dateTime)
|
|
|
|
.replaceRange(11, 19, "$temp:00"))) {
|
|
|
|
currSelectTime = temp;
|
|
|
|
if (nights.contains("18:30") &&
|
|
|
|
DateUtil.getDateMsByTimeStr(DateUtil.formatDate(dateTime)
|
|
|
|
.replaceRange(11, 19, "$temp:00")) <
|
|
|
|
DateUtil.getDateMsByTimeStr(DateUtil.formatDate(dateTime)
|
|
|
|
.replaceRange(11, 19, "18:30:00"))) {
|
|
|
|
currSelectTime = "18:30";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LogUtil.v("currSelectTime:$currSelectTime");
|
|
|
|
String ddateStr=DateUtil.getDateMsByTimeStr(DateUtil.formatDate(dateTime).replaceRange(11,19, "$currSelectTime:00")).toString();
|
|
|
|
return ddateStr.substring(0,10);
|
|
|
|
String ddateStr = DateUtil.getDateMsByTimeStr(DateUtil.formatDate(dateTime)
|
|
|
|
.replaceRange(11, 19, "$currSelectTime:00"))
|
|
|
|
.toString();
|
|
|
|
return ddateStr.substring(0, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
//根据获取时间 11:00-12:30 获取30分钟间隔组装的数组
|
|
|
|
_getHourAndMinute(
|
|
|
|
String hourAndMinuteStr, int mnd) {
|
|
|
|
_getHourAndMinute(String hourAndMinuteStr, int mnd) {
|
|
|
|
List tempDate = hourAndMinuteStr.split("-");
|
|
|
|
String beginDate = tempDate[0];
|
|
|
|
String endDate = tempDate[1];
|
|
...
|
...
|
@@ -211,7 +235,7 @@ class TableManagerModel with ChangeNotifier{ |
|
|
|
Map<String, String> params = {"sellerid": userModel.user.sellerid};
|
|
|
|
BaseResp<List> baseResp = await DioUtil()
|
|
|
|
.request<List>(context, Method.get, HttpUrl.table_list,
|
|
|
|
data: params,showLoading: false)
|
|
|
|
data: params, showLoading: false)
|
|
|
|
.catchError((error) {
|
|
|
|
print(error.toString());
|
|
|
|
if (error is MyError) {
|
|
...
|
...
|
@@ -229,17 +253,22 @@ class TableManagerModel with ChangeNotifier{ |
|
|
|
}
|
|
|
|
notifyListeners();
|
|
|
|
});
|
|
|
|
tableOuterList=[];
|
|
|
|
if(baseResp.code==Constant.status_success){
|
|
|
|
tableOuterList = [];
|
|
|
|
if (baseResp.code == Constant.status_success) {
|
|
|
|
if (baseResp.data.length == 0) {
|
|
|
|
pageState = PageState.ConnectivityError;
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
if ((baseResp.data[0] as List).isEmpty) {
|
|
|
|
pageState = PageState.Empty;
|
|
|
|
notifyListeners();
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
tableOuterList=(baseResp.data[0] as List).map((value){
|
|
|
|
TableOuter tableOuter=TableOuter();
|
|
|
|
tableOuter.name=value["name"];
|
|
|
|
tableOuter.list=(value["list"] as List).map((table){
|
|
|
|
return t.Table.fromJson(table as Map<String,dynamic>);
|
|
|
|
tableOuterList = (baseResp.data[0] as List).map((value) {
|
|
|
|
TableOuter tableOuter = TableOuter();
|
|
|
|
tableOuter.name = value["name"];
|
|
|
|
tableOuter.list = (value["list"] as List).map((table) {
|
|
|
|
return t.Table.fromJson(table as Map<String, dynamic>);
|
|
|
|
}).toList();
|
|
|
|
return tableOuter;
|
|
|
|
}).toList();
|
|
...
|
...
|
@@ -283,21 +312,21 @@ class TableManagerModel with ChangeNotifier{ |
|
|
|
String _getRdate() {
|
|
|
|
//一天开始时间
|
|
|
|
double startDay = (DateTime.parse((dateTime.year.toString() +
|
|
|
|
"-" +
|
|
|
|
Utils.addZeroNumber(dateTime.month) +
|
|
|
|
"-" +
|
|
|
|
Utils.addZeroNumber(dateTime.day) +
|
|
|
|
" 00:00:00"))
|
|
|
|
.millisecondsSinceEpoch) /
|
|
|
|
"-" +
|
|
|
|
Utils.addZeroNumber(dateTime.month) +
|
|
|
|
"-" +
|
|
|
|
Utils.addZeroNumber(dateTime.day) +
|
|
|
|
" 00:00:00"))
|
|
|
|
.millisecondsSinceEpoch) /
|
|
|
|
1000;
|
|
|
|
//一天结束时间
|
|
|
|
double endDay = (DateTime.parse((dateTime.year.toString() +
|
|
|
|
"-" +
|
|
|
|
Utils.addZeroNumber(dateTime.month) +
|
|
|
|
"-" +
|
|
|
|
Utils.addZeroNumber(dateTime.day) +
|
|
|
|
" 23:59:59"))
|
|
|
|
.millisecondsSinceEpoch) /
|
|
|
|
"-" +
|
|
|
|
Utils.addZeroNumber(dateTime.month) +
|
|
|
|
"-" +
|
|
|
|
Utils.addZeroNumber(dateTime.day) +
|
|
|
|
" 23:59:59"))
|
|
|
|
.millisecondsSinceEpoch) /
|
|
|
|
1000;
|
|
|
|
return startDay.floor().toString() + "-" + endDay.floor().toString();
|
|
|
|
}
|
|
...
|
...
|
@@ -312,7 +341,8 @@ class TableManagerModel with ChangeNotifier{ |
|
|
|
table.sign = "";
|
|
|
|
table.notebookId = "";
|
|
|
|
table.reserver = "";
|
|
|
|
if (table.tablestatus == "0") {//没有用餐中
|
|
|
|
if (table.tablestatus == "0") {
|
|
|
|
//没有用餐中
|
|
|
|
if (tableMap["${table.id}"] != null) {
|
|
|
|
Notebook notebook = tableMap["${table.id}"];
|
|
|
|
table.sign = notebook.status;
|
|
...
|
...
|
@@ -325,7 +355,8 @@ class TableManagerModel with ChangeNotifier{ |
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {//用餐中
|
|
|
|
} else {
|
|
|
|
//用餐中
|
|
|
|
table.sign = "2";
|
|
|
|
table.notebookId = "";
|
|
|
|
}
|
|
...
|
...
|
@@ -337,16 +368,17 @@ class TableManagerModel with ChangeNotifier{ |
|
|
|
areas.add(area);
|
|
|
|
}
|
|
|
|
currentArea = areaTableMap.keys.first;
|
|
|
|
currentTables=areaTableMap[currentArea];
|
|
|
|
currentTables = areaTableMap[currentArea];
|
|
|
|
pageState = PageState.Success;
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
|
|
|
|
//生成日期文本
|
|
|
|
createDateText(BuildContext context,DateTime day) {
|
|
|
|
createDateText(BuildContext context, DateTime day) {
|
|
|
|
if (Utils.isOneDay(day, dateTime)) return; //日期没变
|
|
|
|
DateTime dateNow = DateTime.now();
|
|
|
|
dateText = "${day.year}年 "+Utils.addZeroNumber(day.month) +
|
|
|
|
dateText = "${day.year}年 " +
|
|
|
|
Utils.addZeroNumber(day.month) +
|
|
|
|
"月" +
|
|
|
|
Utils.addZeroNumber(day.day) +
|
|
|
|
"日";
|
|
...
|
...
|
@@ -364,18 +396,19 @@ class TableManagerModel with ChangeNotifier{ |
|
|
|
}
|
|
|
|
|
|
|
|
//获取桌位数据
|
|
|
|
Future<dynamic> setSwitchStatus(BuildContext context,Map<String,String> params) async {
|
|
|
|
Future<dynamic> setSwitchStatus(
|
|
|
|
BuildContext context, Map<String, String> params) async {
|
|
|
|
BaseResp<dynamic> baseResp = await DioUtil()
|
|
|
|
.request<dynamic>(context, Method.get, HttpUrl.set_switch_status,
|
|
|
|
data: params,showLoading: true)
|
|
|
|
data: params, showLoading: true)
|
|
|
|
.catchError((error) {
|
|
|
|
print(error.toString());
|
|
|
|
});
|
|
|
|
if(baseResp==null)return null;
|
|
|
|
if(baseResp.code==Constant.status_success){
|
|
|
|
if (baseResp == null) return null;
|
|
|
|
if (baseResp.code == Constant.status_success) {
|
|
|
|
return baseResp.data;
|
|
|
|
}else{
|
|
|
|
} else {
|
|
|
|
Utils.showToast(baseResp.msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} |
|
|
\ No newline at end of file |
|
|
|
} |
...
|
...
|
|