EditOrgModal.jsx 2.41 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 21 22 23 24
    console.log(orgID);
    if (visible && orgID) {
      console.log(orgID.text);
      editOrgForm.setFieldsValue({ OUName: orgID.text });
      console.log(editOrgForm.getFieldValue('OUName'));
    }
25
  }, [visible]);
26 27 28 29

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

export default EditOrgModal;