Commit e18fde029630d6f3da7982636b65131545427ebd

Authored by wdn127929
1 parent 84d5981d

新增创建区域

  1 +import 'package:json_annotation/json_annotation.dart';
  2 +
  3 +part 'area_model.g.dart';
  4 +
  5 +
  6 +@JsonSerializable()
  7 + class AreaModel extends Object {
  8 +
  9 + @JsonKey(name: 'ret')
  10 + int ret;
  11 +
  12 + @JsonKey(name: 'data')
  13 + List<AreaSunModel> data;
  14 +
  15 + @JsonKey(name: 'msg')
  16 + String msg;
  17 +
  18 + AreaModel(this.ret,this.data,this.msg,);
  19 +
  20 + factory AreaModel.fromJson(Map<String, dynamic> srcJson) => _$AreaModelFromJson(srcJson);
  21 +
  22 + Map<String, dynamic> toJson() => _$AreaModelToJson(this);
  23 +
  24 +}
  25 +
  26 +
  27 +@JsonSerializable()
  28 + class AreaSunModel extends Object {
  29 +
  30 + @JsonKey(name: 'id')
  31 + String id;
  32 +
  33 + @JsonKey(name: 'sellerid')
  34 + String sellerid;
  35 +
  36 + @JsonKey(name: 'name')
  37 + String name;
  38 +
  39 + @JsonKey(name: 'order_o')
  40 + String orderO;
  41 +
  42 + @JsonKey(name: 'status')
  43 + String status;
  44 +
  45 + @JsonKey(name: 'cdate')
  46 + String cdate;
  47 +
  48 + AreaSunModel(this.id,this.sellerid,this.name,this.orderO,this.status,this.cdate,);
  49 +
  50 + factory AreaSunModel.fromJson(Map<String, dynamic> srcJson) => _$AreaSunModelFromJson(srcJson);
  51 +
  52 + Map<String, dynamic> toJson() => _$AreaSunModelToJson(this);
  53 +
  54 +}
  55 +
  56 +
  1 +// GENERATED CODE - DO NOT MODIFY BY HAND
  2 +
  3 +part of 'area_model.dart';
  4 +
  5 +// **************************************************************************
  6 +// JsonSerializableGenerator
  7 +// **************************************************************************
  8 +
  9 +AreaModel _$AreaModelFromJson(Map<String, dynamic> json) {
  10 + return AreaModel(
  11 + json['ret'] as int,
  12 + (json['data'][0] as List)
  13 + ?.map((e) =>
  14 + e == null ? null : AreaSunModel.fromJson(e as Map<String, dynamic>))
  15 + ?.toList(),
  16 + json['msg'] as String,
  17 + );
  18 +}
  19 +
  20 +Map<String, dynamic> _$AreaModelToJson(AreaModel instance) => <String, dynamic>{
  21 + 'ret': instance.ret,
  22 + 'data': instance.data,
  23 + 'msg': instance.msg,
  24 + };
  25 +
  26 +AreaSunModel _$AreaSunModelFromJson(Map<String, dynamic> json) {
  27 + return AreaSunModel(
  28 + json['id'] as String,
  29 + json['sellerid'] as String,
  30 + json['name'] as String,
  31 + json['order_o'] as String,
  32 + json['status'] as String,
  33 + json['cdate'] as String,
  34 + );
  35 +}
  36 +
  37 +Map<String, dynamic> _$AreaSunModelToJson(AreaSunModel instance) =>
  38 + <String, dynamic>{
  39 + 'id': instance.id,
  40 + 'sellerid': instance.sellerid,
  41 + 'name': instance.name,
  42 + 'order_o': instance.orderO,
  43 + 'status': instance.status,
  44 + 'cdate': instance.cdate,
  45 + };
