import React, { useState, useEffect } from 'react';
import { Modal, Descriptions } from 'antd';

import { coscoAccessWork } from '../services'


interface Data {
  accessWorkName: string;
  deptId: string;
  accessTypeText: string;
  createTime: string;
  reviewStatusText: string;
}

const ViewModal: React.FC<{
  visible: boolean;
  record?: any;
  onCancel: () => void;
}> = ({ visible, record = {}, onCancel }) => {

  const [data, setData] = useState<Data | null>(null);

  useEffect(() => {
    if(record.id) {
      coscoAccessWork(record.id).then((res) => {
        const { code, data } = res;
        if (code == 200) {
          setData(data.coscoAccessWork)
        }
      })
    }
    

  }, [record])

  return (
    <Modal title="查看详情" visible={visible} footer={null} onCancel={onCancel}>
      {data && (
        <Descriptions bordered column={1}>
          <Descriptions.Item label="准入工作">{data.accessWorkName}</Descriptions.Item>
          <Descriptions.Item label="准入单位">{data.deptId}</Descriptions.Item>
          <Descriptions.Item label="准入部门">{data.deptId}</Descriptions.Item>
          <Descriptions.Item label="准入方式">{data.accessTypeText}</Descriptions.Item>
          <Descriptions.Item label="申请时间">{data.createTime}</Descriptions.Item>
          <Descriptions.Item label="状态">{data.reviewStatusText}</Descriptions.Item>
        </Descriptions>
      )}

    </Modal>
  );
};

export default ViewModal;