import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../utils/dialog_utils.dart';
import '../../utils/dict_utils.dart';
import 'immune_batch_logic.dart';

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

  final logic = Get.find<ImmuneBatchLogic>();
  final state = Get.find<ImmuneBatchLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('免疫记录',
          style: TextStyle(
            color: Colors.white,
          ),),
        backgroundColor: Colors.blue,
        centerTitle: true,
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: <Widget>[
          Expanded(
            child: GetBuilder<ImmuneBatchLogic>(builder: (logic) {
              return ListView(
                children: [
                  Padding(
                    padding: const EdgeInsets.all(2.0),
                    child: Row(
                      children: [
                        const SizedBox(
                          width: 10,
                        ),
                        getItemView(
                            '圈舍号',
                            state.circleNo ?? '',
                            () async => {
                                  DialogUtils.showSingleListDialog(await DictUtils.getDictList('zxgl_circle_list'),
                                      onPositive: (selectReslut) => {
                                            state.circleNo = selectReslut.key,
                                            state.entity.value.circleNo = selectReslut.value,
                                            logic.update(),
                                          }),
                                }),
                        getItemView(
                          '免疫日期',
                          state.entity.value.immuneDate ?? '',
                          () => {
                            DialogUtils.showTimeDialog(
                              context,
                              isTime: false,
                              title: '请选择免疫日期',
                              onPositive: (date) => {
                                state.entity.value.immuneDate = date,
                                logic.update(),
                              },
                            ),
                          },
                        ),
                        const SizedBox(
                          width: 10,
                        ),
                      ],
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.all(2.0),
                    child: Row(
                      children: [
                        const SizedBox(
                          width: 10,
                        ),
                        getItemView(
                            '免疫有效期',
                            state.entity.value.immuneExp ?? '',
                            () async => {
                                  DialogUtils.showInputDialog(
                                      hintText: '输入免疫有效期',
                                      isNum: true,
                                      onPositive: (text) => {
                                            state.entity.value.immuneExp = text,
                                            logic.update(),
                                          }),
                                }),
                        getItemView(
                            '免疫人员',
                            state.entity.value.immunePerson ?? '',
                            () => {
                                  DialogUtils.showInputDialog(
                                      hintText: '输入免疫人员',
                                      onPositive: (text) => {
                                            state.entity.value.immunePerson = text,
                                            logic.update(),
                                          }),
                                }),
                        const SizedBox(
                          width: 10,
                        ),
                      ],
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.all(2.0),
                    child: Row(
                      children: [
                        const SizedBox(
                          width: 10,
                        ),
                        getItemView(
                            '围药期',
                            state.entity.value.perinatalPeriod ?? '',
                            () async => {
                                  DialogUtils.showInputDialog(
                                      hintText: '输入围药期',
                                      isNum: true,
                                      onPositive: (text) => {
                                            state.entity.value.perinatalPeriod = text,
                                            logic.update(),
                                          }),
                                }),
                        getItemView(
                            '疫苗名称',
                            state.entity.value.vaccineName ?? '',
                            () => {
                                  DialogUtils.showInputDialog(
                                      hintText: '输入疫苗名称',
                                      onPositive: (text) => {
                                            state.entity.value.vaccineName = text,
                                            logic.update(),
                                          }),
                                }),
                        const SizedBox(
                          width: 10,
                        ),
                      ],
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.all(2.0),
                    child: Row(
                      children: [
                        const SizedBox(
                          width: 10,
                        ),
                        getItemView(
                            '疫苗批号',
                            (state.entity.value.lotnumber ?? '').toString(),
                            () async => {
                                  DialogUtils.showInputDialog(
                                      hintText: '输入疫苗批号',
                                      onPositive: (text) => {
                                            state.entity.value.lotnumber = text,
                                            logic.update(),
                                          }),
                                }),
                        getItemView(
                            '生产厂家',
                            state.entity.value.manufacturer ?? '',
                            () => {
                                  DialogUtils.showInputDialog(
                                      hintText: '输入生产厂家',
                                      onPositive: (text) => {
                                            state.entity.value.manufacturer = text,
                                            logic.update(),
                                          }),
                                }),
                        const SizedBox(
                          width: 10,
                        ),
                      ],
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.all(2.0),
                    child: Row(
                      children: [
                        const SizedBox(
                          width: 10,
                        ),
                        getItemView(
                            '规格',
                            state.entity.value.specifications ?? '',
                            () async => {
                                  DialogUtils.showInputDialog(
                                      hintText: '输入规格',
                                      isNum: true,
                                      onPositive: (text) => {
                                            state.entity.value.specifications = text,
                                            logic.update(),
                                          }),
                                }),
                        getItemView(
                            '免疫剂量',
                            state.entity.value.immuneDosage ?? '',
                            () => {
                                  DialogUtils.showInputDialog(
                                      hintText: '输入免疫剂量',
                                      isNum: true,
                                      onPositive: (text) => {
                                            state.entity.value.immuneDosage = text,
                                            logic.update(),
                                          }),
                                }),
                        const SizedBox(
                          width: 10,
                        ),
                      ],
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.all(2.0),
                    child: Row(
                      children: [
                        const SizedBox(
                          width: 10,
                        ),
                        getItemView(
                            '免疫方法',
                            (state.immuneMethod ?? '').toString(),
                                () async => {
                                  DialogUtils.showSingleListDialog(
                                      await DictUtils.getDictList('zxgl_immunebatch_immuneMethod'),
                                      onPositive: (selectReslut) => {
                                        state.immuneMethod = selectReslut.key,
                                        state.entity.value.immuneMethod = selectReslut.value,
                                        logic.update(),
                                      }),
                            }),
                        getItemView(
                            '备注',
                            state.entity.value.remark ?? '',
                            () => {
                                  DialogUtils.showInputDialog(
                                      hintText: '输入备注',
                                      onPositive: (text) => {
                                            state.entity.value.remark = text,
                                            logic.update(),
                                          }),
                                }),
                        const SizedBox(
                          width: 10,
                        ),
                      ],
                    ),
                  ),
                ],
              );
            }),
          ),
          // Row(children: [
          //   Expanded(
          //     child:
          TextButton(
            style: ButtonStyle(
              backgroundColor: MaterialStateProperty.all(Colors.blue),
              foregroundColor: MaterialStateProperty.all(Colors.white),
              padding: MaterialStateProperty.all(const EdgeInsets.all(10)),
            ),
            onPressed: () => {
              logic.save(),
            },
            child: const Text("保存"),
          ),
          //   ),
          // ]),
        ],
      ),
    );
  }

  getItemView(String title, String context, Function() onClick) {
    return Expanded(
      child: Container(
          decoration: const BoxDecoration(
            color: Colors.white,
            boxShadow: [
              BoxShadow(
                color: Colors.black12,
                blurRadius: 2,
              ),
            ],
          ),
          padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
          child: InkWell(
            onTap: onClick,
            child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  const SizedBox(
                    height: 10,
                  ),
                  Text(
                    title,
                    style: const TextStyle(
                      color: Colors.blue,
                      fontSize: 14,
                    ),
                  ),
                  const SizedBox(
                    height: 10,
                  ),
                  SizedBox(
                    height: 1,
                    child: Container(
                      color: Colors.black12,
                      height: 1,
                    ),
                  ),
                  const SizedBox(
                    height: 10,
                  ),
                  Text(
                    context,
                    style: const TextStyle(
                      height: 1.5,
                      color: Colors.black,
                      fontSize: 14,
                    ),
                  ),
                  const SizedBox(
                    height: 10,
                  ),
                ],
              ),
          ),
          ),
    );
  }
}