@@ -101,4 +101,9 @@ class HttpUrl { @@ -101,4 +101,9 @@ class HttpUrl {
101 "?service=App.User.CheckbindPhone"; //APP微信登录后检测是否绑定过手机号 101 "?service=App.User.CheckbindPhone"; //APP微信登录后检测是否绑定过手机号
102 static const String get_integral_list = 102 static const String get_integral_list =
103 "?service=App.Activity.GetIntegralList"; //获取客户经理积分列表 103 "?service=App.Activity.GetIntegralList"; //获取客户经理积分列表
  104 + static const String add_table_area =
  105 + "?service=App.Tables.AddTableRegion"; // 添加商家桌位区域
  106 + static const String get_area_by_sellerid =
  107 + "?service=App.Tables.GetRegionBySellerid"; // 获取区域列表
  108 +
104 } 109 }
  1 +import 'package:flutter/material.dart';
  2 +import 'package:flutter_screenutil/flutter_screenutil.dart';
  3 +import 'package:one_key/models/area.dart';
  4 +import 'package:one_key/res/colors.dart';
  5 +import 'package:one_key/widgets/h_empty_view.dart';
  6 +
  7 +class AreaItemTable extends StatefulWidget {
  8 + final String currentArea; //当前选中区域名称
  9 + final Area area;
  10 + final ValueChanged selectCallback;
  11 +
  12 + AreaItemTable(this.area, this.currentArea, this.selectCallback);
  13 +
  14 + @override
  15 + State<StatefulWidget> createState() {
  16 + // TODO: implement createState
  17 + return new AreaItemTableState();
  18 + }
  19 +}
  20 +
  21 +class AreaItemTableState extends State<AreaItemTable> {
  22 + @override
  23 + Widget build(BuildContext context) {
  24 + // TODO: implement build
  25 + Area area = widget.area;
  26 + bool isSelected = area.name == widget.currentArea;
  27 + return GestureDetector(
  28 + onTap: () {
  29 + if (widget.selectCallback != null) {
  30 + widget.selectCallback(widget.area);
  31 + }
  32 + },
  33 + child: Stack(
  34 + children: <Widget>[
  35 + Container(
  36 + // width: ScreenUtil().setWidth(189),
  37 + height: ScreenUtil().setWidth(50),
  38 + margin: EdgeInsets.only(right: ScreenUtil().setWidth(40)),
  39 + padding:
  40 + EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(40)),
  41 + alignment: Alignment.center,
  42 +
  43 + decoration: BoxDecoration(
  44 + borderRadius: BorderRadius.circular(ScreenUtil().setWidth(30)),
  45 + color: isSelected
  46 + ? MyColours.color_199095
  47 + : MyColours.color_ffffff,
  48 + border: Border.all(
  49 + color: MyColours.color_199095,
  50 + width: ScreenUtil().setWidth(2))),
  51 + child: Text(
  52 + area.name,
  53 + style: TextStyle(
  54 + color: isSelected
  55 + ? MyColours.color_ffffff
  56 + : MyColours.color_199095,
  57 + fontSize: ScreenUtil().setSp(32),
  58 + decoration: TextDecoration.none,
  59 + fontWeight: FontWeight.normal),
  60 + ),
  61 + ),
  62 + Positioned(
  63 + left: 0,
  64 + top: 0,
  65 + child: Container(
  66 + width: ScreenUtil().setWidth(73),
  67 + height: ScreenUtil().setHeight(37),
  68 + alignment: Alignment.center,
  69 + decoration: BoxDecoration(
  70 + color: area.count <= 0
  71 + ? MyColours.color_999999
  72 + : MyColours.color_63a6d1,
  73 + borderRadius: BorderRadius.only(
  74 + topRight: Radius.circular(ScreenUtil().setWidth(8)),
  75 + bottomRight: Radius.circular(ScreenUtil().setWidth(8)))),
  76 + child: Text(
  77 + area.count == 0
  78 + ? "满座"
  79 + : area.count == -1
  80 + ? '无'
  81 + : "余${area.count}",
  82 + style: TextStyle(
  83 + color: MyColours.color_ffffff,
  84 + fontSize: ScreenUtil().setSp(26),
  85 + decoration: TextDecoration.none,
  86 + fontWeight: FontWeight.normal)),
  87 + ),
  88 + ),
  89 + ],
  90 + ),
  91 + );
  92 + }
  93 +}
  1 +import 'dart:async';
  2 +
1 import 'package:common_utils/common_utils.dart'; 3 import 'package:common_utils/common_utils.dart';
  4 +import 'package:dotted_border/dotted_border.dart';
2 import 'package:flutter/material.dart'; 5 import 'package:flutter/material.dart';
3 import 'package:flutter_screenutil/flutter_screenutil.dart'; 6 import 'package:flutter_screenutil/flutter_screenutil.dart';
4 import 'package:one_key/constant/state.dart'; 7 import 'package:one_key/constant/state.dart';
5 import 'package:one_key/models/area.dart'; 8 import 'package:one_key/models/area.dart';
6 import 'package:one_key/models/notebook_detail.dart'; 9 import 'package:one_key/models/notebook_detail.dart';
  10 +import 'package:one_key/models/tableOuter.dart';
  11 +import 'package:one_key/pages/table/area_item_table.dart';
7 import 'package:one_key/provider/table_manager_model.dart'; 12 import 'package:one_key/provider/table_manager_model.dart';
8 import 'package:one_key/res/colors.dart'; 13 import 'package:one_key/res/colors.dart';
9 import 'package:one_key/utils/dialog_util.dart'; 14 import 'package:one_key/utils/dialog_util.dart';
10 import 'package:one_key/utils/event_bus.dart'; 15 import 'package:one_key/utils/event_bus.dart';
11 import 'package:one_key/route/navigator_util.dart'; 16 import 'package:one_key/route/navigator_util.dart';
  17 +import 'package:one_key/utils/utils.dart';
12 import 'package:one_key/widgets/MyDivider.dart'; 18 import 'package:one_key/widgets/MyDivider.dart';
13 import 'package:one_key/widgets/app_bar.dart'; 19 import 'package:one_key/widgets/app_bar.dart';
14 import 'package:one_key/widgets/area_item.dart'; 20 import 'package:one_key/widgets/area_item.dart';
@@ -17,8 +23,12 @@ import 'package:one_key/widgets/page_exception.dart'; @@ -17,8 +23,12 @@ import 'package:one_key/widgets/page_exception.dart';
17 import 'package:one_key/widgets/system_app_bar.dart'; 23 import 'package:one_key/widgets/system_app_bar.dart';
18 import 'package:one_key/widgets/table_item.dart'; 24 import 'package:one_key/widgets/table_item.dart';
19 import 'package:one_key/models/table.dart' as t; 25 import 'package:one_key/models/table.dart' as t;
  26 +import 'package:one_key/widgets/v_empty_view.dart';
20 import 'package:provider/provider.dart'; 27 import 'package:provider/provider.dart';
21 import 'dart:convert' as convert; 28 import 'dart:convert' as convert;
  29 +import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
  30 +
  31 +const scrollDuration = Duration(microseconds: 500);
