notebook_detail_change_page.dart 41 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 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053
import 'dart:convert';
import 'dart:ui';

import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:one_key/models/notebook_detail.dart';
import 'package:one_key/models/reserve_info_model.dart';
import 'package:one_key/provider/notebook_detail_change_model.dart';
import 'package:one_key/provider/notebook_detail_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/event_bus.dart';
import 'package:one_key/utils/navigator_util.dart';
import 'package:one_key/utils/utils.dart';
import 'package:one_key/widgets/MyDivider.dart';
import 'package:one_key/widgets/app_bar.dart';
import 'package:one_key/widgets/common_button.dart';
import 'package:one_key/widgets/h_empty_view.dart';
import 'package:one_key/widgets/new_table_item.dart';
import 'package:one_key/widgets/table_item.dart';
import 'package:one_key/widgets/v_empty_view.dart';
import 'package:provider/provider.dart';
import 'package:one_key/models/table_list.dart' as t;
import 'dart:convert' as convert;

typedef clickCallback = void Function(String value);

class NoteBookChangePage extends StatefulWidget {
  final NotebookDetail detailEntity;
  final String rid;

  const NoteBookChangePage({Key key, this.detailEntity, this.rid})
      : super(key: key);
  @override
  _NoteBookChangePageState createState() => _NoteBookChangePageState();
}

class _NoteBookChangePageState extends State<NoteBookChangePage> {
  DateTime dateTime; //当前日期
  NotebookDetailChangeModel _notebookDetailChangeModel;
  FocusNode _phoneNode = FocusNode();
  FocusNode _nameNode = FocusNode();
  FocusNode _needNode = FocusNode();
  NotebookDetailModel detailModel = NotebookDetailModel();

  @override
  void initState() {
    super.initState();
    dateTime = DateTime.now();

    _notebookDetailChangeModel =
        Provider.of<NotebookDetailChangeModel>(context, listen: false);
    _notebookDetailChangeModel.initDateHourMinuteList(context);
    String ddate = widget.detailEntity.ddate.toString() + '000';
    _notebookDetailChangeModel.getNewTableList(
        context,
        ddate,
        widget.detailEntity.ddate_solt,
        widget.detailEntity.pnum,
        widget.detailEntity.tables);
    _initData();
  }

  _initData() {
    print(widget.detailEntity);
    for (var item in widget.detailEntity.tables) {
      item.selected = true;
    }
  }

