import { useEffect, useState } from "react";
import { Badge, Button, Form, Input, Modal, Table, message } from "antd";
import ControlWrapper from "@cqsjjb/jjb-react-admin-component/ControlWrapper";
import SearchForm from "~/components/SearchForm";
import TableAction from "@cqsjjb/jjb-react-admin-component/TableAction";
import { Connect } from "@cqsjjb/jjb-dva-runtime";
import { NS_COURSEWARE } from "~/enumerate/namespace";
import {
CLASS_STUDENT_EXAM_STATUS_OPTIONS,
CLASS_STUDENT_FACE_AUTH_MAP,
CLASS_STUDENT_STUDY_STATUS_MAP,
CLASS_STUDENT_EXAM_STATUS_MAP,
CLASS_STUDENT_STUDY_STATUS_OPTIONS,
} from "~/enumerate/constant";
/** 搜索表单值 → 查询参数:入班时间范围拆为起止字段(yyyy-MM-dd,接口暂未支持,先行透传) */
const buildQuery = (value) => {
const { entryTimeRange, ...rest } = value || {};
return {
...rest,
...(entryTimeRange?.[0]
? { entryTimeStart: entryTimeRange[0].format("YYYY-MM-DD") }
: {}),
...(entryTimeRange?.[1]
? { entryTimeEnd: entryTimeRange[1].format("YYYY-MM-DD") }
: {}),
current: 1,
size: 10,
};
};
/** 班级详情 — 学员 Tab:班级学员查询 */
function ClassStudentTab(props) {
const { classId } = props;
const [searchForm] = Form.useForm();
const [query, setQuery] = useState({ current: 1, size: 10 });
const [selectOpen, setSelectOpen] = useState(false);
const {
classStudentList: dataSource,
classStudentTotal: total,
classStudentLoading: loading,
} = props.courseware || {};
const tableSource = Array.isArray(dataSource) ? dataSource : [];
const handleSearch = (params = query) => {
props.classStudentPage({ ...params, classId });
};
useEffect(() => {
if (!classId) return;
handleSearch(query);
}, [classId]);
const columns = [
{
title: "序号",
width: 70,
fixed: "left",
render: (_, __, index) => (query.current - 1) * query.size + index + 1,
},
{ title: "姓名", dataIndex: "studentName", width: 100 },
{
title: "参训单位",
dataIndex: "unitName",
width: 160,
ellipsis: true,
render: (v) => v || "-",
},
{ title: "部门", dataIndex: "department", width: 120, render: (v) => v || "-" },
{ title: "手机号", dataIndex: "phone", width: 130, render: (v) => v || "-" },
{ title: "档案编号", dataIndex: "fileNumber", width: 220, ellipsis: true },
{
title: "人脸认证",
dataIndex: "faceAuth",
width: 100,
render: (v) => {
const item = CLASS_STUDENT_FACE_AUTH_MAP[v];
return item ? : "-";
},
},
{
title: "要求学时",
dataIndex: "requiredHours",
width: 100,
render: (v) => (v == null ? "-" : v),
},
{
title: "已完成学时",
dataIndex: "completedHours",
width: 110,
render: (v) => (v == null ? "-" : v),
},
{
title: "学习状态",
dataIndex: "studyStatus",
width: 100,
render: (v) => CLASS_STUDENT_STUDY_STATUS_MAP[v] ?? "-",
},
{
title: "考试状态",
dataIndex: "examStatus",
width: 100,
render: (v) => CLASS_STUDENT_EXAM_STATUS_MAP[v] ?? "-",
},
{
title: "操作人",
dataIndex: "createName",
width: 100,
},
{
title: "操作",
width: 160,
fixed: "right",
render: (_, record) => (
),
},
];
return (
<>
,
,
,
,
]}
onReset={(value) => {
const next = buildQuery(value);
setQuery(next);
handleSearch(next);
}}
onFinish={(value) => {
const next = buildQuery(value);
setQuery(next);
handleSearch(next);
}}
/>
`共 ${t} 条`,
current: query.current,
pageSize: query.size,
onChange: (page, pageSize) => {
const next = { ...query, current: page, size: pageSize };
setQuery(next);
handleSearch(next);
},
}}
/>
item.phone)}
onOk={async (rows) => {
// 批量新增班级学员
const res = await props.classStudentBatchSave(
rows.map(({ userName, deptName, account }) => ({
classId,
studentName: userName,
department: deptName,
phone: account,
})),
);
if (res?.success === false) return;
message.success("添加成功");
setSelectOpen(false);
handleSearch();
}}
onCancel={() => setSelectOpen(false)}
/>
>
);
}
/** 选择学员弹窗:数据源为人员信息列表 */
function StudentSelectModal({
open,
loading,
confirmLoading,
dataSource,
total,
requestPage,
selectedPhones,
onOk,
onCancel,
}) {
const [query, setQuery] = useState({ current: 1, size: 10 });
const [keyword, setKeyword] = useState("");
const [selectedRows, setSelectedRows] = useState([]);
const handleSearch = (params) => {
setQuery(params);
requestPage({
...params,
employmentStatusCode: 1,
});
};
useEffect(() => {
if (open) {
setKeyword("");
setSelectedRows([]);
handleSearch({ current: 1, size: 10 });
}
}, [open]);
return (
onOk(selectedRows)}
onCancel={onCancel}
>
setKeyword(e.target.value)}
onSearch={(value) =>
handleSearch({ current: 1, size: query.size, userName: value })
}
/>
(query.current - 1) * query.size + index + 1,
},
{
title: "公司名称",
dataIndex: "orgName",
ellipsis: true,
render: (v) => v || "-",
},
{
title: "部门",
dataIndex: "deptName",
width: 140,
render: (v) => v || "-",
},
{ title: "学员姓名", dataIndex: "userName", width: 100 },
{
title: "手机号",
dataIndex: "account",
width: 130,
render: (v) => v || "-",
},
]}
dataSource={Array.isArray(dataSource) ? dataSource : []}
rowSelection={{
preserveSelectedRowKeys: true,
selectedRowKeys: selectedRows.map((r) => r.id),
getCheckboxProps: (record) => ({
disabled: selectedPhones.includes(record.account),
}),
onChange: (_, rows) => setSelectedRows(rows),
}}
pagination={{
total,
size: "small",
showTotal: (t) => `共 ${t} 条`,
current: Number(query.current) || 1,
pageSize: Number(query.size) || 10,
onChange: (page, pageSize) =>
handleSearch({
current: page,
size: pageSize,
userName: query.userName,
}),
}}
/>
);
}
export default Connect([NS_COURSEWARE], true)(ClassStudentTab);