EditOrgModal.jsx 1.88 KB
Newer Older
1 2
import React, { useEffect } from 'react';
import { Modal, Form, Input, notification, message } from 'antd';
邓超's avatar
邓超 committed
3
import { editOrgInfo } from '@/services/userManage/api';
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

const EditOrgModal = props => {
  const {
    title,
    visible,
    orgID,
    orgTitle,
    description,
    onCancel,
    updateTrees,
    onSelect,
  } = props;
  const [editOrgForm] = Form.useForm(); // 添加用户

  useEffect(() => {
    editOrgForm.setFieldsValue({
      OUName: orgTitle,
      description,
    });
  }, [orgTitle, description]);

  // 提交-编辑当前机构
  const submitEditOrg = () =>
    editOrgInfo(
皮倩雯's avatar
皮倩雯 committed
28
      orgID.id,
29 30 31 32 33
      editOrgForm.getFieldValue('OUName'),
      editOrgForm.getFieldValue('description') || '',
      '',
    )
      .then(res => {
皮倩雯's avatar
皮倩雯 committed
34
        if (res.code === 0) {
35 36 37 38 39 40 41 42 43 44 45 46
          onCancel();
          notification.success({
            message: '提交成功',
            duration: 2,
          });
          // 重新获取机构树与用户表
          updateTrees();
          onSelect([orgID]);
          // setExpandedKeys([`${orgID}`]);
        } else {
          notification.error({
            message: '提交失败',
皮倩雯's avatar
皮倩雯 committed
47
            description: res.msg,
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
          });
        }
      })
      .catch(err => {
        message.error(err);
      });
  return (
    <Modal
      title={title}
      visible={visible}
      onCancel={onCancel}
      onOk={submitEditOrg}
      okText="确认"
      cancelText="取消"
    >
      <Form form={editOrgForm} labelCol={{ span: 4 }}>
        <Form.Item
          name="OUName"
          label="机构名称"
          rules={[{ required: true, message: '不能为空' }]}
        >
          <Input placeholder="请输入机构名称" />
        </Form.Item>
        <Form.Item name="description" label="描述">
          <Input placeholder="请输入相关描述" />
        </Form.Item>
      </Form>
    </Modal>
  );
};

export default EditOrgModal;