/*
 * @Author: XianKaiQun
 * @Date: 2020-09-15 09:06:33
 * @LastEditors: wuwei
 * @LastEditTime: 2024-01-16 16:12:13
 * @Description: 
 */
part of '../index.dart';

///切换到修改时  显示的表单
///
class _ModifyComponent extends StatelessWidget {
  const _ModifyComponent({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 (data == null) {
      return SliverToBoxAdapter();
    }
    if (!store.isEdit && data.status != 1) {
      return SliverToBoxAdapter();
    }
    return WisCard(
      isSliver: true,
      color: Colors.white,
      margin: EdgeInsets.symmetric(horizontal: 15.pt, vertical: 5.pt),
      child: WForm(
        key: store.formKey,
        initialValues: store.modifyForm,
        onChanged: () => store.formChange(),
        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: TextFormField(
                  readOnly: true,
                  initialValue: '${data.applyMan ?? ''}',
                ),
              ),
              WFormTile(
                required: true,
                minWidth: 120.pt,
                leading: Text('通行门禁组'),
                child: WMultiplePickerFormField.textField(
                  field: 'doorGroups',
                  title: Text('选择通行门禁组'),
                  buildName: (List<DoorGroupModel>? e) =>
                      e?.map((e) => e.selectName).toList().join('，') ?? '',
                  getData: () => store.getAuditList(),
                  decoration: InputDecoration(hintText: '选择通行门禁组，可多选'),
                  maxLines: null,
                ),
              ),

              ///关联租户(如果已存在住户，那么不可编辑)
              if (store.data!.residentId?.isEmpty == true)
                WFormTile(
                  minWidth: 120.pt,
                  leading: Text('与申请人关系'),
                  child: TextFormField(
                    readOnly: true,
                    initialValue: store.relationMap[data.relation] ?? '',
                  ),
                ),
              if (data.openDoorWay == 'scanCard')
                WFormTile(
                  minWidth: 120.pt,
                  leading: Text('卡号'),
                  child: TextFormField(
                    readOnly: true,
                    initialValue: data.doorCards?.join('，') ?? '',
                  ),
                ),

              ///关联租户(如果已存在住户，那么不可编辑)
              if (store.data!.residentId?.isEmpty ?? true)
                WFormTile(
                  minWidth: 120.pt,
                  leading: Text('关联住户'),
                  child: WSinglePickerFormField.textField(
                    field: 'resident',
                    title: Text('关联住户'),
                    getData: () => store.getOwnerData(),
                    decoration: InputDecoration(hintText: '选择关联住户'),
                  ),
                )
              else
                WFormTile(
                  required: true,
                  minWidth: 120.pt,
                  leading: Text('关联住户'),
                  child: TextFormField(
                    readOnly: true,
                    initialValue: [
                      data.buildName,
                      data.unitName,
                      data.houseInfo,
                      data.residentName
                    ].where((e) => e != null && e != '').toList().join(','),
                    maxLines: null,
                  ),
                ),
              WFormTile(
                minWidth: 120.pt,
                leading: Text('失效日期'),
                child: WDatePickerFormField.textField(
                  field: 'expirationTime',
                  title: Text('失效日期'),
                  firstDate: DateTime.now(),
                  lastDate: DateTime(2099),
                  buildName: (d) => d?.toFormat(WisDateTimeFormat.date) ?? '',
                  decoration: InputDecoration(hintText: '请选择日期（选填）'),
                ),
              ),
            ],
          ).toList(),
        ),
      ),
    );
  }
}
