import { Connect } from "@cqsjjb/jjb-dva-runtime"; import { Button, DatePicker, Descriptions, Form, Input, message, Modal, Select, Table, Upload } from "antd"; import { UploadOutlined } from "@ant-design/icons"; import { useEffect, useState } from "react"; import dayjs from "dayjs"; import PageLayout from "@cqsjjb/jjb-react-admin-component/PageLayout"; import SearchForm from "@cqsjjb/jjb-react-admin-component/SearchForm"; import ControlWrapper from "@cqsjjb/jjb-react-admin-component/ControlWrapper"; import TableAction from "@cqsjjb/jjb-react-admin-component/TableAction"; import { AntdTableFuncControl } from "@cqsjjb/jjb-common-decorator/antd"; import { tools } from "@cqsjjb/jjb-common-lib"; import { NS_STAFF_CERTIFICATE } from "~/enumerate/namespace"; import CertPreviewImg from "~/components/CertPreviewImg"; import AttachmentUpload from "~/components/AttachmentUpload"; import { dateRangeRule } from "~/utils/validators"; const { router } = tools; function StaffCertificatePage(props) { const urlParams = Object.fromEntries(new URLSearchParams(window.location.search)); const staffId = urlParams.staffId; const staffName = urlParams.staffName ? decodeURIComponent(urlParams.staffName) : ""; const [addModalOpen, setAddModalOpen] = useState(false); const [viewModalOpen, setViewModalOpen] = useState(false); const [currentId, setCurrentId] = useState(""); const [searchForm] = Form.useForm(); const { staffCertificate } = props; const { staffCertificateList: dataSource, staffCertificateTotal: total, staffCertificateLoading: loading, } = staffCertificate || {}; useEffect(() => { searchForm.setFieldsValue(router.query); handleSearch(); }, []); const handleSearch = () => { props.staffCertificateList({ ...router.query, personnelId: staffId }); }; const goBack = () => { window.location.href = window.location.pathname.replace(/\/Certificate.*$/, "/List"); }; const onDelete = (id) => { Modal.confirm({ title: "提示", content: "数据将会删除,您是否确认删除?", okText: "是", cancelText: "否", onOk: async () => { const res = await props.staffCertificateRemove({ id }); if (res?.success !== false) { message.success("删除成功"); handleSearch(); } }, }); }; return ( { setCurrentId(""); setAddModalOpen(true); }}>新增证书 } > , , , , ]} onReset={() => { router.query = { ...router.query, current: 1, size: 10 }; handleSearch(); }} onFinish={() => { router.query = { ...router.query, current: 1, size: 10 }; handleSearch(); }} /> ( ), }, ]} dataSource={dataSource} scroll={{ y: props.scrollY }} loading={loading} pagination={{ total, showSizeChanger: true, showQuickJumper: true, showTotal: (t) => `共 ${t} 条`, current: Number(router.query.current) || 1, pageSize: Number(router.query.size) || 10, onChange: (page, pageSize) => { router.query = { ...router.query, current: page, size: pageSize }; handleSearch(); }, }} /> {addModalOpen && ( { setAddModalOpen(false); setCurrentId(""); }} onSuccess={handleSearch} /> )} {viewModalOpen && ( { setViewModalOpen(false); setCurrentId(""); }} /> )} ); } function CertModal({ open, staffId, currentId, staffCertificateAdd, staffCertificateEdit, staffCertificateInfo, onCancel, onSuccess, }) { const [form] = Form.useForm(); const [submitting, setSubmitting] = useState(false); const [detailLoading, setDetailLoading] = useState(false); const [uploadFileList, setUploadFileList] = useState([]); useEffect(() => { if (!open) return; if (!currentId) { form.resetFields(); setUploadFileList([]); return; } let cancelled = false; (async () => { setDetailLoading(true); try { const res = await staffCertificateInfo({ id: currentId }); if (cancelled || !res?.data) return; const data = { ...res.data }; // 将 validStartDate/validEndDate 合并为 validDate(RangePicker 需要 dayjs 对象) if (data.validStartDate || data.validEndDate) { data.validDate = [ data.validStartDate ? dayjs(data.validStartDate) : undefined, data.validEndDate ? dayjs(data.validEndDate) : undefined, ]; } // 复核日期需要转为 dayjs 对象 if (data.reviewDate) { data.reviewDate = dayjs(data.reviewDate); } // 处理证书附件 fileList let fileList = []; if (Array.isArray(data.certImgFiles)) { fileList = data.certImgFiles.map((f, i) => ({ uid: f.uid || `-${i}`, name: f.fileName || f.name || `证书附件${i + 1}`, status: "done", url: f.url, })); } else if (data.certAttachmentUrl) { fileList = data.certAttachmentUrl.split(",").filter(Boolean).map((url, i) => ({ uid: `-${i}`, name: url.split("/").pop() || `证书附件${i + 1}`, status: "done", url, })); } data.certAttachmentUrl = fileList; setUploadFileList(fileList); form.setFieldsValue(data); } catch (err) { console.warn("[StaffCertificate] load detail failed:", err); } finally { if (!cancelled) setDetailLoading(false); } })(); return () => { cancelled = true; }; }, [open, currentId]); const handleCancel = () => { form.resetFields(); setUploadFileList([]); onCancel(); }; const handleSubmit = async (values) => { try { setSubmitting(true); const payload = { ...values, personnelId: staffId, validStartDate: values.validDate?.[0] ? dayjs(values.validDate[0]).format("YYYY-MM-DD") : undefined, validEndDate: values.validDate?.[1] ? dayjs(values.validDate[1]).format("YYYY-MM-DD") : undefined, reviewDate: values.reviewDate ? dayjs(values.reviewDate).format("YYYY-MM-DD") : undefined, certAttachmentUrl: Array.isArray(values.certAttachmentUrl) ? values.certAttachmentUrl.map((f) => f.url || f.response?.url).filter(Boolean).join(",") : "", }; delete payload.validDate; delete payload.certImgFiles; if (currentId) payload.id = currentId; const request = currentId ? staffCertificateEdit : staffCertificateAdd; const res = await request(payload); if (res?.success !== false) { message.success(currentId ? "编辑成功" : "添加成功"); handleCancel(); onSuccess(); } else { message.error(res?.message || "操作失败"); } } finally { setSubmitting(false); } }; return (
); } function ViewModal({ open, currentId, staffCertificateInfo, onCancel }) { const [info, setInfo] = useState({}); const [detailLoading, setDetailLoading] = useState(false); useEffect(() => { if (!open || !currentId) { setInfo({}); return; } let cancelled = false; (async () => { setDetailLoading(true); try { const res = await staffCertificateInfo({ id: currentId }); if (cancelled || !res?.data) return; const data = { ...res.data }; // 处理 certImgFiles if (Array.isArray(data.certImgFiles)) { data.certDisplayFiles = data.certImgFiles; } else if (data.certAttachmentUrl) { data.certDisplayFiles = data.certAttachmentUrl.split(",").filter(Boolean).map((url, i) => ({ uid: `-${i}`, fileName: url.split("/").pop() || `证书附件${i + 1}`, url, })); } else { data.certDisplayFiles = []; } setInfo(data); } catch (err) { console.warn("[StaffCertificate] load view failed:", err); } finally { if (!cancelled) setDetailLoading(false); } })(); return () => { cancelled = true; }; }, [open, currentId]); return ( {info.certName} {info.certTypeCode} {info.certTypeName} {info.certCategoryCode} {info.certCategoryName} {info.operationCategoryCode} {info.operationCategoryName} {info.certNo} {info.issueOrg} {info.validStartDate} {info.validEndDate} {info.reviewDate} ); } export default Connect([NS_STAFF_CERTIFICATE], true)(AntdTableFuncControl(StaffCertificatePage));