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

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

  useEffect(() => {
    addForm.setFieldsValue({ name: changeObj.name });
  }, [visible]);

  const submitEdit = () => {
    console.log(changeObj);
    console.log(addForm.getFieldValue('name'));
    if (addForm.getFieldValue('name')) {
      UpdateModelType({ modelTypeName: addForm.getFieldValue('name'), id: changeObj.ID })
        .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={submitEdit}
      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 EditModal;