AddSubOrgModal.jsx 2.86 KB
Newer Older
1
/* eslint-disable import/no-unresolved */
2 3
import React, { useEffect } from 'react';
import { Modal, Form, Input, notification, message } from 'antd';
邓超's avatar
邓超 committed
4
import { addOrg } from '@/services/userManage/api';
5 6

const AddUserModal = props => {
7
  const { visible, orgID, onCancel, updateTrees1, onSelect, orgTitle1 } = props;
8 9 10
  const [addOrgForm] = Form.useForm(); // 添加用户

  useEffect(() => {
11
    console.log(orgID);
12 13 14 15 16
    addOrgForm.resetFields();
  }, [orgID]);

  // 提交-添加下级机构
  const submitAddOrg = () => {
17
    // 顶级机构
18
    if (orgID == -1) {
皮倩雯's avatar
皮倩雯 committed
19
      addOrg(orgID, addOrgForm.getFieldsValue().OUName, addOrgForm.getFieldsValue().description)
20
        .then(res => {
皮倩雯's avatar
皮倩雯 committed
21
          if (res.code === 0) {
22 23 24 25 26 27
            onCancel();
            notification.success({
              message: '提交成功',
              duration: 2,
            });
            // 重新获取机构树与用户表
28 29 30
            console.log(res.data);
            updateTrees1(res.data);
            onSelect([`${res.data}`]);
31 32 33 34 35 36 37 38 39 40
          } else {
            notification.error({
              message: '提交失败',
              description: res.msg,
            });
          }
        })
        .catch(err => {
          message.error(err);
        });
41
    } else {
皮倩雯's avatar
皮倩雯 committed
42
      addOrg(orgID.id, addOrgForm.getFieldsValue().OUName, addOrgForm.getFieldsValue().description)
43
        .then(res => {
皮倩雯's avatar
皮倩雯 committed
44
          if (res.code === 0) {
45 46 47 48 49 50
            onCancel();
            notification.success({
              message: '提交成功',
              duration: 2,
            });
            // 重新获取机构树与用户表
51 52 53
            console.log(res.data);
            updateTrees1(res.data);
            onSelect([`${res.data}`]);
54 55 56 57 58 59 60 61 62 63 64
          } else {
            notification.error({
              message: '提交失败',
              description: res.msg,
            });
          }
        })
        .catch(err => {
          message.error(err);
        });
    }
65
  };
66 67
  const title = (
    <span>
68 69
<span style={{ fontWeight: 'bold', color: 'rgb(24, 144, 255)' }}>{orgTitle1}</span>
      下添加机构
70 71
    </span>
  );
72 73
  return (
    <Modal
74
      title={orgID === '-1' ? '添加顶级机构' : title}
75 76 77
      visible={visible}
      onCancel={onCancel}
      onOk={submitAddOrg}
78 79 80 81 82
      destroyOnClose
      afterClose={() => {
        addOrgForm.resetFields();
      }}
      maskClosable={false}
83 84 85 86
      okText="确认"
      cancelText="取消"
    >
      <Form form={addOrgForm} labelCol={{ span: 4 }}>
87
        <Form.Item name="OUName" label="机构名称" rules={[{ required: true, message: '不能为空' }]}>
88
          <Input placeholder="请输入机构名称" maxLength="20" />
89 90
        </Form.Item>
        <Form.Item name="description" label="描述">
91
          <Input placeholder="请输入相关描述" maxLength="100" />
92 93 94 95 96 97 98
        </Form.Item>
      </Form>
    </Modal>
  );
};

export default AddUserModal;