/*
 * @Author: XianKaiQun
 * @Date: 2020-07-30 09:18:54
 * @LastEditors: XianKaiQun
 * @LastEditTime: 2020-09-07 17:20:49
 * @Description: 
 */
part of '../index.dart';

class _FormComponent extends StatelessWidget {
  const _FormComponent({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    final PrivateRepairMaintainStore store = Provider.of(context);
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;
    final theme = Theme.of(context);
    final textTheme = theme.textTheme;

    return WisCard(
      isSliver: true,
      margin: EdgeInsets.all(15.pt),
      padding: EdgeInsets.all(15.pt),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: <Widget>[
          Text(
            '维修前照片',
            style: textTheme.titleMedium,
          ),
          SizedBox(height: 15.pt),
          Wrap(
            runSpacing: 10.pt,
            spacing: 10.pt,
            children: <Widget>[
              for (var i = 0; i < store.beforeImages.length; i++)
                Wisdom.stack(
                  onTap: () => WisPhotoViewUtil.show(
                      store.beforeImages
                          .map(
                            (e) => CachedNetworkImageProvider(
                              AppParseUtil.image(e),
                            ),
                          )
                          .toList(),
                      i),
                  color: colorScheme.background,
                  children: <Widget>[
                    WImage.network(
                      AppParseUtil.image(store.beforeImages[i]),
                      fit: BoxFit.cover,
                      width: 98.pt,
                      height: 98.pt,
                    ),
                    Positioned(
                      top: 4.pt,
                      right: 4.pt,
                      child: Wisdom(
                        onTap: () => store.removeBeforeImage(i),
                        color: Colors.black54,
                        borderRadius: BorderRadius.circular(50),
                        child: Icon(
                          Icons.close,
                          color: Colors.white,
                          size: 15.pt,
                        ),
                      ),
                    ),
                  ],
                ),
              if (store.beforeImages.length < 6)
                WLoadingWrapper(
                  action: () => store.onBeforeImagePicker(),
                  builder: (context, action, child) {
                    return Wisdom(
                      onTap: action,
                      color: colorScheme.background,
                      width: 98.pt,
                      height: 98.pt,
                      alignment: Alignment.center,
                      child: child,
                    );
                  },
                  child: Icon(Icons.camera_alt),
                ),
            ],
          ),
          SizedBox(height: 15.pt),
          Text(
            '异常备注',
            style: textTheme.titleMedium,
          ),
          TextFormField(
            onChanged: (v) => store.onInputChange(v),
            minLines: 4,
            maxLines: 4,
            maxLength: 200,
            decoration: InputDecoration(
              hintText: '请输入描述',
            ),
          ).asPaddingSymmetric(vertical: 15.pt),
          Text(
            '维修后照片',
            style: textTheme.titleMedium,
          ),
          SizedBox(height: 15.pt),
          Wrap(
            runSpacing: 10.pt,
            spacing: 10.pt,
            children: <Widget>[
              for (var i = 0; i < store.afterImages.length; i++)
                Wisdom.stack(
                  onTap: () => WisPhotoViewUtil.show(
                      store.afterImages
                          .map(
                            (e) => CachedNetworkImageProvider(
                              AppParseUtil.image(e),
                            ),
                          )
                          .toList(),
                      i),
                  color: colorScheme.background,
                  children: <Widget>[
                    WImage.network(
                      AppParseUtil.image(store.afterImages[i]),
                      fit: BoxFit.cover,
                      width: 98.pt,
                      height: 98.pt,
                    ),
                    Positioned(
                      top: 4.pt,
                      right: 4.pt,
                      child: Wisdom(
                        onTap: () => store.removeAfterImage(i),
                        color: Colors.black54,
                        borderRadius: BorderRadius.circular(50),
                        child: Icon(
                          Icons.close,
                          color: Colors.white,
                          size: 15.pt,
                        ),
                      ),
                    ),
                  ],
                ),
              if (store.afterImages.length < 6)
                WLoadingWrapper(
                  action: () => store.onAfterImagePicker(),
                  builder: (context, action, child) {
                    return Wisdom(
                      onTap: action,
                      color: colorScheme.background,
                      width: 98.pt,
                      height: 98.pt,
                      alignment: Alignment.center,
                      child: child,
                    );
                  },
                  child: Icon(Icons.camera_alt),
                ),
            ],
          ),
        ],
      ),
    );
  }
}
