/* eslint-disable no-underscore-dangle */
import React, { useEffect } from 'react';

import { Form, Modal, Input, TimePicker, message, Radio, DatePicker } from 'antd';
import moment from 'moment';
import { AddFlowHoliday } from '@/services/holidays/holidays';
const { RangePicker } = DatePicker;
const AddModal = props => {
  const { onSubumit, handleCancel, visible, msg } = props;
  const [form] = Form.useForm();
  useEffect(() => {
    form.resetFields();
    if (visible) {
      getFormData();
    }
  }, [visible]);
  // 获取表单回显
  const getFormData = () => {
    console.log(msg, 'msg');
    // form.setFieldsValue({
    //   workTime: [moment(msg.from, 'HH:mm:ss'), moment(msg.to, 'HH:mm:ss')],
    // });
  };

  // 提交表单
  const onFinish = () => {
    form.validateFields().then(validate => {
      if (validate) {
        AddFlowHoliday({
          dayName: validate.dayName,
          startDate: validate.dayTime[0].format('YYYY-MM-DD'),
          endDate: validate.dayTime[1].format('YYYY-MM-DD'),
          dayType: 1,
        }).then(res => {
          if (res.code === 0) {
            message.success('新增成功');
            onSubumit();
          }
        });
      }
    });
  };
  return (
    <Modal
      title="新增节假日管理"
      visible={visible}
      onOk={onFinish}
      onCancel={handleCancel}
      maskClosable={false}
      destroyOnClose
    >
      <Form
        form={form}
        labelCol={{ span: 5 }}
        wrapperCol={{ span: 18 }}
        initialValues={{ remember: true }}
      >
        <Form.Item
          label="假期名称"
          name="dayName"
          rules={[{ required: true, message: '请填写节假日名称' }]}
        >
          <Input placeholder="请输入假日名称" />
        </Form.Item>

        {/* <Form.Item label="节假日类型" name="dayType" initialValue={1}>
          <Radio.Group>
            <Radio value={1}>休息</Radio>
            <Radio value={3}>法定</Radio>
          </Radio.Group>
        </Form.Item> */}
        <Form.Item
          label="假期时间"
          name="dayTime"
          rules={[{ required: true, message: '请选择假期时间' }]}
        >
          <RangePicker />
        </Form.Item>
      </Form>
    </Modal>
  );
};
export default AddModal;