EditModal.jsx 2.26 KB
Newer Older
皮倩雯's avatar
皮倩雯 committed
1 2 3 4
/*
 * @Description:
 * @Author: leizhe
 * @Date: 2022-04-07 10:23:26
5
 * @LastEditTime: 2022-05-20 09:30:13
皮倩雯's avatar
皮倩雯 committed
6 7 8 9 10 11 12
 * @LastEditors: leizhe
 */
import React, { useEffect } from 'react';
import { Modal, Form, Input, notification, message } from 'antd';
import { UpdateModelType } from '@/services/drawBoardManage/api';

const EditModal = props => {
13
  const { visible, onCancel, changeObj, callBackSubmit = () => {} } = props;
皮倩雯's avatar
皮倩雯 committed
14 15 16 17 18 19 20
  const [addForm] = Form.useForm();

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

  const submitEdit = () => {
21
    console.log(changeObj);
皮倩雯's avatar
皮倩雯 committed
22 23
    console.log(addForm.getFieldValue('name'));
    if (addForm.getFieldValue('name')) {
24
      UpdateModelType({ modelTypeName: addForm.getFieldValue('name'), id: changeObj.ID })
皮倩雯's avatar
皮倩雯 committed
25 26
        .then(res => {
          if (res.code === 0) {
27
            callBackSubmit(addForm.getFieldValue('name'));
皮倩雯's avatar
皮倩雯 committed
28 29 30 31 32 33 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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
            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;