AddModal.jsx 2.25 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
/* 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'),
邓超's avatar
邓超 committed
33
          dayType: 1,
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
        }).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>

邓超's avatar
邓超 committed
66
        {/* <Form.Item label="节假日类型" name="dayType" initialValue={1}>
67 68 69 70
          <Radio.Group>
            <Radio value={1}>休息</Radio>
            <Radio value={3}>法定</Radio>
          </Radio.Group>
邓超's avatar
邓超 committed
71
        </Form.Item> */}
72 73 74 75 76 77 78 79 80 81 82 83
        <Form.Item
          label="假期时间"
          name="dayTime"
          rules={[{ required: true, message: '请选择假期时间' }]}
        >
          <RangePicker />
        </Form.Item>
      </Form>
    </Modal>
  );
};
export default AddModal;