/*
 * @Author       : WuWei
 * @LastEditors: wjc
 * @Date         : 2021-09-26 18:41:44
 * @LastEditTime: 2023-01-18 16:42:34
 * @Description  : Do not edit
 */
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:task_package/src/view_models/repair_form_store.dart';
import 'package:wisdom_cli/wisdom_cli.dart';
part 'index.g.dart';

///路由传递的参数
class RepairFormPageArguments {
  final String? id;
  final dynamic detail;
  RepairFormPageArguments({
    this.id,
    this.detail,
  });

  ///
  ///
  ///
  ///
  ///
  ///
  ///
//***以下为模板代码谨慎修改***
  factory RepairFormPageArguments.fromJson(Map<String, dynamic> json) {
    return _$RepairFormPageArgumentsFromJson(json);
  }
  factory RepairFormPageArguments.fromRouteArguments(BuildContext context) {
    return _$RepairFormPageArgumentsFromJson(
        (ModalRoute.of(context)?.settings.arguments ??
            new Map<String, dynamic>()) as Map<String, dynamic>);
  }
  Map<String, dynamic> toJson() => _$RepairFormPageArgumentsToJson(this);
}

///
///
///
///
///
//***以下为模板代码谨慎修改***
class RepairFormPage extends StatelessWidget {
  const RepairFormPage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (_) => RepairFormStore(context)),
      ],
      child: RepairFormPageView(),
    );
  }
}

class RepairFormPageView extends StatelessWidget {
  const RepairFormPageView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    final store = Provider.of<RepairFormStore>(context, listen: false);
    return Scaffold(
      appBar: WAppBar(
        brightness: Brightness.light,
        iconTheme: IconThemeData(
          color: colorScheme.mainTitle,
          size: 19.pt,
        ),
        backgroundColor: Colors.white,
        title: WisText('${store.presetName ?? ''}报修',
            size: 19.pt, weight: FontWeight.w600, color: colorScheme.mainTitle),
      ),
      body: WisScrollView(
        onInit: () => store.onInit(),
        slivers: [
          SliverToBoxAdapter(
            child: Observer(builder: (_) {
              return Wisdom.column(
                color: Colors.white,
                margin:
                    EdgeInsets.symmetric(vertical: 10.pt, horizontal: 15.pt),
                padding: EdgeInsets.all(15.pt),
                crossAxisAlignment: CrossAxisAlignment.stretch,
                borderRadius: BorderRadius.circular(10.pt),
                boxShadow: [
                  BoxShadow(
                    offset: Offset(0, 2.pt),
                    color: Color(0x08000000),
                    blurRadius: 10.pt,
                    spreadRadius: 2.5.pt,
                  ),
                ],
                children: [
                  Wisdom(
                    margin: EdgeInsets.only(bottom: 15.pt),
                    child: WisText(
                      '工单处理',
                      color: colorScheme.mainTitle,
                      size: 16.pt,
                      weight: FontWeight.w600,
                    ),
                  ),
                  Observer(builder: (_) {
                    return WFSinglePicker(
                      isRequired: true,
                      title: WisText(
                        '类别',
                        size: 15.pt,
                        color: colorScheme.mainTitle,
                      ),
                      label: 'name',
                      value: 'id',
                      initialValue: store.businessTypeId,
                      dataList: store.typeList,
                      onChanged: (value) => store.setType(value),
                    );
                  }),
                  if (store.sortList.length > 0) ...[
                    Observer(builder: (_) {
                      return WFSinglePicker(
                        isRequired: false,
                        title: WisText(
                          '分类',
                          size: 15.pt,
                          color: colorScheme.mainTitle,
                        ),
                        label: 'sortName',
                        value: 'id',
                        initialValue: store.sortId,
                        dataList: store.sortList,
                        onChanged: (value) => store.setSort(value),
                      );
                    }),
                  ],
                  WFInput(
                    isRequired: true,
                    type: InputType.multiLine,
                    minLines: 4,
                    hintText: "请输入内容",
                    title: WisText('工作内容'),
                    onInput: (v) => store.onInput(v),
                    initialValue: store.description,
                  ),
                  Divider(
                    height: 1.pt,
                    color: colorScheme.divider,
                  ),
                  Observer(builder: (_) {
                    return WFImagePicker(
                      isRequired: true,
                      title: WisText('上传图片'),
                      onSelected: (v) => store.onSelectedImg(v),
                      onDelete: (index) => store.onImageRemoveAt(index),
                      images: store.images,
                      currentCount: store.images.length,
                    );
                  }),
                ],
              );
            }),
          )
        ],
      ),
      bottomSheet: _BuildBottom(),
    );
  }
}

class _BuildBottom extends StatelessWidget {
  const _BuildBottom({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    final store = Provider.of<RepairFormStore>(context, listen: false);

    return Wisdom.row(
        height: 70.pt,
        color: Colors.white,
        padding: EdgeInsets.only(
            left: 15.pt, right: 15.pt, bottom: 18.pt, top: 10.pt),
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          Wisdom.row(
              onTap: () => {store.onHandleRepair()},
              height: 44.pt,
              color: colorScheme.primary,
              padding: EdgeInsets.symmetric(horizontal: 15.pt, vertical: 5.pt),
              mainAxisAlignment: MainAxisAlignment.center,
              borderRadius: BorderRadius.circular(100.pt),
              children: [
                WisText(
                  '提交',
                  color: Colors.white,
                  size: 16.pt,
                  weight: FontWeight.w300,
                ),
              ]).asFlexible(flex: 1),
        ]);
  }
}
