safety-eval-service-frontend/src/pages/Container/QualApplication/FilingForm/components/EquipmentStep.jsx

153 lines
4.4 KiB
React
Raw Normal View History

2026-07-03 17:55:26 +08:00
import { Button, Image, Space, Table } from "antd";
2026-06-30 17:32:29 +08:00
import { useState } from "react";
2026-07-02 15:01:19 +08:00
2026-07-03 17:55:26 +08:00
import UploadButton from "~/components/UploadButton";
2026-06-30 17:32:29 +08:00
import OrgEquipmentSelectModal from "./OrgEquipmentSelectModal";
export default function EquipmentStep({
equipmentList = [],
disabled,
onAdd,
onRemove,
onUploadCalibration,
}) {
const [selectOpen, setSelectOpen] = useState(false);
2026-07-02 15:01:19 +08:00
const [previewImage, setPreviewImage] = useState("");
2026-07-15 16:13:07 +08:00
const [selectedRowKeys, setSelectedRowKeys] = useState([]);
const existingIds = equipmentList.map((item) =>
String(item.sourceEquipmentId || ""),
);
const isImage = (url) =>
/\.(png|jpe?g|gif|bmp|webp|svg)(\?.*)?$/i.test(url || "");
2026-06-30 17:32:29 +08:00
2026-07-15 16:13:07 +08:00
const handleBatchRemove = () => {
const records = selectedRowKeys
.map((key) =>
equipmentList.find(
(item) => String(item.sourceEquipmentId || item.id) === key,
),
)
.filter(Boolean);
if (records.length > 0) {
onRemove?.(records);
}
};
2026-07-02 15:01:19 +08:00
2026-06-30 17:32:29 +08:00
return (
<>
2026-07-15 16:13:07 +08:00
<div
style={{
display: "flex",
justifyContent: "space-between",
marginBottom: 12,
}}
>
2026-06-30 17:32:29 +08:00
<span style={{ fontWeight: 600 }}>申请单位装备清单</span>
{!disabled && (
2026-07-15 16:13:07 +08:00
<Space size="small">
<Button size="small" onClick={() => setSelectOpen(true)}>
添加设备
</Button>
{selectedRowKeys.length > 0 && (
<Button danger size="small" onClick={handleBatchRemove}>
批量移除
</Button>
)}
</Space>
2026-06-30 17:32:29 +08:00
)}
</div>
<Table
size="small"
2026-07-15 16:13:07 +08:00
rowKey={(record) => String(record.sourceEquipmentId || record.id)}
2026-06-30 17:32:29 +08:00
pagination={false}
2026-07-03 14:47:36 +08:00
dataSource={equipmentList || []}
2026-07-15 16:13:07 +08:00
rowSelection={
!disabled
? {
selectedRowKeys,
onChange: setSelectedRowKeys,
}
: undefined
}
2026-06-30 17:32:29 +08:00
columns={[
{ title: "序号", width: 60, render: (_, __, index) => index + 1 },
2026-07-10 16:08:16 +08:00
{ title: "装备名称", dataIndex: "deviceName", ellipsis: true },
2026-07-15 16:13:07 +08:00
{ title: "规格型号", dataIndex: "deviceModel", ellipsis: true },
2026-06-30 17:32:29 +08:00
{ title: "生产厂家", dataIndex: "manufacturer" },
{
title: "计量检定情况",
2026-07-02 15:01:19 +08:00
width: 180,
2026-06-30 17:32:29 +08:00
render: (_, record) => (
2026-07-02 15:01:19 +08:00
<Space size="small">
{record.calibrationReportUrl ? (
<Button
type="link"
size="small"
onClick={() => {
if (isImage(record.calibrationReportUrl)) {
setPreviewImage(record.calibrationReportUrl);
} else {
window.open(record.calibrationReportUrl);
}
}}
>
预览
</Button>
) : (
!disabled && (
2026-07-03 17:55:26 +08:00
<UploadButton
2026-07-15 16:13:07 +08:00
uploadProps={{
accept:
".pdf,.doc,.docx,.xls,.xlsx,.png,.jpg,.jpeg,.gif,.bmp,.webp",
}}
2026-07-03 17:55:26 +08:00
onSuccess={(data) => onUploadCalibration?.(record, data)}
buttonProps={{ children: "上传报告" }}
/>
2026-07-02 15:01:19 +08:00
)
)}
</Space>
2026-06-30 17:32:29 +08:00
),
},
{
title: "操作",
width: 100,
2026-07-15 16:13:07 +08:00
render: (_, record) =>
2026-06-30 17:32:29 +08:00
!disabled && (
2026-07-15 16:13:07 +08:00
<Button
type="link"
size="small"
danger
onClick={() => onRemove?.(record)}
>
移除
</Button>
),
2026-06-30 17:32:29 +08:00
},
]}
/>
<OrgEquipmentSelectModal
open={selectOpen}
existingIds={existingIds}
onCancel={() => setSelectOpen(false)}
onConfirm={(ids, rows) => {
onAdd?.(ids, rows);
setSelectOpen(false);
}}
/>
2026-07-15 16:13:07 +08:00
{previewImage && (
<Image
style={{ display: "none" }}
preview={{
visible: !!previewImage,
src: previewImage,
onVisibleChange: (visible) => {
if (!visible) setPreviewImage("");
},
}}
/>
)}
2026-06-30 17:32:29 +08:00
</>
);
}