/*
 * @Author: XianKaiQun
 * @Date: 2020-09-14 17:40:13
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2023-03-31 10:16:26
 * @Description: 
 */
part of '../index.dart';

///非编辑状态下显示的表格
///只有在非编辑模式下[PrivateDetailStore.isEdit==false]
///或者[PrivateDetailStore.data.status!=1](非待审核状态) 才会显示
///否则显示[_ModifyComponent]  操作表单
class _TableComponent extends StatelessWidget {
  const _TableComponent({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;
    final store = Provider.of<PrivateDetailStore>(context);
    final data = store.data;

    if (store.isEdit || data?.id == null || data?.status == 1) {
      return SliverToBoxAdapter();
    }
    return WisCard(
      isSliver: true,
      color: Colors.white,
      margin: EdgeInsets.symmetric(horizontal: 15.pt, vertical: 5.pt),
      child: Wisdom.column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        padding: EdgeInsets.symmetric(horizontal: 15.pt),
        color: Colors.white,
        border: Border(
          top: Divider.createBorderSide(context),
          bottom: Divider.createBorderSide(context),
        ),
        children: ListTile.divideTiles(
          context: context,
          tiles: [
            WFormTile(
              minWidth: 120.pt,
              leading: Text('申请人'),
              child: Text('${data!.applyMan ?? ''}'),
            ),
            WFormTile(
              minWidth: 120.pt,
              leading: Text('与申请人关系'),
              child: Text(store.relationMap[data.relation] ?? '--'),
            ),
            if (data.openDoorWay == 'scanCard')
              WFormTile(
                minWidth: 120.pt,
                leading: Text('卡号'),
                child: Text(data.doorCards?.join('，') ?? '--'),
              ),
            if (data.status != 5)
              WFormTile(
                minWidth: 120.pt,
                leading: Text('通行门禁组'),
                child: Text(data.doorGroups!
                    .map((e) => e.doorGroupName)
                    .toList()
                    .join('，')),
              ),
            if (data.status != 5)
              WFormTile(
                minWidth: 120.pt,
                leading: Text('关联住户'),
                child: Text(
                  [
                    data.buildName,
                    data.unitName,
                    data.houseInfo,
                    data.residentName,
                  ].where((e) => e != null && e != '').toList().join(','),
                ),
              ),
            if (data.status != 5)
              WFormTile(
                minWidth: 120.pt,
                leading: Text('失效日期'),
                child: Wisdom.row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Text(
                      data.expirationTime ?? '--',
                      style: TextStyle(
                        color: store.isOverDate() ? colorScheme.danger : null,
                      ),
                    ),
                    if (store.isOverDate())
                      Container(
                        margin: EdgeInsets.only(left: 5.pt),
                        child: Text(
                          "已失效",
                          style: TextStyle(
                            color: colorScheme.minor,
                          ),
                        ),
                      )
                  ],
                ),
              ),
            if (data.status == 5)
              WFormTile(
                minWidth: 120.pt,
                leading: Text('拒绝原因'),
                child: Text(store.data!.auditRemark ?? '--'),
              ),
            if (data.status != 2)
              WFormTile(
                minWidth: 120.pt,
                leading: Text('操作人'),
                child: Text(data.operationName ?? '--'),
              ),
            if (data.status != 2)
              WFormTile(
                minWidth: 120.pt,
                leading: Text('操作时间'),
                child: Text(DateTime.parse(data.updateAt!).toFormat()),
              ),
          ],
        ).toList(),
      ),
    );
  }
}