22 32
23 class TableManagerPage extends StatefulWidget { 33 class TableManagerPage extends StatefulWidget {
24 @override 34 @override
@@ -30,6 +40,15 @@ class TableManagerPage extends StatefulWidget { @@ -30,6 +40,15 @@ class TableManagerPage extends StatefulWidget {
30 40
31 class TableManagerPageState extends State<TableManagerPage> { 41 class TableManagerPageState extends State<TableManagerPage> {
32 TableManagerModel tableManagerModel; 42 TableManagerModel tableManagerModel;
  43 + final ItemScrollController itemScrollController = ItemScrollController();
  44 + bool isTap = false;
  45 + int min;
  46 + int max;
  47 + int _selectIndex;
  48 + ScrollController _areaController = ScrollController();
  49 +
  50 + final ItemPositionsListener itemPositionsListener =
  51 + ItemPositionsListener.create();
33 52
34 @override 53 @override
35 void initState() { 54 void initState() {
@@ -42,10 +61,159 @@ class TableManagerPageState extends State<TableManagerPage> { @@ -42,10 +61,159 @@ class TableManagerPageState extends State<TableManagerPage> {
42 EventBus().on("refresh_tablemanager", (arg) { 61 EventBus().on("refresh_tablemanager", (arg) {
43 //订座-完成预订 刷新管理桌位 62 //订座-完成预订 刷新管理桌位
44 tableManagerModel.getReserveList(context); 63 tableManagerModel.getReserveList(context);
  64 + print(tableManagerModel);
45 }); 65 });
46 }); 66 });
47 } 67 }
48 68
  69 + Widget list(List data) => ScrollablePositionedList.builder(
  70 + itemCount: data.length,
  71 + itemBuilder: (context, index) => item(index),
  72 + itemScrollController: itemScrollController,
  73 + itemPositionsListener: itemPositionsListener,
  74 + reverse: false,
  75 + scrollDirection: Axis.vertical,
  76 + );
  77 +
  78 + void scrollTo(int index) => itemScrollController.scrollTo(
  79 + index: index,
  80 + duration: scrollDuration,
  81 + curve: Curves.easeInOutCubic,
  82 + alignment: 0);
  83 +
  84 + void jumpTo(int index) =>
  85 + itemScrollController.jumpTo(index: index, alignment: 0);
  86 +
  87 + /// Generate item number [i].
  88 + Widget item(int i) {
  89 + int heightSum;
  90 + int length =
  91 + tableManagerModel.areaTableMap[tableManagerModel.areas[i].name].length;
  92 + if (length % 4 == 0) {
  93 + heightSum = (length / 4).floor();
  94 + } else {
  95 + heightSum = (length / 4).floor() + 1;
  96 + }
  97 + return Container(
  98 + height: ScreenUtil().setWidth(185) * heightSum +
  99 + heightSum * 10 +
  100 + ScreenUtil().setWidth(60 * 2),
  101 + child: Column(
  102 + children: [
  103 + Container(
  104 + alignment: Alignment.center,
  105 + height: ScreenUtil().setWidth(30 * 2),
  106 + child: Text(tableManagerModel.areas[i].name,
  107 + style: TextStyle(
  108 + fontSize: ScreenUtil().setWidth(30),
  109 + color: MyColours.color_666666)),
  110 + ),
  111 + Container(
  112 + constraints: BoxConstraints(
  113 + minHeight: ScreenUtil().setWidth(185) * heightSum),
  114 + height: ScreenUtil().setWidth(200) * heightSum + heightSum * 10,
  115 + child: GridView.builder(
  116 + physics: NeverScrollableScrollPhysics(),
  117 + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  118 + crossAxisCount: 4,
  119 + childAspectRatio: 8 / 9,
  120 + ),
  121 + itemBuilder: (context, index) {
  122 + return Selector<TableManagerModel, t.Table>(
  123 + shouldRebuild: (pre, next) => true,
  124 + selector: (context, model) => model.currentTables[index],
  125 + builder: (context, table, _) {
  126 + return TableItem(table, onSelected: (table) {
  127 + if ((table as t.Table).selected) {
  128 + tableManagerModel.selectTables.add(table);
  129 + } else {
  130 + tableManagerModel.selectTables
  131 + .removeWhere((t) => t.id == table.id);
  132 + }
  133 + DialogUtil.showTableManagerDialog(context, table)
  134 + .then((value) {
  135 + if (value != null) {
  136 + switch (value) {
  137 + case 1: //查看详情
  138 + NavigatorUtil.goNotebookDetailPage(context,
  139 + tableManagerModel.tableMap[table.id].id);
  140 + break;
  141 + case 2: //订座
  142 + NavigatorUtil.goNoteBookChangePage(
  143 + context,
  144 + NotebookDetail.fromTableManager(
  145 + tableManagerModel.getCurrDdateStr(),
  146 + tableManagerModel.currTimeIndex
  147 + .toString(),
  148 + table),
  149 + "");
  150 + break;
  151 + case 3: //停用,启用桌位
  152 + Map<String, String> params = {
  153 + "id": (table as t.Table).id,
  154 + "status": (table as t.Table).enable == "1"
  155 + ? "0"
  156 + : "1"
  157 + };
  158 + tableManagerModel
  159 + .setSwitchStatus(context, params)
  160 + .then((value) {
  161 + if (value != null) {
  162 + (table as t.Table).enable = ((int.parse(
  163 + (table as t.Table)
  164 + .enable) +
  165 + 1) %
  166 + 2)
  167 + .toString();
  168 + if ((table as t.Table).enable == "1") {
  169 + for (Area area
  170 + in tableManagerModel.areas) {
  171 + if (area.name ==
  172 + tableManagerModel.currentArea) {
  173 + if (table.sign != '5' &&
  174 + table.sign != '1') {
  175 + //已预订
  176 + area.count++;
  177 + }
  178 + break;
  179 + }
  180 + }
  181 + } else {
  182 + for (Area area
  183 + in tableManagerModel.areas) {
  184 + if (area.name ==
  185 + tableManagerModel.currentArea) {
  186 + if (table.sign != '5' &&
  187 + table.sign != '1') {
  188 + //已预订
  189 + area.count--;
  190 + }
  191 + break;
  192 + }
  193 + }
  194 + }
  195 + tableManagerModel.notifyListeners();
  196 + }
  197 + });
  198 + break;
  199 + }
  200 + }
  201 + });
  202 + },
  203 + canSelected: false,
  204 + fromPage: 'table_manage',
  205 + tableMap: tableManagerModel.tableMap,
  206 + rid: "");
  207 + },
  208 + );
  209 + },
  210 + itemCount: tableManagerModel
  211 + .areaTableMap[tableManagerModel.areas[i].name].length,
  212 + )),
  213 + ],
  214 + ));
  215 + }
  216 +
49 @override 217 @override
50 Widget build(BuildContext context) { 218 Widget build(BuildContext context) {
51 return Consumer<TableManagerModel>( 219 return Consumer<TableManagerModel>(
@@ -171,11 +339,6 @@ class TableManagerPageState extends State<TableManagerPage> { @@ -171,11 +339,6 @@ class TableManagerPageState extends State<TableManagerPage> {
171 ], 339 ],
172 ), 340 ),
173 ), 341 ),
174 - Container(  
175 - height: ScreenUtil().setWidth(20),  
176 - width: double.infinity,  
177 - color: MyColours.color_f5f5f5,  
178 - ),  
179 Expanded( 342 Expanded(
180 child: Consumer<TableManagerModel>( 343 child: Consumer<TableManagerModel>(
181 builder: (context, model, child) { 344 builder: (context, model, child) {
@@ -196,178 +359,317 @@ class TableManagerPageState extends State<TableManagerPage> { @@ -196,178 +359,317 @@ class TableManagerPageState extends State<TableManagerPage> {
196 } else { 359 } else {
197 return Container( 360 return Container(
198 color: MyColours.color_ffffff, 361 color: MyColours.color_ffffff,
199 - child: Row(  
200 - children: <Widget>[  
201 - Container(  
202 - width: ScreenUtil().setWidth(170),  
203 - height: double.infinity,  
204 - color: MyColours.color_f1f1f1,  
205 - child: ListView.builder(  
206 - itemBuilder: (context, index) {  
207 - return Selector<TableManagerModel, Area>(  
208 - selector: (context, model) =>  
209 - model.areas[index],  
210 - builder: (context, area, _) {  
211 - return AreaItem(  
212 - area, tableManagerModel.currentArea,  
213 - (area) {  
214 - setState(() {  
215 - tableManagerModel.currentArea =  
216 - (area as Area).name;  
217 - tableManagerModel.currentTables =  
218 - tableManagerModel.areaTableMap[  
219 - tableManagerModel.currentArea];  
220 - });  
221 - });  
222 - },  
223 - );  
224 - },  
225 - itemExtent: ScreenUtil().setHeight(207),  
226 - itemCount: tableManagerModel.areas.length,  
227 - ),  
228 - ),  
229 - Expanded(  
230 - child: Padding(  
231 - padding: EdgeInsets.symmetric(  
232 - vertical: ScreenUtil().setHeight(10),  
233 - horizontal: ScreenUtil().setWidth(9)),  
234 - child: Column(  
235 - children: [  
236 - Expanded(  
237 - child: GridView.builder(  
238 - gridDelegate:  
239 - SliverGridDelegateWithFixedCrossAxisCount(  
240 - crossAxisCount: 3,  
241 - childAspectRatio: 8 / 9),  
242 - itemBuilder: (context, index) {  
243 - return Selector<TableManagerModel,  
244 - t.Table>(  
245 - shouldRebuild: (pre, next) => true,  
246 - selector: (context, model) =>  
247 - model.currentTables[index],  
248 - builder: (context, table, _) {  
249 - return TableItem(table,  
250 - onSelected: (table) {  
251 - if ((table as t.Table).selected) {  
252 - tableManagerModel.selectTables  
253 - .add(table);  
254 - } else {  
255 - tableManagerModel.selectTables  
256 - .removeWhere((t) =>  
257 - t.id == table.id); 362 + child: Column(children: <Widget>[
  363 + VEmptyView(20),
  364 + ValueListenableBuilder<Iterable<ItemPosition>>(
  365 + valueListenable:
  366 + itemPositionsListener.itemPositions,
  367 + builder: (context, positions, child) {
  368 + if (positions.isNotEmpty) {
  369 + // max = positions
  370 + // .where((ItemPosition position) =>
  371 + // position.itemLeadingEdge < 1)
  372 + // .reduce((ItemPosition max,
  373 + // ItemPosition position) =>
  374 + // position.itemLeadingEdge >
  375 + // max.itemLeadingEdge
  376 + // ? position
  377 + // : max)
  378 + // .index;
  379 + min = positions
  380 + .where((ItemPosition position) =>
  381 + position.itemTrailingEdge > 0)
  382 + .reduce((ItemPosition min,
  383 + ItemPosition position) =>
  384 + position.itemTrailingEdge <
  385 + min.itemTrailingEdge
  386 + ? position
  387 + : min)
  388 + .index;
  389 +
  390 + if (isTap) {
  391 + if (min >= _selectIndex) {
  392 + _selectIndex = min;
  393 + } else {
  394 + _selectIndex = _selectIndex;
  395 + }
  396 + isTap = false;
  397 + } else {
  398 + _selectIndex = min;
  399 + }
  400 + tableManagerModel.currentArea =
  401 + tableManagerModel.areas[_selectIndex].name;
  402 + }
  403 + return Container(
  404 + height: ScreenUtil().setWidth(50),
  405 + color: MyColours.color_ffffff,
  406 + margin: EdgeInsets.only(
  407 + bottom: ScreenUtil().setWidth(20)),
  408 + child: ListView.builder(
  409 + controller: _areaController,
  410 + scrollDirection: Axis.horizontal,
  411 + itemBuilder: (context, index) {
  412 + if (index ==
  413 + tableManagerModel.areas.length ||
  414 + tableManagerModel.areas.length == 0) {
  415 + return InkWell(
  416 + onTap: () async {
  417 + //添加区域弹框
  418 + await DialogUtil
  419 + .openCreateAreaDialog(context,
  420 + onTap: (value) async {
  421 + print(value);
  422 + //添加区域
  423 + bool success =
  424 + await tableManagerModel
  425 + .addTableAreas(
  426 + context, value);
  427 + print(success);
  428 + if (success) {
  429 + Utils.showToast('添加成功!');
  430 + TableOuter tableOuter =
  431 + TableOuter();
  432 + tableOuter.name = value;
  433 + tableOuter.list = [];
  434 + tableManagerModel.tableOuterList
  435 + .add(tableOuter);
  436 + tableManagerModel.initData();
  437 + Timer(
  438 + Duration(milliseconds: 500),
  439 + () => _areaController
  440 + .jumpTo(_areaController
  441 + .position
  442 + .maxScrollExtent));
  443 +
  444 + // await tableManagerModel
  445 + // .getTableList(context);
  446 + // await tableManagerModel
  447 + // .initData();
258 } 448 }
259 - DialogUtil.showTableManagerDialog(  
260 - context, table)  
261 - .then((value) {  
262 - if (value != null) {  
263 - switch (value) {  
264 - case 1: //查看详情  
265 - NavigatorUtil  
266 - .goNotebookDetailPage(  
267 - context,  
268 - tableManagerModel  
269 - .tableMap[  
270 - table.id]  
271 - .id);  
272 - break;  
273 - case 2: //订座  
274 - NavigatorUtil.goNoteBookChangePage(  
275 - context,  
276 - NotebookDetail.fromTableManager(  
277 - tableManagerModel  
278 - .getCurrDdateStr(),  
279 - tableManagerModel  
280 - .currTimeIndex  
281 - .toString(),  
282 - table),  
283 - "");  
284 - break;  
285 - case 3: //停用,启用桌位  
286 - Map<String, String>  
287 - params = {  
288 - "id": (table as t.Table)  
289 - .id,  
290 - "status": (table as t  
291 - .Table)  
292 - .enable ==  
293 - "1"  
294 - ? "0"  
295 - : "1"  
296 - };  
297 - tableManagerModel  
298 - .setSwitchStatus(  
299 - context, params)  
300 - .then((value) {  
301 - if (value != null) {  
302 - (table as t.Table)  
303 - .enable =  
304 - ((int.parse((table as t.Table)  
305 - .enable) +  
306 - 1) %  
307 - 2)  
308 - .toString();  
309 - if ((table as t.Table)  
310 - .enable ==  
311 - "1") {  
312 - for (Area area  
313 - in tableManagerModel  
314 - .areas) {  
315 - if (area.name ==  
316 - tableManagerModel  
317 - .currentArea) {  
318 - if (table.sign !=  
319 - '5' &&  
320 - table.sign !=  
321 - '1') {  
322 - //已预订  
323 - area.count++;  
324 - }  
325 - break;  
326 - }  
327 - }  
328 - } else {  
329 - for (Area area  
330 - in tableManagerModel  
331 - .areas) {  
332 - if (area.name ==  
333 - tableManagerModel  
334 - .currentArea) {  
335 - if (table.sign !=  
336 - '5' &&  
337 - table.sign !=  
338 - '1') {  
339 - //已预订  
340 - area.count--;  
341 - }  
342 - break;  
343 - }  
344 - }  
345 - }  
346 - tableManagerModel  
347 - .notifyListeners();  
348 - }  
349 - });  
350 - break;  
351 - }  
352 - }  
353 - });  
354 - },  
355 - canSelected: false,  
356 - fromPage: 'table_manage',  
357 - tableMap:  
358 - tableManagerModel.tableMap,  
359 - rid: ""); 449 + });
360 }, 450 },
361 - );  
362 - },  
363 - itemCount: tableManagerModel  
364 - .currentTables.length,  
365 - )),  
366 - ],  
367 - )),  
368 - )  
369 - ],  
370 - ), 451 + child: DottedBorder(
  452 + dashPattern: [5, 5, 5, 5],
  453 + borderType: BorderType.RRect,
  454 + radius: Radius.circular(
  455 + ScreenUtil().setWidth(30)),
  456 + // padding: EdgeInsets.all(ScreenUtil().setWidth(70)),
  457 + color: MyColours.color_199095,
  458 + strokeWidth:
  459 + ScreenUtil().setWidth(2),
  460 + child: ClipRRect(
  461 + borderRadius: BorderRadius.all(
  462 + Radius.circular(ScreenUtil()
  463 + .setWidth(30))),
  464 + child: Container(
  465 + height: ScreenUtil()
  466 + .setWidth(50 * 2),
  467 + width: ScreenUtil()
  468 + .setWidth(60 * 2),
  469 + child: Column(
  470 + mainAxisAlignment:
  471 + MainAxisAlignment.center,
  472 + children: [
  473 + Image.asset(
  474 + Utils.getImgPath(
  475 + 'add_store'),
  476 + width: ScreenUtil()
  477 + .setWidth(22)),
  478 + ],
  479 + ),
  480 + ),
  481 + ),
  482 + ));
  483 + } else {
  484 + return Selector<TableManagerModel, Area>(
  485 + selector: (context, model) =>
  486 + model.areas[index],
  487 + builder: (context, area, _) {
  488 + return AreaItemTable(area,
  489 + tableManagerModel.currentArea,
  490 + (area) {
  491 + isTap = true;
  492 + scrollTo(index);
  493 + // setState(() {
  494 + tableManagerModel.currentArea =
  495 + tableManagerModel
  496 + .areas[index].name;
  497 + tableManagerModel.currentTables =
  498 + tableManagerModel.areaTableMap[
  499 + tableManagerModel
  500 + .currentArea];
  501 + _selectIndex = index;
  502 + // });
  503 + // setState(() {
  504 + // tableManagerModel.currentArea =
  505 + // (area as Area).name;
  506 + // tableManagerModel.currentTables =
  507 + // tableManagerModel.areaTableMap[
  508 + // tableManagerModel
  509 + // .currentArea];
  510 + // });
  511 + });
  512 + },
  513 + );
  514 + }
  515 + },
  516 +
  517 + // itemExtent: ScreenUtil().setHeight(207),
  518 + itemCount: tableManagerModel.areas.length + 1,
  519 + ),
  520 + );
  521 + }),
  522 + Expanded(
  523 + child: Container(
  524 + color: MyColours.color_ffffff,
  525 + padding: EdgeInsets.symmetric(
  526 + horizontal: ScreenUtil().setWidth(40)),
  527 + width: double.infinity,
  528 + child: list(tableManagerModel.areas)),
  529 + ),
  530 + // Expanded(
  531 + // child: Container(
  532 + // color: MyColours.color_e5e5e5,
  533 + // padding: EdgeInsets.symmetric(
  534 + // vertical: ScreenUtil().setHeight(10),
  535 + // horizontal: ScreenUtil().setWidth(9)),
  536 + // child: Column(
  537 + // children: [
  538 + // Expanded(
  539 + // child: GridView.builder(
  540 + // gridDelegate:
  541 + // SliverGridDelegateWithFixedCrossAxisCount(
  542 + // crossAxisCount: 3,
  543 + // childAspectRatio: 8 / 9),
  544 + // itemBuilder: (context, index) {
  545 + // return Selector<TableManagerModel,
  546 + // t.Table>(
  547 + // shouldRebuild: (pre, next) => true,
  548 + // selector: (context, model) =>
  549 + // model.currentTables[index],
  550 + // builder: (context, table, _) {
  551 + // return TableItem(table,
  552 + // onSelected: (table) {
  553 + // if ((table as t.Table).selected) {
  554 + // tableManagerModel.selectTables
  555 + // .add(table);
  556 + // } else {
  557 + // tableManagerModel.selectTables
  558 + // .removeWhere((t) =>
  559 + // t.id == table.id);
  560 + // }
  561 + // DialogUtil.showTableManagerDialog(
  562 + // context, table)
  563 + // .then((value) {
  564 + // if (value != null) {
  565 + // switch (value) {
  566 + // case 1: //查看详情
  567 + // NavigatorUtil
  568 + // .goNotebookDetailPage(
  569 + // context,
  570 + // tableManagerModel
  571 + // .tableMap[
  572 + // table.id]
  573 + // .id);
  574 + // break;
  575 + // case 2: //订座
  576 + // NavigatorUtil.goNoteBookChangePage(
  577 + // context,
  578 + // NotebookDetail.fromTableManager(
  579 + // tableManagerModel
  580 + // .getCurrDdateStr(),
  581 + // tableManagerModel
  582 + // .currTimeIndex
  583 + // .toString(),
  584 + // table),
  585 + // "");
  586 + // break;
  587 + // case 3: //停用,启用桌位
  588 + // Map<String, String>
  589 + // params = {
  590 + // "id": (table as t.Table)
  591 + // .id,
  592 + // "status": (table as t
  593 + // .Table)
  594 + // .enable ==
  595 + // "1"
  596 + // ? "0"
  597 + // : "1"
  598 + // };
  599 + // tableManagerModel
  600 + // .setSwitchStatus(
  601 + // context, params)
  602 + // .then((value) {
  603 + // if (value != null) {
  604 + // (table as t.Table)
  605 + // .enable =
  606 + // ((int.parse((table as t.Table)
  607 + // .enable) +
  608 + // 1) %
  609 + // 2)
  610 + // .toString();
  611 + // if ((table as t.Table)
  612 + // .enable ==
  613 + // "1") {
  614 + // for (Area area
  615 + // in tableManagerModel
  616 + // .areas) {
  617 + // if (area.name ==
  618 + // tableManagerModel
  619 + // .currentArea) {
  620 + // if (table.sign !=
  621 + // '5' &&
  622 + // table.sign !=
  623 + // '1') {
  624 + // //已预订
  625 + // area.count++;
  626 + // }
  627 + // break;
  628 + // }
  629 + // }
  630 + // } else {
  631 + // for (Area area
  632 + // in tableManagerModel
  633 + // .areas) {
  634 + // if (area.name ==
  635 + // tableManagerModel
  636 + // .currentArea) {
  637 + // if (table.sign !=
  638 + // '5' &&
  639 + // table.sign !=
  640 + // '1') {
  641 + // //已预订
  642 + // area.count--;
  643 + // }
  644 + // break;
  645 + // }
  646 + // }
  647 + // }
  648 + // tableManagerModel
  649 + // .notifyListeners();
  650 + // }
  651 + // });
  652 + // break;
  653 + // }
  654 + // }
  655 + // });
  656 + // },
  657 + // canSelected: false,
  658 + // fromPage: 'table_manage',
  659 + // tableMap:
  660 + // tableManagerModel.tableMap,
  661 + // rid: "");
  662 + // },
  663 + // );
  664 + // },
  665 + // itemCount: tableManagerModel
  666 + // .currentTables.length,
  667 + // )),
  668 + // ],
  669 + // )),
  670 + // )
  671 + // ],
  672 + ]),
371 ); 673 );
372 } 674 }
373 }, 675 },
@@ -4,6 +4,7 @@ import 'package:one_key/constant/constant.dart'; @@ -4,6 +4,7 @@ import 'package:one_key/constant/constant.dart';
4 import 'package:one_key/constant/error.dart'; 4 import 'package:one_key/constant/error.dart';
5 import 'package:one_key/constant/state.dart'; 5 import 'package:one_key/constant/state.dart';
6 import 'package:one_key/models/area.dart'; 6 import 'package:one_key/models/area.dart';
  7 +import 'package:one_key/models/area_model.dart';
7 import 'package:one_key/models/notebook.dart'; 8 import 'package:one_key/models/notebook.dart';
8 import 'package:one_key/models/tableOuter.dart'; 9 import 'package:one_key/models/tableOuter.dart';
9 import 'package:one_key/net/base_resp.dart'; 10 import 'package:one_key/net/base_resp.dart';
@@ -273,6 +274,27 @@ class TableManagerModel with ChangeNotifier { @@ -273,6 +274,27 @@ class TableManagerModel with ChangeNotifier {
273 return tableOuter; 274 return tableOuter;
274 }).toList(); 275 }).toList();
275 } 276 }
  277 + List<AreaSunModel> areaSunModelList = await getRegionBySellerid(context);
  278 + List<String> tempTableName = [];
  279 + List<String> tempAreaName = [];
  280 + for (TableOuter itemTable in tableOuterList) {
  281 + tempTableName.add(itemTable.name);
  282 + }
  283 + for (AreaSunModel itemArea in areaSunModelList) {
  284 + tempAreaName.add(itemArea.name);
  285 + }
  286 + if (tempAreaName.length > tempTableName.length) {
  287 + for (var itemT in tempTableName) {
  288 + tempAreaName.removeWhere((element) => element == itemT);
  289 + }
  290 + for (var item in tempAreaName) {
  291 + TableOuter tableOuter = TableOuter();
  292 + tableOuter.name = item;
  293 + tableOuter.list = [];
  294 + tableOuterList.add(tableOuter);
  295 + }
  296 + }
  297 +
276 return tableOuterList; 298 return tableOuterList;
277 } 299 }
278 300
@@ -398,7 +420,7 @@ class TableManagerModel with ChangeNotifier { @@ -398,7 +420,7 @@ class TableManagerModel with ChangeNotifier {
398 areaTableMap["${outer.name}"] = outer.list; 420 areaTableMap["${outer.name}"] = outer.list;
399 Area area = Area(); 421 Area area = Area();
400 area.name = outer.name; 422 area.name = outer.name;
401 - area.count = count; 423 + area.count = outer.list.length == 0 ? -1 : count;
402 areas.add(area); 424 areas.add(area);
403 } 425 }
404 if (areaTableMap.isNotEmpty) { 426 if (areaTableMap.isNotEmpty) {
@@ -450,4 +472,61 @@ class TableManagerModel with ChangeNotifier { @@ -450,4 +472,61 @@ class TableManagerModel with ChangeNotifier {
450 Utils.showToast(baseResp.msg); 472 Utils.showToast(baseResp.msg);
451 } 473 }
452 } 474 }
  475 +
  476 + //添加商家桌位区域
  477 + Future<bool> addTableAreas(BuildContext context, String name) async {
  478 + Map<String, String> params = {
  479 + "sellerid": userModel.user.sellerid,
  480 + "name": name
  481 + };
  482 + BaseResp<dynamic> baseResp = await DioUtil()
  483 + .request<dynamic>(context, Method.get, HttpUrl.add_table_area,
  484 + data: params, showLoading: true)
  485 + .catchError((error) {
  486 + print(error.toString());
  487 + // if (error is MyError) {
  488 + // switch (error.type) {
  489 + // case 1:
  490 + // pageState = PageState.ConnectivityError;
  491 + // break;
  492 + // case 2:
  493 + // pageState = PageState.ConnectivityTimeOut;
  494 + // break;
  495 + // default:
  496 + // pageState = PageState.ConnectivityError;
  497 + // break;
  498 + // }
  499 + // }
  500 + // notifyListeners();
  501 + return false;
  502 + });
  503 +
  504 + if (baseResp.code == Constant.status_success) {
  505 + if (baseResp.responseData['data'] != null &&
  506 + baseResp.responseData['data'].length > 0) {
  507 + return true;
  508 + } else {
  509 + Utils.showToast(baseResp.msg ?? '新增区域失败!');
  510 + }
  511 + }
  512 + return false;
  513 + }
  514 +
  515 + //获取区域数据
  516 + Future<List<AreaSunModel>> getRegionBySellerid(BuildContext context) async {
  517 + Map<String, String> params = {"sellerid": userModel.user.sellerid};
  518 + BaseResp<List> baseResp = await DioUtil()
  519 + .request<List>(context, Method.get, HttpUrl.get_area_by_sellerid,
  520 + data: params, showLoading: false)
  521 + .catchError((error) {
  522 + print(error.toString());
  523 + });
  524 + List<AreaSunModel> areaSunModelList;
  525 + if (baseResp.code == Constant.status_success) {
  526 + if (baseResp.data.length > 0) {
  527 + areaSunModelList = AreaModel.fromJson(baseResp.responseData).data;
  528 + }
  529 + }
  530 + return areaSunModelList;
  531 + }
453 } 532 }
@@ -15,6 +15,7 @@ import 'package:one_key/utils/utils.dart'; @@ -15,6 +15,7 @@ import 'package:one_key/utils/utils.dart';
15 import 'package:one_key/widgets/MyDivider.dart'; 15 import 'package:one_key/widgets/MyDivider.dart';
16 import 'package:one_key/widgets/common_button.dart'; 16 import 'package:one_key/widgets/common_button.dart';
17 import 'package:one_key/widgets/h_empty_view.dart'; 17 import 'package:one_key/widgets/h_empty_view.dart';
  18 +import 'package:one_key/widgets/round_button.dart';
