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

121 lines
3.9 KiB
React
Raw Normal View History

2026-06-30 17:32:29 +08:00
import { Connect } from "@cqsjjb/jjb-dva-runtime";
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";
import { NS_STAFF_INFO } from "~/enumerate/namespace";
import StaffViewModal from "~/pages/Container/EnterpriseInfo/PersonnelInfo/StaffViewModal";
function OrgPersonnelSelectModalInner(props) {
const { open, onCancel, onConfirm, existingIds = [] } = props;
const [searchForm] = Form.useForm();
const [selectedRowKeys, setSelectedRowKeys] = useState([]);
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();
const res = await props.staffInfoList({
current: page,
pageSize,
likeStaffName: values.staffName || undefined,
});
if (res?.success !== false) {
setDataSource(res?.data || []);
setPagination((prev) => ({ ...prev, current: page, pageSize, total: res?.totalCount || 0 }));
}
} catch (err) {
console.warn("[OrgPersonnelSelectModal] list failed:", err);
} finally {
setLoading(false);
}
};
2026-06-30 17:32:29 +08:00
useEffect(() => {
if (open) {
setSelectedRowKeys([]);
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-07-01 10:10:11 +08:00
const rows = dataSource.filter((row) => ids.includes(row.id));
2026-06-30 17:32:29 +08:00
onConfirm?.(ids, rows);
};
return (
<>
<Modal
open={open}
title="添加备案人员"
width={800}
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 }}>
<Form.Item name="staffName">
<Input placeholder="关键字搜索" allowClear />
</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,
onChange: setSelectedRowKeys,
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-06-30 17:32:29 +08:00
columns={[
{ title: "人员姓名", dataIndex: "staffName" },
{ title: "类型", dataIndex: "personType" },
{ title: "职务", dataIndex: "positionName" },
{ title: "职称", dataIndex: "titleName" },
{
title: "操作",
width: 80,
render: (_, record) => (
<Button type="link" size="small" onClick={() => setViewId(record.id)}>查看</Button>
),
},
]}
/>
</Modal>
<StaffViewModal
open={!!viewId}
currentId={viewId}
requestDetails={props.staffInfoGet}
onCancel={() => setViewId("")}
/>
</>
);
}
export default Connect([NS_STAFF_INFO], true)(OrgPersonnelSelectModalInner);