/*
 * @Author: XianKaiQun
 * @Date: 2020-09-03 11:32:39
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2023-03-27 16:03:38
 * @Description: 
 */
part of '../index.dart';

class _FaceListComponent extends StatelessWidget {
  const _FaceListComponent({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    final store = Provider.of<PrivateIndexStore>(context);
    final list = store.faceList;
    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,
    };
    return Column(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      mainAxisSize: MainAxisSize.min,
      children: <Widget>[
        Wisdom.row(
          color: Colors.white,
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          margin: EdgeInsets.only(bottom: 10.pt),
          children: <Widget>[
            /// 输入框
            Expanded(
              child: WSearch(
                hintText: '输入手机号或房屋号搜索',
                onSubmitted: (v) => store.onSearch(v),
                onCancel: () => store.onSearch(''),
                moonlight: false,
                padding: EdgeInsets.symmetric(vertical: 10.pt),
                isDark: true,
              ),
            ),
          ],
        ),
        WisScrollView(
            key: store.scorllViewListKey,
            onInit: () => store.getFaceList(isLoad: false),
            onRefresh: () => store.getFaceList(isLoad: false),
            onLoad: () => store.getFaceList(isLoad: true),
            slivers: <Widget>[
              WisSliverList.childBuilder(
                childCount: list.length,
                builder: (context, index) {
                  final item = list[index];
                  return WisCard(
                    color: Colors.white,
                    margin: EdgeInsets.only(
                        left: 15.pt, right: 15.pt, bottom: 10.pt),
                    elevation: 0,
                    child: Wisdom.row(
                      onTap: () => store.route2detail(item.id),
                      crossAxisAlignment: CrossAxisAlignment.start,
                      color: Colors.white,
                      padding: EdgeInsets.all(15.pt),
                      children: [
                        ///头像
                        if (item.openDoorWay == 'scanCard')
                          WImage(
                            image: AssetList.$card_png_image,
                            borderRadius: BorderRadius.circular(4.pt),
                            width: 80.pt,
                            height: 80.pt,
                          )
                        else
                          WImage.network(
                            AppParseUtil.image(item.photo!),
                            borderRadius: BorderRadius.circular(4.pt),
                            width: 80.pt,
                            height: 80.pt,
                            fit: BoxFit.cover,
                          ),
                        SizedBox(width: 15.pt),
                        Column(
                          mainAxisAlignment: MainAxisAlignment.spaceAround,
                          crossAxisAlignment: CrossAxisAlignment.stretch,
                          children: [
                            Row(
                              children: [
                                ///名
                                Text(
                                  item.residentName!,
                                  style: TextStyle(
                                    fontWeight: FontWeight.bold,
                                    color: colorScheme.primary,
                                    fontSize: 15.pt,
                                  ),
                                ),

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

                                ///添加时间
                                Text(
                                  item.applyTime!,
                                  style: TextStyle(
                                    color: colorScheme.grey,
                                    fontSize: 11.pt,
                                  ),
                                ),
                              ],
                            ),
                            SizedBox(height: 10.pt),

                            ///电话
                            Text(item.mobile!),
                            SizedBox(height: 10.pt),

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