f_table_item.dart 26.1 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

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/utils/utils.dart';
import 'package:one_key/widgets/v_empty_view.dart';

import '../utils/screen_util.dart';

class FTableItem 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 List<t.Table>? selectTables;

  FTableItem(this.table,
      {this.onSelected,
      this.canSelected = false,
      this.height = 185,
      this.fromPage = 'new',
      this.rid,
      this.tableMap,
      this.need = true,
      this.selectTables});

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

class FTableItemState extends State<FTableItem> {
  // 判断两数组是否有相同元素, true: 存在相同 false:没相同
  haveSame(List arr, List otherArr) {
    if (arr == null || otherArr == null) {
      return false;
    }
    // 合并数组

    arr.addAll(otherArr);

    // 合并数组并去重
    Set setArr = new Set(); //用set进行去重
    setArr.addAll(arr); //把数组塞进set里
    List newList = setArr.toList();

    return arr.length != newList.length;
  }

  @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;
      }
    }
    List selectTids = []; //被选中的桌子ids
    if (widget.selectTables != null) {
      widget.selectTables!.forEach((element) {
        selectTids.add(element.id);
      });
    }

    bool islock = (table.isLock == '1' &&
            widget.tableMap!.containsKey(table.lockTid)) ||
        (table.isMerge == '1' &&
            haveSame(widget.tableMap!.keys.toList(), table.tids!.split(','))) ||
        (table.isLock == '1' && selectTids.contains(table.lockTid)) ||
        (table.isMerge == '1' &&
            haveSame(
                selectTids,
                table.tids!.split(
                    ','))); //真正上锁*******被合并桌子上锁:合并的桌子被预订&&islock == '1' || 合并桌子上锁:被合并的桌子被预订&&ismerge == '1'

    return GestureDetector(
      onTap: () {
        if (widget.canSelected && widget.fromPage == 'change') {
          if (islock && signStr != '已预订') {
            return;
          }
          //从变更页面进来 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) {
          if (islock && signStr != '已预订') {
            return;
          }
          //从安排桌位进来
          setState(() {
            table.selected = !(table.selected ?? false);
          });
          widget.onSelected!(table);
        } else if (widget.fromPage == 'table_manage' ||
            widget.fromPage == 'room_manage') {
          if (islock && signStr != '已预订') {
            return;
          }
          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: islock && signStr != '已预订' && widget.fromPage != 'tablePhoto'
          ? Stack(
              children: [
                Container(
                    // width: ScreenUtil().setWidth(160),
                    // height: ScreenUtil().setWidth(widget.height),
                    // margin: EdgeInsets.all(ScreenUtil().setWidth(9)),
                    decoration: BoxDecoration(
                        color: MyColours.color_DBDBDB,
                        border: Border.all(
                            width: ScreenUtil().setWidth(2),
                            color: MyColours.color_BFC4D4),
                        borderRadius: BorderRadius.all(
                            Radius.circular(ScreenUtil().setWidth(20)))),
                    child: Column(
                      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: MyColours.color_333333,
                                  fontSize: ScreenUtil().setSp(36),
                                  decoration: TextDecoration.none,
                                  fontWeight: FontWeight.bold),
                              overflow: TextOverflow.ellipsis,
                            )),
                        VEmptyView(10),
                        Image.asset(
                          Utils.getImgPath('lock'),
                          width: w(16),
                        )
                      ],
                    )),
                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
                              //     : Color.fromRGBO(239, 239, 239, 1),
                              borderRadius: BorderRadius.only(
                            topLeft: Radius.circular(ScreenUtil().setWidth(20)),
                            // topRight:
                            //     Radius.circular(ScreenUtil().setWidth(8)),
                            // bottomRight: Radius.circular(
                            //     ScreenUtil().setWidth(8))
                          )),
                          child: Text(table.tidStr,
                              style: TextStyle(
                                  color: MyColours.color_999999,
                                  fontSize: ScreenUtil().setSp(20),
                                  decoration: TextDecoration.none,
                                  fontWeight: FontWeight.normal)),
                        ),
                ),
              ],
            )
          : 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
                          ? table.sign == '10'
                              ? MyColours.color_FEF3E6
                              : MyColours.color_80438E93
                          : widget.canSelected && table.selected!
                              ? MyColours.color_199095
                              : MyColours.color_ffffff,
                      border: Border.all(
                          width: ScreenUtil().setWidth(2),
                          color: MyColours.color_E0E0E0),
                      borderRadius: BorderRadius.all(
                          Radius.circular(ScreenUtil().setWidth(20)))),
                  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
                                          : (widget.canSelected &&
                                                  table.selected!)
                                              ? MyColours.color_ffffff
                                              : MyColours.color_333333,
                                      fontSize: ScreenUtil().setSp(34),
                                      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(8)
                                : SizedBox(),
                            signStr == '已预订' && !isSelf
                                ? SizedBox()
                                : Text(
                                    table.tableNum,
                                    style: TextStyle(
                                        color: signStr == '已预订' && !isSelf
                                            ? MyColours.color_353535
                                            : (widget.canSelected &&
                                                    table.selected!)
                                                ? MyColours.color_ffffff
                                                : MyColours.color_353535,
                                        fontSize: ScreenUtil().setSp(22),
                                        decoration: TextDecoration.none,
                                        fontWeight: FontWeight.normal),
                                    overflow: TextOverflow.ellipsis,
                                  ),
                            signStr == '已预订' &&
                                    !isSelf &&
                                    ((table.reserver != null &&
                                            !table.reserver!.isEmpty &&
                                            table.reserver != '') ||
                                        (table.pnum != '' &&
                                            table.pnum != null &&
                                            table.pnum != '0'))
                                ? Text(
                                    (table.reserver == null ||
                                            table.reserver!.isEmpty ||
                                            table.reserver == '')
                                        ? (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(22),
                                        decoration: TextDecoration.none,
                                        fontWeight: FontWeight.normal),
                                    overflow: TextOverflow.ellipsis,
                                  )
                                : SizedBox(),

                            widget.need &&
                                    signStr == '已预订' &&
                                    !isSelf &&
                                    table.place_order_name != null &&
                                    table.place_order_name != ''
                                ? Padding(
                                    padding: EdgeInsets.only(
                                      top: ScreenUtil().setWidth(6),
                                      bottom: ScreenUtil().setWidth(8),
                                    ),
                                    child: Text(
                                      table.place_order_name != null && table.place_order_name != ''
                                          ? '${table.place_order_name}订'
                                          : '',
                                      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 && (table.sign == '10' || table.reserveCountShow != '') 
                                ? 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
                                              : Color.fromRGBO(
                                                  239, 239, 239, 1),
                                          borderRadius: BorderRadius.only(
                                            topLeft: Radius.circular(
                                                ScreenUtil().setWidth(20)),
                                            // topRight:
                                            //     Radius.circular(ScreenUtil().setWidth(8)),
                                            // bottomRight: Radius.circular(
                                            //     ScreenUtil().setWidth(8))
                                          )),
                                      child: Text(table.tidStr,
                                          style: TextStyle(
                                              color: widget.canSelected &&
                                                      table.selected!
                                                  ? MyColours.color_ffffff
                                                  : MyColours.color_333333,
                                              fontSize: ScreenUtil().setSp(20),
                                              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.center,
                            padding: EdgeInsets.symmetric(
                                horizontal: ScreenUtil().setWidth(10)),
                            decoration: BoxDecoration(
                                color: table.sign == '10'
                                    ? MyColours.color_F7C797
                                    :table.reserveCountShow == ''? Colors.transparent: MyColours.color_d9d9d9,
                                borderRadius: BorderRadius.only(
                                    bottomLeft: Radius.circular(
                                        ScreenUtil().setWidth(20)),
                                    bottomRight: Radius.circular(
                                        ScreenUtil().setWidth(20)))),
                            child: Text(
                              table.sign == '10'
                                  ? table.label!
                                  : table.reserveCountShow,
                              textAlign: TextAlign.center,
                              style: TextStyle(
                                  color: MyColours.color_28323B,
                                  fontSize: ScreenUtil().setSp(22),
                                  decoration: TextDecoration.none,
                                  fontWeight: FontWeight.normal),
                            ),
                          )
                        : SizedBox())
              ],
            ),
    );
  }
}