/*
 * @Author: XianKaiQun
 * @Date: 2020-08-04 11:29:12
 * @LastEditors  : WuWei
 * @LastEditTime : 2023-05-11 14:58:41
 * @Description: 
 */
part of '../index.dart';

// 维修时展示
class _MaintainComponent extends StatelessWidget {
  const _MaintainComponent({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?.equipmentServiceRecordVo?.content == null) {
      return SliverToBoxAdapter();
    }
    final EquipmentServiceRecordVoOfRepairEquipmentRecordModel vo =
        data!.equipmentServiceRecordVo!;
    final beforeImgs = vo.beforeImg ?? [];

    final beforeUrls = beforeImgs.map((e) => AppParseUtil.image(e)).toList();
    final beforeImages =
        beforeUrls.map((e) => CachedNetworkImageProvider(e)).toList();

    final afterImgs = vo.afterImg ?? [];
    final afterUrls = afterImgs.map((e) => AppParseUtil.image(e)).toList();
    final afterImages =
        afterUrls.map((e) => CachedNetworkImageProvider(e)).toList();

    final list = [
      {
        'name': '操作时间',
        'val': data.createdAt,
      },
      {
        'name': '操作员',
        'val': data.createdBy,
      }
    ];
    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>[
              Text(
                '维修前照片',
                style: textTheme.titleSmall,
              ),
              SizedBox(height: 15.pt),
              Wrap(
                spacing: 10.pt,
                runSpacing: 10.pt,
                children: <Widget>[
                  for (var i = 0; i < beforeImages.length; i++)
                    Wisdom(
                      onTap: () => WisPhotoViewUtil.show(beforeImages, i),
                      width: 98.pt,
                      height: 98.pt,
                      color: colorScheme.background,
                      border: Border.all(color: colorScheme.divider),
                      child: WImage(
                        image: beforeImages[i],
                        fit: BoxFit.cover,
                      ),
                    ),
                ],
              ),
              SizedBox(height: 15.pt),
              Text(
                '维修内容',
                style: textTheme.titleSmall,
              ),
              Wisdom(
                margin: EdgeInsets.only(top: 10.pt),
                padding: EdgeInsets.all(10.pt),
                color: colorScheme.background,
                minHeight: 100.pt,
                child: Text(
                  '${vo.content}',
                ),
              ),
              SizedBox(height: 15.pt),
              Text(
                '维修后照片',
                style: textTheme.titleSmall,
              ),
              SizedBox(height: 15.pt),
              Wrap(
                spacing: 10.pt,
                runSpacing: 10.pt,
                children: <Widget>[
                  for (var i = 0; i < afterImages.length; i++)
                    Wisdom(
                      onTap: () => WisPhotoViewUtil.show(afterImages, i),
                      width: 98.pt,
                      height: 98.pt,
                      color: colorScheme.background,
                      border: Border.all(color: colorScheme.divider),
                      child: WImage(
                        image: afterImages[i],
                        fit: BoxFit.cover,
                      ),
                    ),
                ],
              ),
            ],
          ),
        ),
      ],
    ).asSliver();
  }
}
