2026-05-22 08:55:04 +08:00
|
|
|
import { Button, Descriptions, Modal, Space, message } from "antd";
|
2025-11-28 18:02:24 +08:00
|
|
|
import PreviewImg from "zy-react-library/components/PreviewImg";
|
|
|
|
|
import PreviewPdf from "zy-react-library/components/PreviewPdf";
|
2026-05-22 08:55:04 +08:00
|
|
|
import { getFileName, getFileSuffix, getFileUrl } from "zy-react-library/utils";
|
2025-11-28 18:02:24 +08:00
|
|
|
|
|
|
|
|
const ViewQualificationDetailsModal = (props) => {
|
2026-05-22 08:55:04 +08:00
|
|
|
const handleDownload = async (file) => {
|
|
|
|
|
const baseUrl = getFileUrl();
|
|
|
|
|
const fileUrl = file.url || (file.filePath ? `${baseUrl}${file.filePath}` : "");
|
|
|
|
|
const fileName = file.fileName || file.name || getFileName(file.filePath || fileUrl);
|
|
|
|
|
|
|
|
|
|
if (!fileUrl) {
|
|
|
|
|
message.error("文件地址不存在");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(fileUrl);
|
|
|
|
|
const blob = await response.blob();
|
|
|
|
|
const link = document.createElement("a");
|
|
|
|
|
const blobUrl = window.URL.createObjectURL(blob);
|
|
|
|
|
|
|
|
|
|
link.href = blobUrl;
|
|
|
|
|
link.download = fileName;
|
|
|
|
|
link.style.display = "none";
|
|
|
|
|
document.body.appendChild(link);
|
|
|
|
|
link.click();
|
|
|
|
|
document.body.removeChild(link);
|
|
|
|
|
window.URL.revokeObjectURL(blobUrl);
|
|
|
|
|
}
|
|
|
|
|
catch {
|
|
|
|
|
message.error("下载失败");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-11-28 18:02:24 +08:00
|
|
|
const previewFile = () => {
|
2026-05-22 08:55:04 +08:00
|
|
|
const files = props.data.files || [];
|
2025-11-28 18:02:24 +08:00
|
|
|
const imgFiles = [];
|
|
|
|
|
const pdfFiles = [];
|
2026-05-22 08:55:04 +08:00
|
|
|
const compressedFiles = [];
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < files.length; i++) {
|
|
|
|
|
const file = files[i];
|
|
|
|
|
const suffix = getFileSuffix(file.fileName || file.name || "").toLowerCase();
|
|
|
|
|
|
|
|
|
|
if (suffix === "pdf") {
|
|
|
|
|
pdfFiles.push(file);
|
|
|
|
|
}
|
|
|
|
|
else if (suffix === "zip" || suffix === "rar") {
|
|
|
|
|
compressedFiles.push(file);
|
2025-11-28 18:02:24 +08:00
|
|
|
}
|
|
|
|
|
else {
|
2026-05-22 08:55:04 +08:00
|
|
|
imgFiles.push(file);
|
2025-11-28 18:02:24 +08:00
|
|
|
}
|
|
|
|
|
}
|
2026-05-22 08:55:04 +08:00
|
|
|
|
|
|
|
|
const compressedFileNodes = compressedFiles.length > 0 && (
|
|
|
|
|
<div style={{ marginTop: imgFiles.length > 0 || pdfFiles.length > 0 ? 20 : 0 }}>
|
|
|
|
|
<Space direction="vertical" size="middle">
|
|
|
|
|
{compressedFiles.map(file => (
|
|
|
|
|
<Space key={file.id || file.filePath || file.url || file.fileName || file.name}>
|
|
|
|
|
<span>{file.fileName || file.name || getFileName(file.filePath || file.url || "")}</span>
|
|
|
|
|
<Button type="primary" size="small" onClick={() => handleDownload(file)}>
|
|
|
|
|
下载
|
|
|
|
|
</Button>
|
|
|
|
|
</Space>
|
|
|
|
|
))}
|
|
|
|
|
</Space>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
2025-11-28 18:02:24 +08:00
|
|
|
if (imgFiles.length > 0 && pdfFiles.length > 0) {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<div><PreviewImg files={imgFiles} /></div>
|
|
|
|
|
<div style={{ marginTop: 20 }}><PreviewPdf files={pdfFiles} urlKey="url" /></div>
|
2026-05-22 08:55:04 +08:00
|
|
|
{compressedFileNodes}
|
2025-11-28 18:02:24 +08:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (imgFiles.length > 0) {
|
2026-05-22 08:55:04 +08:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<PreviewImg files={imgFiles} />
|
|
|
|
|
{compressedFileNodes}
|
|
|
|
|
</>
|
|
|
|
|
);
|
2025-11-28 18:02:24 +08:00
|
|
|
}
|
|
|
|
|
if (pdfFiles.length > 0) {
|
2026-05-22 08:55:04 +08:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<PreviewPdf files={pdfFiles} />
|
|
|
|
|
{compressedFileNodes}
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (compressedFiles.length > 0) {
|
|
|
|
|
return compressedFileNodes;
|
2025-11-28 18:02:24 +08:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Modal
|
|
|
|
|
title={`${props.data.dataName}资质`}
|
|
|
|
|
width={800}
|
|
|
|
|
open
|
|
|
|
|
maskClosable={false}
|
|
|
|
|
onCancel={props.onCancel}
|
|
|
|
|
footer={[
|
|
|
|
|
<Button key="cancel" onClick={props.onCancel}>取消</Button>,
|
|
|
|
|
]}
|
|
|
|
|
>
|
|
|
|
|
<Descriptions
|
|
|
|
|
bordered
|
|
|
|
|
column={1}
|
|
|
|
|
styles={{ label: { width: 200 } }}
|
|
|
|
|
items={[
|
|
|
|
|
{ label: "资质", children: previewFile() },
|
|
|
|
|
...(props.data.isValidity === 0
|
|
|
|
|
? [{ label: "有效期开始时间", children: props.data.qualificationsTermStart }, { label: "有效期结束时间", children: props.data.qualificationsTermEnd }]
|
|
|
|
|
: []),
|
|
|
|
|
]}
|
|
|
|
|
/>
|
|
|
|
|
</Modal>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ViewQualificationDetailsModal;
|