18 import 'package:one_key/widgets/table_item.dart'; 19 import 'package:one_key/widgets/table_item.dart';
19 import 'package:one_key/widgets/v_empty_view.dart'; 20 import 'package:one_key/widgets/v_empty_view.dart';
20 import 'package:provider/provider.dart'; 21 import 'package:provider/provider.dart';
@@ -25,6 +26,132 @@ import 'package:url_launcher/url_launcher.dart'; @@ -25,6 +26,132 @@ import 'package:url_launcher/url_launcher.dart';
25 typedef CustomCallBack = void Function(Object object); 26 typedef CustomCallBack = void Function(Object object);
26 27
27 class DialogUtil { 28 class DialogUtil {
  29 + static Future openCreateAreaDialog(BuildContext context,
  30 + {CustomCallBack onTap}) async {
  31 + TextEditingController controller = TextEditingController();
  32 + final action = await showDialog(
  33 + context: context,
  34 + barrierDismissible: false,
  35 + builder: (BuildContext context) {
  36 + return Center(
  37 + child: Container(
  38 + padding:
  39 + EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(72)),
  40 + height: ScreenUtil().setWidth(380),
  41 + decoration: BoxDecoration(
  42 + borderRadius: BorderRadius.circular(ScreenUtil().setWidth(30))),
  43 + child: Card(
  44 + shape: RoundedRectangleBorder(
  45 + borderRadius: BorderRadius.all(
  46 + Radius.circular(ScreenUtil().setWidth(30)))), //设置圆角
  47 + child: Column(
  48 + children: [
  49 + VEmptyView(40),
  50 + Container(
  51 + // height: ScreenUtil().setWidth(48),
  52 + alignment: Alignment.center,
  53 + child: Text('新建区域',
  54 + style: TextStyle(
  55 + fontSize: ScreenUtil().setSp(36),
  56 + color: MyColours.color_199095)),
  57 + ),
  58 + Padding(
  59 + padding: EdgeInsets.symmetric(
  60 + horizontal: ScreenUtil().setWidth(40)),
  61 + child: Row(
  62 + crossAxisAlignment: CrossAxisAlignment.end,
  63 + children: [
  64 + Text(
  65 + '区域名称',
  66 + style: TextStyle(
  67 + fontSize: ScreenUtil().setSp(30),
  68 + color: MyColours.color_199095),
  69 + ),
  70 + HEmptyView(10),
  71 + Expanded(
  72 + child: TextField(
  73 + controller: controller,
  74 + maxLines: 1,
  75 + // //光标颜色
  76 + // cursorColor:
  77 + // widget.isSelect ? Colors.white : MyColours.color_199095,
  78 + //输入文本的样式
  79 + style: TextStyle(
  80 + fontSize: ScreenUtil().setSp(26),
  81 + ),
  82 +
  83 + decoration: InputDecoration(
  84 + contentPadding: EdgeInsets.only(
  85 + top: 15, bottom: -15), //设置文字内容与边框距离
  86 + enabledBorder: UnderlineInputBorder(
  87 + borderSide:
  88 + BorderSide(color: MyColours.color_d8d8d8),
  89 + ),
  90 + focusedBorder: UnderlineInputBorder(
  91 + borderSide:
  92 + BorderSide(color: MyColours.color_d8d8d8),
  93 + ),
  94 + hintText: '点击输入区域名称',
  95 + hintStyle: TextStyle(
  96 + color: MyColours.color_999999,
  97 + fontSize: ScreenUtil().setSp(26),
  98 + ),
  99 + ),
  100 + onChanged: (value) {},
  101 + onEditingComplete: () {
  102 + FocusScope.of(context)
  103 + .requestFocus(FocusNode()); //点击空白处隐藏键盘
  104 + },
  105 + keyboardType: TextInputType.text,
  106 + ),
  107 + )
  108 + ],
  109 + ),
  110 + ),
  111 + VEmptyView(60),
  112 + Row(
  113 + mainAxisAlignment: MainAxisAlignment.center,
  114 + children: [
  115 + RoundButton(
  116 + text: '取消',
  117 + width: ScreenUtil().setWidth(120),
  118 + height: ScreenUtil().setWidth(84),
  119 + gradientStart: MyColours.color_ffffff,
  120 + gradientEnd: MyColours.color_ffffff,
  121 + textColor: MyColours.color_199095,
  122 + borderColor: MyColours.color_199095,
  123 + isBold: false,
  124 + radius: ScreenUtil().setWidth(20),
  125 + onPressed: () {
  126 + Navigator.pop(context);
  127 + },
  128 + ),
  129 + HEmptyView(40),
  130 + RoundButton(
  131 + text: '保存',
  132 + width: ScreenUtil().setWidth(120),
  133 + height: ScreenUtil().setWidth(84),
  134 + isBold: false,
  135 + radius: ScreenUtil().setWidth(20),
  136 + onPressed: () {
  137 + if (controller.text.trim() == '') {
  138 + Utils.showToast('请输入区域名称!');
  139 + return;
  140 + }
  141 + onTap(controller.text);
  142 + Navigator.pop(context, controller.text);
  143 + })
  144 + ],
  145 + )
  146 + ],
  147 + ),
  148 + ),
  149 + ),
  150 + );
  151 + },
  152 + );
  153 + }
  154 +
28 //跳转拨打电话页面 155 //跳转拨打电话页面
29 static goPhone(String phoneNum) async { 156 static goPhone(String phoneNum) async {
30 String url = "tel:$phoneNum"; 157 String url = "tel:$phoneNum";