merge_table_item.dart 19.2 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
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/models/notebook.dart';
import 'package:one_key/res/colors.dart';

import 'package:one_key/models/table.dart' as t;
import 'package:one_key/widgets/v_empty_view.dart';

class MergeTableItem extends StatefulWidget {
  final t.Table table;
  final bool canSelected; //是否能选中
  final ValueChanged<t.Table> onSelected;
  final String fromPage; // 变更、新建、桌位管理三个页面
  final String rid;
  final Map<String, Notebook> tableMap; //记录已预订桌位对应的订单

  final int height; //高度
  final bool need;
  final String tids;

  MergeTableItem(this.table,
      {this.onSelected,
      this.canSelected = false,
      this.height = 60,
      this.fromPage = 'new',
      this.rid,
      this.tableMap,
      this.need = true,
      this.tids});

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new MergeTableItemState();
  }
}

class MergeTableItemState extends State<MergeTableItem> {
  @override
  Widget build(BuildContext context) {
    t.Table table = widget.table;

    String signStr = table.signStr;
    if (table.sign == '5' && widget.tableMap[table.id]?.orderInfo != null) {
      if (widget.tableMap[table.id].orderInfo?.status == '3') {
        signStr = '已买单';
      }
    }

    bool isSelf = false;
    //当前桌子的预订id
    String idNow = '';
    if (widget.tableMap.containsKey('${table.id}')) {
      //包含,证明该桌子已经被预订了
      idNow = widget.tableMap['${table.id}'].id;
      if (idNow == widget.rid) {
        isSelf = true;
      }
    }

    bool locked = false;
    List<String> tids = [];

    if ((table.isLock == '1' && !widget.tids.split(',').contains(table.id)) ||
        table.isMerge == '1') {
      locked = true;
    }

    return GestureDetector(
      onTap: () {
        if (widget.canSelected && widget.fromPage == 'change') {
          //从变更页面进来 canChoose = true
          if (widget.canSelected && signStr.isEmpty) {
            setState(() {
              table.selected = !(table.selected ?? false);
            });
            widget.onSelected(table);
          } else {
            if (table.sign == '5' || table.sign == '1') {
              // 1一般是商户端
              // 5是用户端
              //已预订状态  不是自己的不可以选择,是自己的可以选择
              //当前桌子的预订id
              String idNow = '';
              if (widget.tableMap.containsKey('${table.id}')) {
                //包含,证明该桌子已经被预订了
                idNow = widget.tableMap['${table.id}'].id;
                if (idNow == widget.rid) {
                  setState(() {
                    isSelf = true;
                    table.selected = !(table.selected ?? false);
                  });
                  widget.onSelected(table);
                }
              }
            }
          }
        } else if (widget.fromPage == 'new' &&
            widget.canSelected &&
            signStr.isEmpty) {
          //从安排桌位进来
          setState(() {
            table.selected = !(table.selected ?? false);
          });
          widget.onSelected(table);
        } else if (widget.fromPage == 'table_manage' ||
            widget.fromPage == 'room_manage' ||
            widget.fromPage == 'merge_table') {
          if (!locked) {
            setState(() {
              table.selected = !(table.selected ?? false);
            });

            widget.onSelected(table);
          }
        } else if (widget.fromPage == 'tablePhoto') {
          // setState(() {
          //   table.selected = true;
          // });

          widget.onSelected(table);
        } else {
          setState(() {
            table.selected = !(table.selected ?? false);
          });
          widget.onSelected(table);
        }
      },
      child: Stack(
        children: <Widget>[
          Container(
            // width: ScreenUtil().setWidth(160),
            // height: ScreenUtil().setWidth(widget.height),
            // margin: EdgeInsets.all(ScreenUtil().setWidth(9)),
            decoration: BoxDecoration(
                color: widget.need && signStr == '已预订' && !isSelf
                    ? MyColours.color_afbcc4
                    : widget.canSelected && table.selected
                        ? MyColours.color_199095
                        : MyColours.color_ffffff,
                border: Border.all(
                    width: ScreenUtil().setWidth(2),
                    color: locked
                        ? MyColours.color_BFC4D4
                        : MyColours.color_438E93),
                borderRadius: BorderRadius.all(
                    Radius.circular(ScreenUtil().setWidth(10)))),
            child: Stack(
              // alignment: Alignment.center,
              children: <Widget>[
                Container(
                  // alignment: Alignment.center,
                  // color: Colors.blueAccent,
                  // height: ScreenUtil().setWidth(widget.height),
                  // padding: EdgeInsets.symmetric(
                  //     horizontal: ScreenUtil().setWidth(20)),
                  // margin: EdgeInsets.only(left: ScreenUtil().setWidth(20)),
                  child: Column(
                    // mainAxisSize: MainAxisSize.min,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      widget.need && signStr == '已预订' && !isSelf
                          ? SizedBox()
                          : VEmptyView(10),
                      Container(
                          // color: Colors.red,
                          alignment: Alignment.center,
                          child: Text(
                            table.name,
                            maxLines: 1,
                            style: TextStyle(
                                color: (widget.need &&
                                        signStr == '已预订' &&
                                        !isSelf)
                                    ? MyColours.color_333333
                                    : locked
                                        ? MyColours.color_BFC4D4
                                        : (widget.canSelected && table.selected)
                                            ? MyColours.color_ffffff
                                            : MyColours.color_438E93,
                                fontSize: ScreenUtil().setSp(30),
                                decoration: TextDecoration.none,
                                fontWeight: FontWeight.bold),
                            overflow: TextOverflow.ellipsis,
                          )
                          // Text(
                          //   table.name,
                          //   // textAlign: TextAlign.center,
                          //   maxLines: 2,
                          //   style: TextStyle(
                          //       color: table.signStr == '已停用'
                          //           ? MyColours.color_999999
                          //           : MyColours.color_353535,
                          //       fontSize: ScreenUtil().setSp(28),
                          //       decoration: TextDecoration.none,
                          //       fontWeight: FontWeight.normal),
                          //   overflow: TextOverflow.ellipsis,
                          // ),
                          ),
                      // ((table.reserver != null && table.reserver != '') ||
                      //         (table.pnum != '' &&
                      //             table.pnum != null &&
                      //             table.pnum != '0'))
                      //     ? VEmptyView(20)
                      //     : SizedBox(),
                      VEmptyView(12),
                      signStr == '已预订' && !isSelf
                          ? SizedBox()
                          : Text(
                              table.tableNum,
                              style: TextStyle(
                                  color: signStr == '已预订' && !isSelf
                                      ? MyColours.color_353535
                                      : locked
                                          ? MyColours.color_BFC4D4
                                          : (widget.canSelected &&
                                                  table.selected)
                                              ? MyColours.color_ffffff
                                              : MyColours.color_438E93,
                                  fontSize: ScreenUtil().setSp(14),
                                  decoration: TextDecoration.none,
                                  fontWeight: FontWeight.normal),
                              overflow: TextOverflow.ellipsis,
                            ),
                      // signStr == '已预订' &&
                      //         !isSelf &&
                      //         ((table.reserver != null &&
                      //                 !table.reserver.isEmpty) ||
                      //             (table.pnum != '' &&
                      //                 table.pnum != null &&
                      //                 table.pnum != '0'))
                      //     ? Text(
                      //         (table.reserver == null || table.reserver.isEmpty)
                      //             ? (table.pnum != '' &&
                      //                     table.pnum != null &&
                      //                     table.pnum != '0')
                      //                 ? '(${table.pnum}人)'
                      //                 : ''
                      //             : '${table.reserver}' +
                      //                 (table.pnum != '' &&
                      //                         table.pnum != null &&
                      //                         table.pnum != '0'
                      //                     ? '(${table.pnum}人)'
                      //                     : ''),
                      //         style: TextStyle(
                      //             color: signStr == '已预订' && !isSelf
                      //                 ? MyColours.color_353535
                      //                 : (widget.canSelected && table.selected)
                      //                     ? MyColours.color_ffffff
                      //                     : MyColours.color_353535,
                      //             fontSize: ScreenUtil().setSp(14),
                      //             decoration: TextDecoration.none,
                      //             fontWeight: FontWeight.normal),
                      //         overflow: TextOverflow.ellipsis,
                      //       )
                      //     : SizedBox(),

                      // widget.need &&
                      //         signStr == '已预订' &&
                      //         !isSelf &&
                      //         table.nickName != null &&
                      //         table.nickName != ''
                      //     ? Padding(
                      //         padding: EdgeInsets.only(
                      //           top: ScreenUtil().setWidth(6),
                      //           bottom: ScreenUtil().setWidth(8),
                      //         ),
                      //         child: Text(
                      //           table.nickName != null && table.nickName != ''
                      //               ? '${table.nickName}订'
                      //               : '',
                      //           style: TextStyle(
                      //               color: MyColours.color_353535,
                      //               fontSize: ScreenUtil().setSp(22),
                      //               decoration: TextDecoration.none,
                      //               fontWeight: FontWeight.normal),
                      //           overflow: TextOverflow.ellipsis,
                      //         ),
                      //       )
                      //     : SizedBox(),
                      // VEmptyView(6),
                      // Text(
                      //   table.lowStr,
                      //   style: TextStyle(
                      //       color: MyColours.color_777777,
                      //       fontSize: ScreenUtil().setSp(26),
                      //       decoration: TextDecoration.none,
                      //       fontWeight: FontWeight.normal),
                      //   overflow: TextOverflow.ellipsis,
                      // )
                      signStr == '已预订' && !isSelf
                          ? Container(
                              // width: ScreenUtil().setWidth(160),
                              height: ScreenUtil().setWidth(34),
                            )
                          : SizedBox()
                    ],
                  ),
                ),

                signStr == '已预订' && !isSelf
                    ? SizedBox()
                    : Positioned(
                        left: 0,
                        top: 0,
                        child: table.tidStr == null
                            ? Container()
                            : Container(
                                // width: ScreenUtil().setWidth(60),
                                // height: ScreenUtil().setWidth(42),
                                padding:
                                    EdgeInsets.all(ScreenUtil().setWidth(4)),
                                alignment: Alignment.center,
                                decoration: BoxDecoration(
                                    color: widget.canSelected && table.selected
                                        ? MyColours.color_199095
                                        : MyColours.color_999999,
                                    borderRadius: BorderRadius.only(
                                      topLeft: Radius.circular(
                                          ScreenUtil().setWidth(8)),
                                      // topRight:
                                      //     Radius.circular(ScreenUtil().setWidth(8)),
                                      // bottomRight: Radius.circular(
                                      //     ScreenUtil().setWidth(8))
                                    )),
                                child: Text(table.tidStr,
                                    style: TextStyle(
                                        color: MyColours.color_ffffff,
                                        fontSize: ScreenUtil().setSp(14),
                                        decoration: TextDecoration.none,
                                        fontWeight: FontWeight.normal)),
                              ),
                      ),
                // widget.need && signStr == '已预订'
                //     ? Positioned(
                //         bottom: 0,
                //         left: 0,
                //         right: 0,
                //         child: signStr.isEmpty
                //             ? Container()
                //             : Container(
                //                 width: ScreenUtil().setWidth(160),
                //                 height: ScreenUtil().setWidth(40),
                //                 alignment: Alignment.center,
                //                 decoration: BoxDecoration(
                //                     color: signStr == '已停用'
                //                         ? MyColours.color_777777
                //                         : signStr == '已买单'
                //                             ? MyColours.color_F59A23
                //                             : MyColours.color_E95750,
                //                     borderRadius: BorderRadius.only(
                //                         bottomLeft: Radius.circular(
                //                             ScreenUtil().setWidth(8)),
                //                         bottomRight: Radius.circular(
                //                             ScreenUtil().setWidth(8)))),
                //                 child: Text(
                //                   signStr,
                //                   style: TextStyle(
                //                       color: MyColours.color_ffffff,
                //                       fontSize: ScreenUtil().setSp(24),
                //                       decoration: TextDecoration.none,
                //                       fontWeight: FontWeight.normal),
                //                 ),
                //               ),
                //       )
                //     : SizedBox(),
              ],
            ),
          ),
          // Positioned(
          //     top: 3,
          //     right: 5,
          //     child: widget.canSelected && (table.selected ?? false)
          //         ? Image.asset(
          //             "assets/icon_selected.png",
          //             width: ScreenUtil().setWidth(40),
          //             height: ScreenUtil().setWidth(40),
          //           )
          //         : Container()),
          // widget.need && signStr == '已预订' && !isSelf
          //     ? SizedBox()
          //     : Positioned(
          //         left: ScreenUtil().setWidth(18),
          //         bottom: ScreenUtil().setWidth(12),
          //         child: table.isPhoto != 1
          //             ? Image.asset(
          //                 widget.canSelected && table.selected
          //                     ? 'assets/f_camera_white.png'
          //                     : "assets/f_camera.png",
          //                 width: ScreenUtil().setWidth(22),
          //                 height: ScreenUtil().setWidth(22),
          //               )
          //             : Container()),
          // Positioned(
          //     bottom: 0,
          //     right: 0,
          //     left: 0,
          //     child: signStr == '已预订' && !isSelf
          //         ? Container(
          //             // width: ScreenUtil().setWidth(160),
          //             height: ScreenUtil().setWidth(34),
          //             alignment: Alignment.centerLeft,
          //             padding: EdgeInsets.symmetric(
          //                 horizontal: ScreenUtil().setWidth(10)),
          //             decoration: BoxDecoration(
          //                 color: MyColours.color_d7d7d7,
          //                 borderRadius: BorderRadius.only(
          //                     bottomLeft:
          //                         Radius.circular(ScreenUtil().setWidth(20)),
          //                     bottomRight:
          //                         Radius.circular(ScreenUtil().setWidth(20)))),
          //             child: Text(
          //               '新客',
          //               style: TextStyle(
          //                   color: MyColours.color_353535,
          //                   fontSize: ScreenUtil().setSp(24),
          //                   decoration: TextDecoration.none,
          //                   fontWeight: FontWeight.normal),
          //             ),
          //           )
          //         : SizedBox())
        ],
      ),
    );
  }
}