/*
 * @Description:
 * @Author: leizhe
 * @Date: 2022-04-07 10:23:26
 * @LastEditTime: 2022-05-20 14:19:53
 * @LastEditors: leizhe
 */
import React, { useEffect } from 'react';
import { Modal, Form, Input, notification, message } from 'antd';
import { Save } from '@/services/drawBoardManage/api';

const AddModal = props => {
  const { visible, onCancel, callBackSubmit = () => {} } = props;
  const [addForm] = Form.useForm();

  useEffect(() => {
    addForm.resetFields();
  }, [visible]);

  const submitAdd = () => {
    console.log(addForm.getFieldValue().name);
    if (addForm.getFieldValue().name) {
      Save({ modelTypeName: addForm.getFieldValue().name })
        .then(res => {
          if (res.code === 0) {
            callBackSubmit(addForm.getFieldValue('name'));
            onCancel();
            notification.success({
              message: '提交成功',
              duration: 2,
            });
            // 重新获取机构树与用户表
          } else {
            notification.error({
              message: '提交失败',
              description: res.msg,
            });
          }
        })
        .catch(err => {
          message.error(err);
        });
    } else {
      notification.warning({
        message: '模板类型名称不能为空',
        duration: 2,
      });
    }
  };
  return (
    <Modal
      title="新增模型类型"
      visible={visible}
      onCancel={onCancel}
      destroyOnClose
      onOk={submitAdd}
      afterClose={() => {
        addForm.resetFields();
      }}
      maskClosable={false}
      okText="确认"
      cancelText="取消"
    >
      <Form form={addForm} labelCol={{ span: 6 }}>
        <Form.Item
          name="name"
          label="模板类型名称"
          rules={[{ required: true, message: '不能为空' }]}
        >
          <Input placeholder="请输入模板类型名称" maxLength="20" style={{ width: '330px' }} />
        </Form.Item>
        {/* <Form.Item name="creator" label="登录人名称">
          <Input placeholder="" maxLength="20" style={{ width: '330px' }} disabled />
        </Form.Item> */}
      </Form>
    </Modal>
  );
};
export default AddModal;
