import React from 'react';
import { Modal, notification, message } from 'antd';
import { deleteOrg } from '@/services/userCenter/userManage/api';

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

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

export default DeleteOrgModal;