  _topWidget() {
    return Container(
      padding: EdgeInsets.all(ScreenUtil().setWidth(40)),
      child: Column(
        children: [
          //第一行 日期选择
          Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: _notebookDetailChangeModel.dateList.map((value) {
                return CustomButton(
                  dateText: value['title'],
                  fontSize: value['fontSize'],
                  dayText: value['dayText'],
                  isImage: value['isImage'],
                  isSelect: value['select'],
                  onTap: () async {
                    print(value['title']);
                    FocusScope.of(context)
                        .requestFocus(FocusNode()); //点击空白处隐藏键盘
                    if (value['title'] == '其他') {
                      _calendWidget(DateTime.now());
                    } else {
                      for (int j = 0;
                          j < _notebookDetailChangeModel.dateList.length;
                          j++) {
                        _notebookDetailChangeModel.dateList[j]['select'] =
                            false;

                        if (_notebookDetailChangeModel.dateList[j]['title'] ==
                            value['title']) {
                          _notebookDetailChangeModel.dateList[j]['select'] =
                              true;

                          if (j == 0 || j == 1) {
                            _notebookDetailChangeModel.dateList[2]['title'] =
                                '其他';
                          }
                          if (j ==
                              _notebookDetailChangeModel.dateList.length - 1) {
                            String selectStr =
                                _notebookDetailChangeModel.dateList[2]['title'];
                            String timeNow = DateUtil.formatDate(
                              DateTime.now(),
                            );
                            String selectDate =
                                timeNow.replaceRange(5, 10, selectStr);
                            _calendWidget(DateUtil.getDateTime(selectDate));
                          }
                        }
                      }
                      //选完今天明天刷新页面
                      int ddate = _getDdate(_notebookDetailChangeModel);
                      String ddateSolt =
                          _getDdateSolt(_notebookDetailChangeModel);
                      String pnum = _getPnum(_notebookDetailChangeModel);
                      List<t.TableList> list =
                          await _notebookDetailChangeModel.getNewTableList(
                              context,
                              '${ddate}',
                              ddateSolt,
                              pnum,
                              _notebookDetailChangeModel.tableList);
                      if (list.length == 0) {
                        _notebookDetailChangeModel.isRecommend = true;
                      }
                    }
                    _notebookDetailChangeModel.notifyListeners();
                  },
                );
              }).toList()),

          VEmptyView(60),
          //早市、午市、晚市
          Row(
              // mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: _notebookDetailChangeModel.sunDateList.map((value) {
            return Container(
              margin: _notebookDetailChangeModel.sunDateList.length == 3 &&
                      value['ddateSolt'] == 3
                  ? EdgeInsets.only(right: 0)
                  : EdgeInsets.only(right: ScreenUtil().setWidth(20)),
              child: CustomButton(
                onTap: () {
                  FocusScope.of(context).requestFocus(FocusNode()); //点击空白处隐藏键盘
                  for (var item in _notebookDetailChangeModel.sunDateList) {
                    item['isSelect'] = false;
                    if (item['dateText'] == value['dateText']) {
                      item['isSelect'] = true;
                      String key = '';

                      if (item['ddateSolt'] == 1) {
                        //早市
                        key = 'morning';
                      } else if (item['ddateSolt'] == 2) {
                        //午市
                        key = 'noon';
                      } else if (item['ddateSolt'] == 3) {
                        //晚市
                        key = 'night';
                      }
                      if (key != '') {
                        for (var sunitem
                            in _notebookDetailChangeModel.dailyMap[key]) {
                          if (sunitem['select'] == true) {
                            _notebookDetailChangeModel.ddateStr =
                                sunitem['title'];
                          }
                        }
                      }
                      _notebookDetailChangeModel.notifyListeners();
                    }
                  }
                  int ddate = _getDdate(_notebookDetailChangeModel);
                  String pnum = _getPnum(_notebookDetailChangeModel);
                  String ddateSolt = _getDdateSolt(_notebookDetailChangeModel);
                  _notebookDetailChangeModel.getNewTableList(
                      context,
                      '${ddate}',
                      '${ddateSolt}',
                      pnum,
                      _notebookDetailChangeModel.tableList);
                },
                dateText: value['dateText'],
                dayText: '',
                isSelect: value['isSelect'],
              ),
            );
          }).toList()),
          VEmptyView(60),

          ///人数选择
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: _notebookDetailChangeModel.personNumList.map((value) {
              return CustomButton(
                onTap: () {
                  for (int j = 0;
                      j < _notebookDetailChangeModel.personNumList.length;
                      j++) {
                    _notebookDetailChangeModel.personNumList[j]['isSelect'] =
                        false;

                    if (_notebookDetailChangeModel.personNumList[j]
                            ['dateText'] ==
                        value['dateText']) {
                      _notebookDetailChangeModel.personNumList[j]['isSelect'] =
                          true;

                      if (j < 5) {
                        _notebookDetailChangeModel.numController.text =
                            value['dateText'];
                        FocusScope.of(context)
                            .requestFocus(FocusNode()); //点击空白处隐藏键盘

                      }

                      // if (j < 5) {
                      //   _notebookDetailChangeModel.personNumList[5]
                      //       ['dateText'] = '更多';
                      // }
                    }
                  }
                  _notebookDetailChangeModel.notifyListeners();
                  //人数选择页面刷新
                  String pnum = _getPnum(_notebookDetailChangeModel);
                  int ddate = _getDdate(_notebookDetailChangeModel);
                  String ddateSolt = _getDdateSolt(_notebookDetailChangeModel);

                  _notebookDetailChangeModel.getNewTableList(
                      context,
                      '${ddate}',
                      ddateSolt,
                      pnum,
                      _notebookDetailChangeModel.tableList);
                },
                dateText: value['dateText'],
                fontSize: value['fontSize'],
                dayText: '',
                width: value['width'],
                isImage: value['isImage'],
                isSelect: value['isSelect'],
                isTextFiled: value['isTextFiled'],
                model: _notebookDetailChangeModel,
              );
            }).toList(),
          )
        ],
      ),
    );
  }

  _calendWidget(DateTime dateTime) {
    DialogUtil.showCalendarDialog(context, dateTime).then((day) {
      if (day != null) {
        // _createDateText(day);
        dateTime = day;
        int dateTimeMill = day.millisecondsSinceEpoch;
        String dateText = DateUtil.formatDateMs(dateTimeMill, format: 'MM-dd');
        bool isThird = true;
        for (int i = 0; i < _notebookDetailChangeModel.dateList.length; i++) {
          _notebookDetailChangeModel.dateList[i]['select'] = false;

          if (_notebookDetailChangeModel.dateList[i]['title'] == dateText) {
            _notebookDetailChangeModel.dateList[i]['select'] = true;
            isThird = false;
          }
        }
        if (isThird) {
          _notebookDetailChangeModel.dateList[2]['select'] = true;
          _notebookDetailChangeModel.dateList[2]['title'] = dateText;
        } else {
          _notebookDetailChangeModel.dateList[2]['title'] = '其他';
        }
        // 选完日历刷新页面
        String ddateSolt = _getDdateSolt(_notebookDetailChangeModel);
        String pnum = _getPnum(_notebookDetailChangeModel);
        _notebookDetailChangeModel.getNewTableList(
            context,
            '${dateTimeMill}',
            ddateSolt,
            _getPnum(_notebookDetailChangeModel),
            _notebookDetailChangeModel.tableList);
      }
      _notebookDetailChangeModel.notifyListeners();
    });
  }

  /// 可订桌位
  _middleWidget() {
    List canBookTable = [];
    if (_notebookDetailChangeModel.isRecommend) {
      canBookTable = _notebookDetailChangeModel.recommendList;
    } else {
      canBookTable = _notebookDetailChangeModel.tableList;
    }
    return Container(
      padding: EdgeInsets.all(ScreenUtil().setWidth(40)),
      color: MyColours.color_f5f5f5,
      child: Column(
        children: [
          InkWell(
              onTap: () async {
                FocusScope.of(context).requestFocus(FocusNode()); //点击空白处隐藏键盘
                //当前选中 月 日string
                String mdStr = '';
                //今天 明天 其他天
                for (var item in _notebookDetailChangeModel.dateList) {
                  if (item['select'] == true) {
                    mdStr = item['title'];
                  }
                }
                String timeNowYear =
                    DateUtil.formatDate(DateTime.now(), format: 'yyyy');
                String ymyStr = timeNowYear + '-' + mdStr; //年月日
                String timeStr = ymyStr + ' ' + "00:00:00";
                int ddate = DateUtil.getDateMsByTimeStr(timeStr); //筛选日期时间戳
                String ddateSolt = '';
                for (var item in _notebookDetailChangeModel.sunDateList) {
                  if (item['isSelect']) {
                    ddateSolt = '${item['ddateSolt']}';
                  }
                }

                // String tempDdate = ymyStr + ' ' + ddateStr + ':00';
                // int ddate = DateUtil.getDateMsByTimeStr(timeStr);
                Map temp = await NavigatorUtil.goSelectTablePage(
                    context, widget.rid, ddate, ddateSolt,
                    canChoose: true,
                    object: {'object': _notebookDetailChangeModel.tableList});
                // if (temp['tid'] != null) {
                //   setReserveStatus("5", tid: temp['tid']);
                // }
                if (temp == null || temp['object'].length == 0) {
                  if (_notebookDetailChangeModel.tableList.length == 0) {
                    _notebookDetailChangeModel.isRecommend = true;
                    _notebookDetailChangeModel.tableList = [];
                    for (t.TableList item
                        in _notebookDetailChangeModel.recommendList) {
                      item.selected = false;
                    }
                    setState(() {});
                  }
                } else {
                  _notebookDetailChangeModel.isRecommend = false;
                  _notebookDetailChangeModel.tableList = temp['object'];
                  // if (_notebookDetailChangeModel.tableList.length == 0) {
                  //   isRecommend = true;
                  // }
                  for (t.TableList item
                      in _notebookDetailChangeModel.tableList) {
                    item.selected = true;
                  }
                  setState(() {});
                }

                // _notebookDetailChangeModel.notifyListeners();
              },
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.end,
                children: [
                  Text(
                    '可订桌位',
                    style: TextStyle(
                        color: MyColours.color_353535,
                        fontSize: ScreenUtil().setSp(30)),
                  ),
                  Row(
                    children: [
                      Text('更多',
                          style: TextStyle(
                              color: MyColours.color_353535,
                              fontSize: ScreenUtil().setSp(26))),
                      HEmptyView(20),
                      Image.asset(
                        'assets/arr_right_gray.png',
                        width: ScreenUtil().setWidth(12),
                        height: ScreenUtil().setWidth(22),
                      )
                    ],
                  ),
                ],
              )),
          VEmptyView(32),
          Align(
            alignment: Alignment.centerRight,
            child: Container(
              // color: Colors.red,
              // height: ScreenUtil().setHeight(178),
              height: ScreenUtil().setHeight(170),
              child: ListView.builder(
                physics: const NeverScrollableScrollPhysics(),
                itemBuilder: (BuildContext contxt, int index) {
                  return NewTableItem(
                    canBookTable[index],
                    isRegionName: true,
                    canSelected: true,
                    onSelected: (table) {
                      if ((table as t.TableList).selected) {
                        _notebookDetailChangeModel.tableList.add(table);
                      } else {
                        _notebookDetailChangeModel.tableList
                            .removeWhere((t) => t.id == table.id);
                      }
                    },
                  );
                },
                itemCount: canBookTable.length > 3 ? 3 : canBookTable.length,
                shrinkWrap: true,
                scrollDirection: Axis.horizontal,
              ),
            ),
          ),
        ],
      ),
    );
  }

  _bottomWidget() {
    return Container(
      padding: EdgeInsets.symmetric(
        horizontal: ScreenUtil().setWidth(40),
      ),
      margin: EdgeInsets.only(top: ScreenUtil().setWidth(72)),
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Expanded(
                child: TextField(
                  maxLines: 1,
                  //输入文本的样式
                  style: TextStyle(
                      fontSize: ScreenUtil().setSp(34),
                      color: MyColours.color_353535),
                  controller: _notebookDetailChangeModel.phoneController,
                  focusNode: _phoneNode,
                  // textAlignVertical: TextAlignVertical.top,
                  decoration: InputDecoration(
                    hintText: "客户电话",
                    hintStyle: TextStyle(
                      color: MyColours.color_999999,
                      fontSize: ScreenUtil().setSp(34),
                    ),
                    // contentPadding:
                    //     EdgeInsets.only(bottom: ScreenUtil().setWidth(17)),
                    border: InputBorder.none,
                  ),
                  onChanged: (value) {},
                  onEditingComplete: () {
                    print('fff');
                    _phoneNode.unfocus();
                  },
                  keyboardType: TextInputType.number,
                ),
              ),
              HEmptyView(40),
              InkWell(
                onTap: () {
                  _showDateChooseWidget(context);
                },
                child: Text(
                  int.parse(widget.detailEntity.is_set_ddate) == 0
                      ? '未设置到店时间'
                      : _notebookDetailChangeModel.ddateStr,
                  style: TextStyle(
                    color: int.parse(widget.detailEntity.is_set_ddate) == 0
                        ? MyColours.color_999999
                        : MyColours.color_199095,
                    fontSize: ScreenUtil().setSp(34),
                  ),
                ),
              ),
            ],
          ),
          VEmptyView(40),
          MyDivider(ScreenUtil().setWidth(335 * 2), ScreenUtil().setWidth(2),
              color: MyColours.color_F1F0F4),
          VEmptyView(72),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Expanded(
                child: TextField(
                  maxLines: 1,

                  //输入文本的样式
                  style: TextStyle(
                      fontSize: ScreenUtil().setSp(34),
                      color: MyColours.color_353535),
                  controller: _notebookDetailChangeModel.nameController,
                  focusNode: _nameNode,
                  // textAlignVertical: TextAlignVertical.top,
                  decoration: InputDecoration(
                    hintText: "客户姓名(必填)",
                    hintStyle: TextStyle(
                      color: MyColours.color_999999,
                      fontSize: ScreenUtil().setSp(34),
                    ),
                    // contentPadding:
                    //     EdgeInsets.only(bottom: ScreenUtil().setWidth(17)),
                    border: InputBorder.none,
                  ),
                  onChanged: (value) {},
                  onEditingComplete: () {
                    print('fff');
                    _nameNode.unfocus();
                  },
                  // keyboardType: TextInputType.number,
                ),
              ),
              HEmptyView(40),
              Row(
                  children: _notebookDetailChangeModel.sexList.map((value) {
                return _callButton(
                    onPress: () {
                      for (var item in _notebookDetailChangeModel.sexList) {
                        item['select'] = false;
                        if (item['title'] == value['title']) {
                          item['select'] = true;
                        }
                      }
                      _notebookDetailChangeModel.notifyListeners();
                    },
                    content: value['title'],
                    hasLeftBorder: value['hasLeftBorder'],
                    isSelect: value['select']);
              }).toList()),
            ],
          ),
          VEmptyView(40),
          MyDivider(ScreenUtil().setWidth(335 * 2), ScreenUtil().setWidth(2),
              color: MyColours.color_F1F0F4),
          VEmptyView(72),
          TextField(
            maxLines: 1,
            inputFormatters: [LengthLimitingTextInputFormatter(25)],
            //输入文本的样式
            style: TextStyle(
                fontSize: ScreenUtil().setSp(34),
                color: MyColours.color_353535),
            controller: _notebookDetailChangeModel.customController,
            focusNode: _needNode,
            // textAlignVertical: TextAlignVertical.top,
            decoration: InputDecoration(
              hintText: "客户要求(25字以内,选填)",
              hintStyle: TextStyle(
                color: MyColours.color_999999,
                fontSize: ScreenUtil().setSp(34),
              ),
              // contentPadding:
              //     EdgeInsets.only(bottom: ScreenUtil().setWidth(17)),
              border: InputBorder.none,
            ),
            onChanged: (value) {},
            onEditingComplete: () {
              print('fff');
              _needNode.unfocus();
            },
            // keyboardType: TextInputType.number,
          ),
          VEmptyView(40),
          MyDivider(ScreenUtil().setWidth(335 * 2), ScreenUtil().setWidth(2),
              color: MyColours.color_F1F0F4),
          // VEmptyView(72),
          // VEmptyView(62),
        ],
      ),
    );
  }

  ///底部弹框,设置时间30分钟间隔布局
  _showDateChooseWidget(BuildContext context) async {
    List tempMndList = [];

    String title = '早市';
    String key;
    for (var item in _notebookDetailChangeModel.sunDateList) {
      if (item['isSelect'] == true) {
        title = item['dateText'];
        key = item['key'];
        tempMndList = _notebookDetailChangeModel.dailyMap[key];
      }
    }
    //计算行数

    int line = 0;
    int count = tempMndList.length;
    if (count % 3 == 0) {
      line = int.parse('${count / 3}');
    } else {
      line = (count / 3).ceil();
    }
    int height = 85 + 40 + 36 * line + (line - 1) * 15;
    final option = await showModalBottomSheet(
        context: context,
        backgroundColor: Colors.white,
        builder: (context) {
          return StatefulBuilder(builder: (context, state) {
            return SafeArea(
                child: Container(
              decoration: BoxDecoration(
                  borderRadius:
                      BorderRadius.circular(ScreenUtil().setWidth(10))),
              height: ScreenUtil().setWidth(height * 2),
              child: Column(
                children: [
                  InkWell(
                    onTap: () {
                      Navigator.pop(context);
                    },
                    child: Align(
                      alignment: Alignment.centerRight,
                      child: Container(
                        padding: EdgeInsets.fromLTRB(
                            ScreenUtil().setWidth(40),
                            ScreenUtil().setWidth(40),
                            ScreenUtil().setWidth(40),
                            ScreenUtil().setWidth(10)),
                        child: Image.asset(
                          'assets/close.png',
                          width: ScreenUtil().setWidth(32),
                          height: ScreenUtil().setWidth(32),
                        ),
                      ),
                    ),
                  ),
                  Center(
                    child: Text(title,
                        style: TextStyle(
                            fontSize: ScreenUtil().setSp(34),
                            fontWeight: FontWeight.bold,
                            color: MyColours.color_353535)),
                  ),
                  VEmptyView(40),
                  Padding(
                      padding: EdgeInsets.symmetric(
                          horizontal: ScreenUtil().setWidth(60)),
                      child: GridView.builder(
                          padding:
                              EdgeInsets.only(top: ScreenUtil().setWidth(20)),
                          shrinkWrap: true,
                          cacheExtent: ScreenUtil().setWidth(0),
                          itemCount: tempMndList.length,
                          gridDelegate:
                              SliverGridDelegateWithFixedCrossAxisCount(
                                  crossAxisCount: 3,
                                  childAspectRatio: 80 / 36,
                                  mainAxisSpacing:
                                      ScreenUtil().setWidth(15 * 2),
                                  crossAxisSpacing:
                                      ScreenUtil().setWidth(38 * 2)),
                          itemBuilder: (BuildContext context, int index) {
                            // locationState = state;
                            return CustomButton(
                              onTap: () {
                                // state(() {
                                for (var item in tempMndList) {
                                  item['select'] = false;
                                  if (item['title'] ==
                                      tempMndList[index]['title']) {
                                    item['select'] = true;
                                    widget.detailEntity.is_set_ddate = '1';
                                    _notebookDetailChangeModel.isSetDate = "1";
                                    _notebookDetailChangeModel.ddateStr =
                                        item['title'];
                                  }
                                }
                                // });

                                _notebookDetailChangeModel.notifyListeners();
                                Navigator.pop(context);
                              },
                              width: 80,
                              height: 36,
                              dateText: tempMndList[index]['title'].toString(),
                              dayText: '',
                              isSelect: tempMndList[index]['select'],
                            );
                          }))
                ],
              ),
            ));
          });
        });
  }

  Widget _callButton(
      {GestureTapCallback onPress,
      content,
      hasLeftBorder = true,
      isSelect = false}) {
    return InkWell(
      onTap: onPress,
      child: Container(
        width: ScreenUtil().setWidth(84),
        height: ScreenUtil().setHeight(48),
        decoration: BoxDecoration(
            color: isSelect ? MyColours.color_199095 : MyColours.color_fefefe,
            border: Border(
                bottom: BorderSide(
                    color: MyColours.color_6AB6B9,
                    width: ScreenUtil().setWidth(2)),
                top: BorderSide(
                    color: MyColours.color_6AB6B9,
                    width: ScreenUtil().setWidth(1)),
                left: hasLeftBorder
                    ? BorderSide(
                        color: MyColours.color_6AB6B9,
                        width: ScreenUtil().setWidth(2))
                    : BorderSide.none,
                right: BorderSide(
                    color: MyColours.color_6AB6B9,
                    width: ScreenUtil().setWidth(2)))),
        child: Align(
          alignment: Alignment.center,
          child: Text(
            content,
            style: TextStyle(
                color: isSelect ? Colors.white : MyColours.color_353535,
                fontSize: ScreenUtil().setSp(28)),
          ),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    _notebookDetailChangeModel =
        Provider.of<NotebookDetailChangeModel>(context, listen: true);
    return GestureDetector(
        behavior: HitTestBehavior.translucent,
        onTap: () {
          FocusScope.of(context).requestFocus(FocusNode()); //点击空白处隐藏键盘
        },
        child: Scaffold(
          backgroundColor: Colors.white,
          body: Column(children: <Widget>[
            SizedBox(height: ScreenUtil.statusBarHeight),
            MyAppBar(
              "变更预订",
              showBack: true,
            ),
            Expanded(
                child: SingleChildScrollView(
                    child: Column(
              children: [_topWidget(), _middleWidget(), _bottomWidget()],
            ))),
            Container(
                padding: EdgeInsets.symmetric(
                  horizontal: ScreenUtil().setWidth(40),
                  vertical: ScreenUtil().setWidth(60),
                ),
                child: CommonButton(
                  width: double.infinity,
                  height: 84,
                  fontSize: 34,
                  content: "确定修改",
                  state: 2,
                  onPress: () async {
                    String name =
                        _notebookDetailChangeModel.nameController.text.trim();
                    if (ObjectUtil.isEmpty(name)) {
                      Utils.showToast("请填写客户姓名");
                      return;
                    }
                    if (_notebookDetailChangeModel.tableList.length == 0) {
                      Utils.showToast("请选择桌位");
                      return;
                    }
                    SunReserveInfoModel _model =
                        await _notebookDetailChangeModel
                            .setReserveInfo(context);
                    if (ObjectUtil.isNotEmpty(_model.row) ||
                        ObjectUtil.isNotEmpty(_model.row.id)) {
                      print('变更成功');
                      // _notebookDetailChangeModel.clearData();
                      bus.emit("refresh_detail");
                      String ddate_solt = '';
                      if (_model.row.isSetDdate == '1') {
                        String createtime = _model.row.ddate.toString() + '000';
                        DateTime createTime =
                            DateTime.fromMillisecondsSinceEpoch(
                                int.parse(createtime));
                        ddate_solt = DateUtil.formatDate(createTime,
                            format: DateFormats.h_m);
                      } else {
                        if (_model.row.ddateSolt == '1') {
                          ddate_solt = '早餐';
                        } else if (_model.row.ddateSolt == '2') {
                          ddate_solt = '午餐';
                        } else if (_model.row.ddateSolt == '3') {
                          ddate_solt = '晚餐';
                        }
                      }
                      List<dynamic> tableinfo =
                          convert.jsonDecode(_model.row.tableinfo);
                      print(tableinfo);
                      String _nameStr = _model.row.name;
                      if (tableinfo.length > 1) {
                        _nameStr = _model.row.name + '等${tableinfo.length}桌';
                      }
                      NavigatorUtil.goInvicationPage(context, _model.row.id,
                          _nameStr, _model.row.ddate, ddate_solt,
                          replace: true);
                    } else {
                      Utils.showToast("变更预订订单失败,请重试!");
                    }
                  },
                ))
          ]),
        ));
  }
}

/// 获取日期  今天  明天  后天等等
int _getDdate(NotebookDetailChangeModel model) {
  //当前选中 月 日string
  String mdStr = '';
  //今天 明天 其他天
  for (var item in model.dateList) {
    if (item['select'] == true) {
      mdStr = item['title'];
    }
  }
  String timeNowYear = DateUtil.formatDate(DateTime.now(), format: 'yyyy');
  String ymyStr = timeNowYear + '-' + mdStr; //年月日
  String timeStr = ymyStr + ' ' + "00:00:00";
  int ddate = DateUtil.getDateMsByTimeStr(timeStr); //筛选日期时间戳
  return ddate;
}

/// 获取早餐、午餐、晚餐字段 1 ,2, 3
String _getDdateSolt(NotebookDetailChangeModel model) {
  String ddateSolt = '';
  for (var item in model.sunDateList) {
    if (item['isSelect']) {
      ddateSolt = '${item['ddateSolt']}';
    }
  }
  return ddateSolt;
}

///  选中前面的按钮获取人数,输入的自己获取
String _getPnum(NotebookDetailChangeModel model) {
  String pnum = '6';
  for (var item in model.personNumList) {
    if (item['isSelect']) {
      pnum = item['dateText'];
    }
  }
  if (pnum == '更多') {
    pnum = '6';
  }
  return pnum;
}

class CustomButton extends StatefulWidget {
  final String dateText;
  final String dayText;
  final bool isSelect;
  final double fontSize;
  final bool isImage;
  final double width;
  final GestureTapCallback onTap;
  final bool isTextFiled;
  final NotebookDetailChangeModel model;
  final double height;

  const CustomButton({
    Key key,
    this.dateText,
    this.dayText,
    this.isSelect,
    this.fontSize = 34,
    this.isImage = false,
    this.width = 105,
    this.onTap,
    this.isTextFiled = false,
    this.model,
    this.height = 25,
  }) : super(key: key);
  @override
  _ButtonState createState() => _ButtonState();
}

class _ButtonState extends State<CustomButton> {
  FocusNode _cancelNode = FocusNode();
  @override
  void initState() {
    super.initState();
    // 监听换行键盘
    // WidgetsBinding.instance.addPostFrameCallback((_) async {
    //   //添加listener监听
    //   //对应的TextField失去或者获取焦点都会回调此监听
    //   _cancelNode.addListener(() {
    //     if (_cancelNode.hasFocus) {
    //       print('得到焦点');
    //     } else {
    //       print('失去焦点');
    //       int ddate = _getDdate(widget.model);
    //       String ddateSolt = _getDdateSolt(widget.model);
    //       String pnum = widget.model.numController.text;
    //       widget.model.getNewTableList(
    //           context, '${ddate}', ddateSolt, pnum, widget.model.tableList);
    //     }
    //   });
    // });
  }

  @override
  Widget build(BuildContext context) {
    String imgStrSelect = widget.isImage && !widget.isTextFiled
        ? 'assets/calender_select.png'
        : 'assets/more_select.png';
    String imgStrNormal = widget.isImage && !widget.isTextFiled
        ? 'assets/calender_narmol.png'
        : 'assets/more_narmol.png';
    return InkWell(
      onTap: widget.onTap,
      child: Container(
        width: ScreenUtil().setWidth(widget.width * 2),
        height: ScreenUtil().setWidth(widget.height * 2),
        decoration: BoxDecoration(
            color: widget.isSelect ? MyColours.color_199095 : Colors.white,
            borderRadius: BorderRadius.circular(ScreenUtil().setWidth(10)),
            border: Border.all(
                color: MyColours.color_199095,
                width: ScreenUtil().setWidth(2))),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            widget.isTextFiled
                ? Container(
                    alignment: Alignment.center,
                    // color: Colors.red,
                    width: ScreenUtil().setWidth(114),
                    height: ScreenUtil().setWidth(50),
                    // padding: EdgeInsets.zero,
                    child: TextField(
                      controller: widget.model.numController,
                      maxLines: 1,

                      inputFormatters: [
                        LengthLimitingTextInputFormatter(3),
                        WhitelistingTextInputFormatter.digitsOnly
                      ],
                      //光标颜色
                      cursorColor: widget.isSelect
                          ? Colors.white
                          : MyColours.color_199095,
                      //输入文本的样式
                      style: TextStyle(
                          fontSize: ScreenUtil().setSp(30),
                          color: widget.isSelect
                              ? Colors.white
                              : MyColours.color_199095),
                      // controller: _cancelController,
                      focusNode: _cancelNode,
                      textAlignVertical: TextAlignVertical.bottom,
                      decoration: InputDecoration(
                        // fillColor: Colors.lightGreenAccent,
                        // filled: true,
                        border: OutlineInputBorder(borderSide: BorderSide.none),
                        hintText: "更多",
                        hintStyle: TextStyle(
                          color: widget.isSelect
                              ? Colors.white
                              : MyColours.color_199095,
                          fontSize: ScreenUtil().setSp(30),
                        ),
                        // contentPadding: EdgeInsets.only(
                        //     bottom: ScreenUtil().setWidth(30)), //ios 17
                        // border: InputBorder.none,
                      ),
                      onChanged: (value) {
                        bool isThird = true;
                        for (int i = 0;
                            i < widget.model.personNumList.length;
                            i++) {
                          widget.model.personNumList[i]['isSelect'] = false;

                          if (widget.model.personNumList[i]['dateText'] ==
                              value) {
                            widget.model.personNumList[i]['isSelect'] = true;
                            isThird = false;
                          }
                        }
                        if (isThird) {
                          widget.model.personNumList[5]['isSelect'] = true;
                          widget.model.personNumList[5]['dateText'] = value;
                        } else {
                          widget.model.personNumList[5]['dateText'] = '更多';
                        }
                        widget.model.notifyListeners();
                      },
                      onEditingComplete: () {
                        _cancelNode.unfocus();
                        int ddate = _getDdate(widget.model);
                        String ddateSolt = _getDdateSolt(widget.model);
                        String pnum = widget.model.numController.text;
                        widget.model.getNewTableList(context, '${ddate}',
                            ddateSolt, pnum, widget.model.tableList);
                      },

                      keyboardType: TextInputType.number,
                    ),
                  )
                : Text(widget.dateText,
                    style: TextStyle(
                        fontWeight: widget.isImage && widget.dateText == "其他"
                            ? FontWeight.normal
                            : FontWeight.bold,
                        color: widget.isSelect
                            ? MyColours.color_fefefe
                            : MyColours.color_199095,
                        fontSize: ScreenUtil().setSp(widget.fontSize))),
            widget.isImage && !widget.isTextFiled
                ? HEmptyView(20)
                : Container(),
            widget.isImage
                ? Image.asset(widget.isSelect ? imgStrSelect : imgStrNormal,
                    width: ScreenUtil().setWidth(36))
                : Text(widget.dayText,
                    style: TextStyle(
                        fontWeight: FontWeight.bold,
                        color: widget.isSelect
                            ? MyColours.color_fefefe
                            : MyColours.color_199095,
                        fontSize: ScreenUtil().setSp(30)))
          ],
        ),
      ),
    );
  }
}