/*
 * @Description:
 * @Author: leizhe
 * @Date: 2022-01-13 17:26:14
 * @LastEditTime: 2022-04-27 11:24:57
 * @LastEditors: leizhe
 */
import React from 'react';
import { Modal, notification, message } from 'antd';
import { deleteOrg } from '@/services/userManage/api';
import { Margin } from 'gojs';

const DeleteOrgModal = props => {
  const { title, visible, orgID, onCancel, updateTrees, orgTitle } = props;

  // 提交-删除机构
  const submitDeleteOrg = () =>
    deleteOrg(orgID.id)
      .then(res => {
        if (res.msg === '') {
          onCancel();
          notification.success({
            message: '提交成功',
            duration: 2,
          });
          // 重新获取机构树与用户表
          updateTrees();
        } else {
          notification.error({
            message: '提交失败',
            description: res.msg,
          });
        }
      })
      .catch(err => {
        message.error(err);
      });
  return (
    <Modal
      title={title}
      visible={visible}
      onCancel={onCancel}
      maskClosable={false}
      onOk={submitDeleteOrg}
      okText="确认"
      cancelText="取消"
    >
      <p style={{ marginLeft: '17px' }}>
        即将删除<span style={{ color: 'red' }}>{orgTitle}</span>，是否确认删除？
      </p>
    </Modal>
  );
};

export default DeleteOrgModal;
