table_item.dart 14.4 KB

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/models/notebook.dart';
import 'package:one_key/models/reserve_detail_model.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 TableItem 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<String>? oldOjectList;

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

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

class TableItemState extends State<TableItem> {
  @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 = '已买单';
      }
    }

    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(() {
                    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') {
          table.selected = !(table.selected ?? false);
          widget.onSelected!(table);
        } else if (widget.fromPage == 'room_manage') {
          if (table.isExitsClass.toString() != '1' ||
              widget.oldOjectList!.contains(table.id)) {
            table.selected = !(table.selected ?? false);
            widget.onSelected!(table);
          }
        } else if (widget.fromPage == 'tablePhoto') {
          // setState(() {
          //   table.selected = true;
          // });

          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 && table.enable == '0') ||
                        (widget.fromPage == 'room_manage' &&
                            table.isExitsClass.toString() == '1' &&
                            !widget.oldOjectList!.contains(table.id))
                    ? MyColours.color_E0E0E0
                    : MyColours.color_A9E3E6,
                borderRadius: BorderRadius.all(
                    Radius.circular(ScreenUtil().setWidth(8)))),
            child: Stack(
              alignment: Alignment.center,
              children: <Widget>[
                Positioned(
                  left: 0,
                  top: 0,
                  child: table.tidStr == null
                      ? Container()
                      : Container(
                          width: ScreenUtil().setWidth(70),
                          height: ScreenUtil().setHeight(32),
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                              color: widget.fromPage == 'room_manage' &&
                                      table.isExitsClass.toString() == '1' &&
                                      !widget.oldOjectList!.contains(table.id)
                                  ? Color.fromRGBO(147, 147, 147, 1)
                                  : MyColours.color_63a6d1,
                              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(context),
                              style: TextStyle(
                                  color: MyColours.color_ffffff,
                                  fontSize: ScreenUtil().setSp(24),
                                  decoration: TextDecoration.none,
                                  fontWeight: FontWeight.normal)),
                        ),
                ),
                Container(
                  alignment: Alignment.center,
                  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>[
                      VEmptyView(38),
                      Container(
                          alignment: Alignment.center,
                          child: Transform.translate(
                            offset:
                                Offset(0, 1 / 2), //1为 StrutStyle 的 leading的值
                            child: Text(
                              table.name!,
                              maxLines: 2,
                              style: TextStyle(
                                  color: (widget.need && table.enable == '0') ||
                                          (widget.fromPage == 'room_manage' &&
                                              table.isExitsClass.toString() ==
                                                  '1' &&
                                              !widget.oldOjectList!
                                                  .contains(table.id))
                                      ? MyColours.color_999999
                                      : MyColours.color_353535,
                                  fontSize: ScreenUtil().setSp(28),
                                  decoration: TextDecoration.none,
                                  fontWeight: FontWeight.normal),
                              overflow: TextOverflow.ellipsis,
                              strutStyle: StrutStyle(
                                forceStrutHeight: true,
                                height: ScreenUtil().setWidth(2),
                                // leading: ScreenUtil().setWidth(0.4)
                              ),
                            ),
                          )
                          // 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,
                          // ),
                          ),
                      VEmptyView(6),
                      Text(
                        (table.reserver == null || table.reserver!.isEmpty)
                            ? table.tableNum
                            : table.reserver!,
                        style: TextStyle(
                            color: widget.fromPage == 'room_manage' &&
                                    table.isExitsClass.toString() == '1' &&
                                    !widget.oldOjectList!.contains(table.id)
                                ? Color.fromRGBO(147, 147, 147, 1)
                                : signStr == '已停用'
                                    ? MyColours.color_999999
                                    : (table.reserver == null ||
                                            table.reserver!.isEmpty)
                                        ? MyColours.color_353535
                                        : MyColours.color_2bb5b7,
                            fontSize: ScreenUtil().setSp(26),
                            decoration: TextDecoration.none,
                            fontWeight: FontWeight.normal),
                        overflow: TextOverflow.ellipsis,
                      ),
                      VEmptyView(6),
                      Text(
                        table.lowStr(context),
                        style: TextStyle(
                            color: widget.fromPage == 'room_manage' &&
                                    table.isExitsClass.toString() == '1' &&
                                    !widget.oldOjectList!.contains(table.id)
                                ? MyColours.color_999999
                                : MyColours.color_777777,
                            fontSize: ScreenUtil().setSp(26),
                            decoration: TextDecoration.none,
                            fontWeight: FontWeight.normal),
                        overflow: TextOverflow.ellipsis,
                      )
                    ],
                  ),
                ),
                widget.need
                    ? Positioned(
                        bottom: 0,
                        left: 0,
                        right: 0,
                        child: signStr.isEmpty
                            ? Container()
                            : Stack(
                                alignment: Alignment.center,
                                children: [
                                  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),
                                    ),
                                  ),
                                  Positioned(
                                      left: 0,
                                      bottom: 0,
                                      top: 0,
                                      child: table.isPhoto == 1
                                          ? Image.asset(
                                              "assets/photo.png",
                                              width: ScreenUtil().setWidth(40),
                                              // height: ScreenUtil().setWidth(40),
                                            )
                                          : Container())
                                ],
                              ),
                      )
                    : 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.isEmpty
                  ? Positioned(
                      left: ScreenUtil().setWidth(8),
                      bottom: ScreenUtil().setWidth(16),
                      child: table.isPhoto == 1
                          ? Image.asset(
                              "assets/photo.png",
                              width: ScreenUtil().setWidth(40),
                              height: ScreenUtil().setWidth(40),
                            )
                          : Container())
                  : Container()
              : SizedBox()
        ],
      ),
    );
  }
}