/*
 * @Author: XianKaiQun
 * @Date: 2020-08-04 11:28:48
 * @LastEditors  : WuWei
 * @LastEditTime : 2023-05-11 14:57:32
 * @Description: 
 */
part of '../index.dart';

///巡检、养护时展示
class _RepairComponent extends StatelessWidget {
  const _RepairComponent({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    final store = Provider.of<PrivateRepairDetailItemStore>(context);
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;

    final theme = Theme.of(context);
    final textTheme = theme.textTheme;
    final data = store.data;
    if (data?.pollingAndUpkeepRecoredVo?.name == null) {
      return SliverToBoxAdapter();
    }
    final PollingAndUpkeepRecoredVoOfRepairEquipmentRecordModel vo =
        data!.pollingAndUpkeepRecoredVo!;

    final opreateRecordVo = vo.opreateRecordVo ?? [];
    final list = [
      {
        'name': '操作时间',
        'val': data.createdAt,
      },
      {
        'name': '操作员',
        'val': data.createdBy,
      },
      {
        'name': '规范名称',
        'val': vo.name ?? '',
      },
      {
        'name': '周期',
        'val': vo.cycleName ?? '',
      }
    ];

    return Wisdom.column(
      padding: EdgeInsets.symmetric(horizontal: 15.pt),
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: <Widget>[
        Divider(),
        SizedBox(height: 15.pt),
        Padding(
          padding: EdgeInsets.symmetric(horizontal: 15.pt),
          child: Text(
            '操作内容',
            style: textTheme.titleSmall!.copyWith(
              fontWeight: FontWeight.bold,
            ),
          ),
        ),
        for (var item in list)
          Wisdom.row(
            padding: EdgeInsets.symmetric(vertical: 5.pt, horizontal: 15.pt),
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Text('${item['name']}'),
              Text('${item['val'] ?? '--'}'),
            ],
          ),
        WisCard(
          padding: EdgeInsets.all(15.pt),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: <Widget>[
              for (var item in opreateRecordVo) ...[
                Padding(
                  padding: EdgeInsets.symmetric(vertical: 15.pt),
                  child: Text(
                    '${item.opreateName}',
                    style: textTheme.titleSmall!
                        .copyWith(fontWeight: FontWeight.bold),
                  ),
                ),
                if (item.type == 'text')
                  Wisdom(
                    padding: EdgeInsets.all(10.pt),
                    color: colorScheme.background,
                    minHeight: 100.pt,
                    child: Text(
                      '${item.opreateContent![0].opreateContent}',
                    ),
                  )
                else if (item.type == 'radio')
                  ...ListTile.divideTiles(
                    context: context,
                    tiles: [
                      for (var child in item.opreateContent!)
                        ListTile(
                          dense: true,
                          leading: Icon(
                            child.status == "1"
                                ? Icons.radio_button_checked
                                : Icons.radio_button_unchecked,
                            color: child.status == "1"
                                ? colorScheme.primary
                                : null,
                          ),
                          title: Text(child.opreateContent ?? ''),
                        ),
                    ],
                  ).toList()

                ///多选

                else if (item.type == 'checkbox')
                  ...ListTile.divideTiles(
                    context: context,
                    tiles: [
                      for (var child in item.opreateContent!)
                        ListTile(
                          dense: true,
                          leading: Icon(
                            child.status == "1"
                                ? Icons.check_box
                                : Icons.check_box_outline_blank,
                            color: child.status == "1"
                                ? colorScheme.primary
                                : null,
                          ),
                          title: Text(child.opreateContent ?? ''),
                        ),
                    ],
                  ).toList()

                ///图片
                else if (item.type == 'img')
                  () {
                    final urls = item.opreateContent!
                        .map((e) => AppParseUtil.image(e.opreateContent!))
                        .toList();

                    final imageproviders =
                        urls.map((e) => CachedNetworkImageProvider(e)).toList();
                    return Wrap(
                      spacing: 10.pt,
                      runSpacing: 10.pt,
                      children: <Widget>[
                        for (var i = 0; i < urls.length; i++)
                          Wisdom(
                            onTap: () =>
                                WisPhotoViewUtil.show(imageproviders, i),
                            width: 98.pt,
                            height: 98.pt,
                            color: colorScheme.background,
                            border: Border.all(color: colorScheme.divider),
                            child: WImage(
                                image: imageproviders[i], fit: BoxFit.cover),
                          ),
                      ],
                    );
                  }(),
              ],
            ],
          ),
        ),
      ],
    ).asSliver();
  }
}
