/*
 * @Author: XianKaiQun
 * @Date: 2020-09-04 10:19:04
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2023-03-31 10:23:34
 * @Description: 
 */
part of '../index.dart';

///顶部描述
class _DescComponent extends StatelessWidget {
  const _DescComponent({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;
//final theme = Theme.of(context);
//final textTheme = theme.textTheme;
    ///审核状态颜色
    final statusColorMap = {
      // 1: '待审核',
      1: colorScheme.warning,
      // 2: '待下发',
      2: colorScheme.orange,
      // 3: '已通过',
      3: colorScheme.success,
      // 4: '禁止通行',
      4: colorScheme.danger,
      // 5: '被拒绝',
      5: colorScheme.danger,
      // 6: '已失效',
      6: colorScheme.grey,
    };
    final store = Provider.of<PrivateDetailStore>(context, listen: true);
    final data = store.data;

    ///人脸(编辑模式下  应该要显示表单内待修改的人脸图片)
    final imageProvider = CachedNetworkImageProvider(
      AppParseUtil.image(
          store.isEdit == true ? store.imageId ?? '' : data?.photo ?? ''),
    );

    return WisCard(
      isSliver: true,
      color: Colors.white,
      margin: EdgeInsets.fromLTRB(15.pt, 10.pt, 15.pt, 5.pt),
      child: Wisdom.row(
        crossAxisAlignment: CrossAxisAlignment.start,
        color: Colors.white,
        padding: EdgeInsets.all(15.pt),
        children: [
          ///头像(刷卡)
          if (data?.openDoorWay == 'scanCard')
            WImage(
              image: AssetList.$card_png_image,
              borderRadius: BorderRadius.circular(4.pt),
              width: 80.pt,
              height: 80.pt,
            )

          ///头像（人脸）
          ///编辑模式下点击选择照片
          ///非编辑模式下点击预览
          else
            Wisdom.stack(
              onTap: () => store.isEdit
                  ? store.facePicker()
                  : WisPhotoViewUtil.show([imageProvider], 0),
              children: [
                WImage(
                  image: imageProvider,
                  borderRadius: BorderRadius.circular(4.pt),
                  width: 80.pt,
                  height: 80.pt,
                  fit: BoxFit.cover,
                ),
                if (store.isEdit == true)
                  Positioned.fill(
                    child: Container(
                      alignment: Alignment.center,
                      color: Colors.black45,
                      child: WImage(
                        image: AssetList.$camera_png_image,
                        width: 18.pt,
                        fit: BoxFit.cover,
                      ),
                    ),
                  ),
              ],
            ),
          SizedBox(width: 15.pt),
          Column(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              Row(
                children: [
                  ///名
                  Text(
                    '${data?.residentName}',
                    style: TextStyle(
                      fontWeight: FontWeight.bold,
                      color: colorScheme.primary,
                      fontSize: 15.pt,
                    ),
                  ),

                  ///状态
                  if (store.statusMap[data?.status] != null)
                    WTag(
                      margin: EdgeInsets.only(left: 5.pt),
                      child: Text('${store.statusMap[data?.status]}'),
                      color: statusColorMap[data!.status],
                    ),
                  Spacer(),

                  ///添加时间
                  Text(
                    '${data?.applyTime}',
                    style: TextStyle(
                      color: colorScheme.grey,
                      fontSize: 11.pt,
                    ),
                  ),
                ],
              ),
              SizedBox(height: 10.pt),

              ///电话
              Text('${data?.mobile}'),
              SizedBox(height: 10.pt),

              ///房屋
              Text(
                data?.houseInfo ?? '',
                style: TextStyle(
                  color: colorScheme.minor,
                  fontSize: 13.pt,
                ),
              ),
            ],
          ).asExpanded(),
        ],
      ),
    );
  }
}
