EditOrgModal.jsx 2.34 KB
Newer Older
1
/* eslint-disable import/no-unresolved */
2 3 4 5
/*
 * @Description:
 * @Author: leizhe
 * @Date: 2022-01-13 17:26:14
6
 * @LastEditTime: 2022-04-27 18:56:09
7 8
 * @LastEditors: leizhe
 */
9
import React, { useEffect, useState } from 'react';
10
import { Modal, Form, Input, notification, message } from 'antd';
邓超's avatar
邓超 committed
11
import { editOrgInfo } from '@/services/userManage/api';
12 13

const EditOrgModal = props => {
14
  const { visible, orgID, description, onCancel, updateTrees, onSelect, orgTitle1 } = props;
15
  const [editOrgForm] = Form.useForm(); // 添加用户
16
  const { Item } = Form;
17
  useEffect(() => {
18
    console.log(orgTitle1);
19 20
    console.log(orgID);
    if (visible && orgID) {
皮倩雯's avatar
皮倩雯 committed
21
      editOrgForm.setFieldsValue({ OUName: orgID.text, description: orgID.describe });
22
    }
23
  }, [visible]);
24 25 26 27

  // 提交-编辑当前机构
  const submitEditOrg = () =>
    editOrgInfo(
皮倩雯's avatar
皮倩雯 committed
28
      orgID.id,
皮倩雯's avatar
皮倩雯 committed
29 30
      editOrgForm.getFieldsValue().OUName,
      editOrgForm.getFieldsValue().description,
31 32
    )
      .then(res => {
皮倩雯's avatar
皮倩雯 committed
33
        if (res.code === 0) {
34 35 36 37 38 39 40
          onCancel();
          notification.success({
            message: '提交成功',
            duration: 2,
          });
          // 重新获取机构树与用户表
          updateTrees();
41
          // onSelect([orgID]);
42 43 44 45
          // setExpandedKeys([`${orgID}`]);
        } else {
          notification.error({
            message: '提交失败',
皮倩雯's avatar
皮倩雯 committed
46
            description: res.msg,
47 48 49 50 51 52
          });
        }
      })
      .catch(err => {
        message.error(err);
      });
53 54
  const title = (
    <span>
55
      编辑<span style={{ fontWeight: 'bold', color: '#1890ff' }}>{orgTitle1}</span>信息
56 57
    </span>
  );
58 59 60 61 62
  return (
    <Modal
      title={title}
      visible={visible}
      onCancel={onCancel}
63 64
      maskClosable={false}
      destroyOnClose
65 66 67
      // afterClose={() => {
      //   editOrgForm.resetFields();
      // }}
68 69 70 71 72
      onOk={submitEditOrg}
      okText="确认"
      cancelText="取消"
    >
      <Form form={editOrgForm} labelCol={{ span: 4 }}>
73
        <Item name="OUName" label="机构名称" rules={[{ required: true, message: '不能为空' }]}>
74
          <Input placeholder="请输入机构名称" maxLength="20" />
75 76
        </Item>
        <Item name="description" label="描述">
77
          <Input placeholder="请输入相关描述" maxLength="100" />
78
        </Item>
79 80 81 82 83 84
      </Form>
    </Modal>
  );
};

export default EditOrgModal;