2026-07-01 10:10:11 +08:00
|
|
|
import { Button, Form, Input, Modal, Table } from "antd";
|
2026-06-30 17:32:29 +08:00
|
|
|
import { useEffect, useState } from "react";
|
2026-08-05 09:11:32 +08:00
|
|
|
import { apiGet } from "~/utils/enterpriseInfo/http";
|
|
|
|
|
import { CAPABILITY_MAP, GENDER_MAP } from "~/enumerate/constant";
|
2026-07-09 09:23:22 +08:00
|
|
|
import StaffViewModal from "~/components/StaffViewModal";
|
2026-06-30 17:32:29 +08:00
|
|
|
|
2026-08-05 09:11:32 +08:00
|
|
|
function calcAge(birthDate) {
|
|
|
|
|
if (!birthDate) return "-";
|
|
|
|
|
const birth = new Date(birthDate);
|
|
|
|
|
if (isNaN(birth.getTime())) return "-";
|
|
|
|
|
const now = new Date();
|
|
|
|
|
let age = now.getFullYear() - birth.getFullYear();
|
|
|
|
|
const m = now.getMonth() - birth.getMonth();
|
|
|
|
|
if (m < 0 || (m === 0 && now.getDate() < birth.getDate())) age--;
|
|
|
|
|
return age >= 0 ? age : "-";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function OrgPersonnelSelectModal(props) {
|
2026-06-30 17:32:29 +08:00
|
|
|
const { open, onCancel, onConfirm, existingIds = [] } = props;
|
|
|
|
|
const [searchForm] = Form.useForm();
|
|
|
|
|
const [selectedRowKeys, setSelectedRowKeys] = useState([]);
|
2026-08-06 15:52:14 +08:00
|
|
|
const [selectedRows, setSelectedRows] = useState([]);
|
2026-06-30 17:32:29 +08:00
|
|
|
const [viewId, setViewId] = useState("");
|
2026-07-01 10:10:11 +08:00
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
|
const [dataSource, setDataSource] = useState([]);
|
|
|
|
|
const [pagination, setPagination] = useState({ current: 1, pageSize: 10, total: 0 });
|
2026-06-30 17:32:29 +08:00
|
|
|
|
2026-07-01 10:10:11 +08:00
|
|
|
const getData = async (page = 1, pageSize = 10) => {
|
|
|
|
|
setLoading(true);
|
|
|
|
|
try {
|
|
|
|
|
const values = searchForm.getFieldsValue();
|
2026-08-05 09:11:32 +08:00
|
|
|
const res = await apiGet("/safetyEval/org-personnel/filing/page", {
|
2026-07-01 10:10:11 +08:00
|
|
|
current: page,
|
2026-07-09 13:15:13 +08:00
|
|
|
size: pageSize,
|
2026-08-05 09:11:32 +08:00
|
|
|
personName: values.personName || undefined,
|
2026-07-01 10:10:11 +08:00
|
|
|
});
|
|
|
|
|
if (res?.success !== false) {
|
2026-08-05 09:11:32 +08:00
|
|
|
setDataSource((res?.data || []).map((item) => ({ ...item, age: calcAge(item.birthDate) })));
|
2026-07-09 10:58:27 +08:00
|
|
|
setPagination((prev) => ({ ...prev, current: page, pageSize, total: res?.total || 0 }));
|
2026-07-01 10:10:11 +08:00
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.warn("[OrgPersonnelSelectModal] list failed:", err);
|
|
|
|
|
} finally {
|
|
|
|
|
setLoading(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
2026-06-30 17:32:29 +08:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (open) {
|
|
|
|
|
setSelectedRowKeys([]);
|
2026-08-06 15:52:14 +08:00
|
|
|
setSelectedRows([]);
|
2026-07-01 10:10:11 +08:00
|
|
|
searchForm.resetFields();
|
2026-06-30 17:32:29 +08:00
|
|
|
getData();
|
|
|
|
|
}
|
|
|
|
|
}, [open]);
|
|
|
|
|
|
2026-07-01 10:10:11 +08:00
|
|
|
const handleSearch = () => {
|
|
|
|
|
getData(1, pagination.pageSize);
|
|
|
|
|
};
|
|
|
|
|
|
2026-06-30 17:32:29 +08:00
|
|
|
const handleOk = () => {
|
|
|
|
|
const ids = selectedRowKeys.filter((id) => !existingIds.includes(String(id)));
|
|
|
|
|
if (!ids.length) {
|
|
|
|
|
Modal.warning({ title: "提示", content: "请选择至少一名未添加的人员" });
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-08-06 15:52:14 +08:00
|
|
|
const rows = selectedRows.filter((row) => ids.includes(row.id));
|
2026-06-30 17:32:29 +08:00
|
|
|
onConfirm?.(ids, rows);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Modal
|
|
|
|
|
open={open}
|
|
|
|
|
title="添加备案人员"
|
2026-08-05 09:11:32 +08:00
|
|
|
width={900}
|
2026-07-06 18:06:49 +08:00
|
|
|
destroyOnHidden
|
2026-06-30 17:32:29 +08:00
|
|
|
onCancel={onCancel}
|
|
|
|
|
onOk={handleOk}
|
|
|
|
|
okText="确认添加"
|
|
|
|
|
>
|
2026-07-01 10:10:11 +08:00
|
|
|
<Form form={searchForm} layout="inline" style={{ marginBottom: 16 }}>
|
2026-08-05 09:11:32 +08:00
|
|
|
<Form.Item name="personName">
|
2026-07-09 13:15:13 +08:00
|
|
|
<Input placeholder="人员姓名搜索" allowClear />
|
2026-07-01 10:10:11 +08:00
|
|
|
</Form.Item>
|
|
|
|
|
<Form.Item>
|
|
|
|
|
<Button type="primary" onClick={handleSearch}>搜索</Button>
|
|
|
|
|
<Button style={{ marginLeft: 8 }} onClick={() => { searchForm.resetFields(); getData(); }}>重置</Button>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
</Form>
|
2026-06-30 17:32:29 +08:00
|
|
|
<Table
|
|
|
|
|
rowKey="id"
|
2026-07-01 10:10:11 +08:00
|
|
|
loading={loading}
|
|
|
|
|
dataSource={dataSource}
|
2026-06-30 17:32:29 +08:00
|
|
|
rowSelection={{
|
|
|
|
|
selectedRowKeys,
|
2026-08-06 15:52:14 +08:00
|
|
|
preserveSelectedRowKeys: true,
|
|
|
|
|
onChange: (keys, rows) => {
|
|
|
|
|
setSelectedRowKeys(keys);
|
|
|
|
|
setSelectedRows(rows);
|
|
|
|
|
},
|
2026-06-30 17:32:29 +08:00
|
|
|
getCheckboxProps: (record) => ({
|
|
|
|
|
disabled: existingIds.includes(String(record.id)),
|
|
|
|
|
}),
|
|
|
|
|
}}
|
2026-07-01 10:10:11 +08:00
|
|
|
pagination={{
|
|
|
|
|
...pagination,
|
|
|
|
|
showSizeChanger: true,
|
|
|
|
|
showTotal: (t) => `共 ${t} 条`,
|
|
|
|
|
onChange: (page, pageSize) => getData(page, pageSize),
|
|
|
|
|
}}
|
2026-08-05 09:11:32 +08:00
|
|
|
scroll={{ x: 1100, y: 400 }}
|
2026-06-30 17:32:29 +08:00
|
|
|
columns={[
|
2026-08-05 09:11:32 +08:00
|
|
|
{ title: "人员姓名", dataIndex: "personName", ellipsis: true, width: 100 },
|
|
|
|
|
{ title: "部门", dataIndex: "deptName", ellipsis: true, width: 150 },
|
|
|
|
|
{ title: "岗位", dataIndex: "positionName", ellipsis: true, width: 120 },
|
|
|
|
|
{ title: "性别", dataIndex: "genderCode", width: 70, render: (v) => GENDER_MAP[v] || "-" },
|
|
|
|
|
{ title: "年龄", dataIndex: "age", width: 70 },
|
|
|
|
|
{ title: "注册安全工程师", dataIndex: "registerEngineerFlag", width: 130, render: (v) => v === 1 ? "是" : "否" },
|
|
|
|
|
{ title: "评价师", dataIndex: "evaluatorCertNo", width: 80, render: (v) => v ? "是" : "否" },
|
|
|
|
|
{
|
|
|
|
|
title: "能力",
|
|
|
|
|
render: (_, record) => {
|
|
|
|
|
const codes = record.professionalCapabilityCodeList || [];
|
|
|
|
|
return codes.length
|
|
|
|
|
? codes.map((code) => CAPABILITY_MAP[code] || code).join("、")
|
|
|
|
|
: "-";
|
|
|
|
|
},
|
|
|
|
|
},
|
2026-06-30 17:32:29 +08:00
|
|
|
{
|
|
|
|
|
title: "操作",
|
|
|
|
|
width: 80,
|
2026-08-05 09:11:32 +08:00
|
|
|
fixed: "right",
|
2026-06-30 17:32:29 +08:00
|
|
|
render: (_, record) => (
|
|
|
|
|
<Button type="link" size="small" onClick={() => setViewId(record.id)}>查看</Button>
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
]}
|
|
|
|
|
/>
|
|
|
|
|
</Modal>
|
|
|
|
|
<StaffViewModal
|
|
|
|
|
open={!!viewId}
|
|
|
|
|
currentId={viewId}
|
|
|
|
|
onCancel={() => setViewId("")}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|