salary-management-oneself/src/pages/calcTable/index.tsx

299 lines
11 KiB
TypeScript
Raw Normal View History

2023-10-10 09:24:36 +08:00
/*
* Author: 黎永顺
* name: 薪资核算-
* Description:
* Date: 2023/9/14
*/
2024-10-18 16:30:50 +08:00
import React, { FunctionComponent, useEffect, useState } from "react";
import type { MenuProps } from "antd";
2025-01-08 18:21:19 +08:00
import { Button, Dropdown, Space, Table, Tooltip, Typography } from "antd";
import { DeleteOutlined, LockOutlined, QuestionCircleOutlined, SettingOutlined, UnlockOutlined } from "@ant-design/icons";
2024-10-18 16:30:50 +08:00
import CustomTableTitle from "@/pages/calcTable/customTableTitle";
import CalcExplainFooter from "@/pages/calcTable/calcExplainFooter";
import CaclFixedTotal from "./calcFixedTotal";
import type { ColumnType } from "antd/lib/table";
import type { PaginationData } from "rc-pagination";
import { exceptStr, paginationFun } from "@/utils/common";
import { IPage } from "@/common/types";
import styles from "@/pages/atdTable/components/index.less";
2023-10-10 09:24:36 +08:00
2024-10-18 15:11:20 +08:00
interface OwnProps {}
2023-10-10 09:24:36 +08:00
type Props = OwnProps;
2024-01-03 14:31:31 +08:00
type fixedProps = boolean | "top" | "bottom";
2023-10-10 09:24:36 +08:00
const { Text } = Typography;
const index: FunctionComponent<Props> = (props) => {
const [columns, setColumns] = useState<ColumnType<any>[]>([]);
const [dataSource, setDataSource] = useState<any[]>([]);
const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);
const [pageInfo, setPageInfo] = useState<Partial<PaginationData>>({});
const [i18n, setI18n] = useState<any>({});
const [showTotalCell, setShowTotalCell] = useState<boolean>(false);
const [isDetailTable, setIsDetailTable] = useState<boolean>(false);
2025-02-11 14:33:18 +08:00
const [showSee, setShowSee] = useState<boolean>(false);
2023-10-10 09:24:36 +08:00
const [sumRowlistUrl, setSumRowlistUrl] = useState<string>("");
2024-01-11 14:52:52 +08:00
const [tableScrollHeight, setTableScrollHeight] = useState<Number>(0);
2023-10-10 09:24:36 +08:00
const [payload, setPayload] = useState<string>("");
2024-01-03 14:31:31 +08:00
const [fixed, setFixed] = useState<fixedProps>(true);
2024-10-18 15:11:20 +08:00
const [sumRow, setSumRow] = useState<Partial<{}>>({}); //总计行数据
2023-10-10 09:24:36 +08:00
useEffect(() => {
window.parent.postMessage({ type: "init" }, "*");
window.addEventListener("message", receiveMessageFromIndex, false);
return () => {
window.removeEventListener("message", receiveMessageFromIndex, false);
};
}, []);
const receiveMessageFromIndex = (event: any) => {
const data: any = exceptStr(event.data);
if (!_.isEmpty(data)) {
const {
2024-10-18 15:11:20 +08:00
columns,
dataSource,
pageInfo,
selectedRowKeys: rowKeys = [],
i18n: i18nRes = {},
showTotalCell = false,
sumRowlistUrl = "",
payload = {},
calcDetail,
2025-02-11 14:33:18 +08:00
showSee = false,
2024-10-18 15:11:20 +08:00
fixed = true,
tableScrollHeight,
sumRow,
optWidth
2023-10-10 09:24:36 +08:00
} = data;
setSumRowlistUrl(sumRowlistUrl);
setShowTotalCell(showTotalCell);
setIsDetailTable(calcDetail);
2025-02-11 14:33:18 +08:00
setShowSee(showSee);
2023-10-10 09:24:36 +08:00
setI18n(i18nRes);
setPayload(payload);
2024-01-03 14:31:31 +08:00
setFixed(fixed);
2024-01-17 14:32:26 +08:00
setSumRow(sumRow);
2023-10-10 09:24:36 +08:00
setPageInfo(pageInfo);
setDataSource(dataSource);
2024-09-30 10:21:03 +08:00
setSelectedRowKeys([...selectedRowKeys, ...rowKeys]);
2024-01-11 14:52:52 +08:00
setTableScrollHeight(tableScrollHeight);
2024-10-18 15:11:20 +08:00
setColumns([
...convertColumns(_.map(columns, (o) => ({ ...o, i18n: i18nRes }))),
{
title: i18nRes["操作"],
dataIndex: "operate",
fixed: "right",
width: optWidth || 120,
render: (__, record) => (
<Space>
2025-02-11 14:33:18 +08:00
<Button type="link" onClick={() => handleEdit(record?.id, showSee)}>
{showSee ? i18nRes["查看"] : i18nRes["编辑"]}
2024-10-18 15:11:20 +08:00
</Button>
2024-11-19 09:17:38 +08:00
{optWidth && (
<>
<Button
type="link"
onClick={() =>
handleLockEmp({
lockStatus: "LOCK",
acctEmpIds: [record?.id]
})
}
>
{i18nRes["锁定"]}
</Button>
<Button
type="link"
onClick={() =>
handleLockEmp({
lockStatus: "UNLOCK",
acctEmpIds: [record?.id]
})
}
>
{i18nRes["解锁"]}
</Button>
</>
)}
2024-10-18 15:11:20 +08:00
{record?.lockTime && <Text>{record?.lockTime}</Text>}
</Space>
)
}
]);
2023-10-10 09:24:36 +08:00
}
};
const convertColumns: any = (cols: any[]) => {
2024-10-18 15:11:20 +08:00
return _.map(cols, (item) => {
2023-10-10 09:24:36 +08:00
if (_.isNaN(parseInt(item.dataIndex))) {
return { ...item };
} else {
return {
2024-10-18 15:11:20 +08:00
...item,
title: <CustomTableTitle {...item} onHandleFormulatd={handleFormulaTd} />,
children: convertColumns(_.map(item.children, (o) => ({ ...o, i18n: item.i18n }))),
className: styles["td_odd"],
i18n: item.i18n,
onCell: (record: any) => ({
2025-01-09 11:15:27 +08:00
className: !_.isEmpty(record[`${item.dataIndex}_feedback`]) && styles["feedbackBg"],
2024-10-18 15:11:20 +08:00
onContextMenu: (e: any) => {
2025-01-08 18:21:19 +08:00
(!item.calcDetail || item.rightClickType) && e.preventDefault();
2024-10-18 15:11:20 +08:00
}
}),
render: (text: string, record: any) => {
2025-01-08 18:21:19 +08:00
let items: MenuProps["items"] = !item.calcDetail
? [
{
label: item.i18n["锁定"],
key: "LOCK",
icon: <LockOutlined />,
onClick: () =>
handleLockEmp({
lockStatus: "LOCK",
acctEmpId: record?.id,
salaryItemId: item?.dataIndex
})
},
{
label: item.i18n["解锁"],
key: "UNLOCK",
icon: <UnlockOutlined />,
onClick: () =>
handleLockEmp({
lockStatus: "UNLOCK",
acctEmpId: record?.id,
salaryItemId: item?.dataIndex
})
}
]
: [];
2025-01-14 14:39:26 +08:00
item.rightClickType &&
item.rightClickType.includes("DELFEEDBACK") &&
2025-01-08 18:21:19 +08:00
(items = [
...items,
{
label: item.i18n["删除反馈"],
key: "DELFEEDBACK",
icon: <DeleteOutlined />,
onClick: () =>
handleDelFeedback({
acctEmpId: record?.id,
salaryItemId: item?.dataIndex
})
}
]);
2025-01-14 14:39:26 +08:00
item.rightClickType &&
item.rightClickType.includes("SETFEEDBACK") &&
2025-01-08 18:21:19 +08:00
(items = [
...items,
{
label: item.i18n["设置反馈"],
key: "SETFEEDBACK",
icon: <SettingOutlined />,
onClick: () =>
handleSetFeedback({
acctEmpId: record?.id,
salaryItemId: item?.dataIndex
})
}
]);
2024-10-18 15:11:20 +08:00
return (
2025-01-08 18:21:19 +08:00
<Dropdown menu={{ items: !item.calcDetail || item.rightClickType ? items : [] }} trigger={["contextMenu"]} overlayClassName={styles.contextMenu} destroyPopupOnHide>
2024-10-18 15:11:20 +08:00
<span className={styles.contentSpan}>
<span title={text} className={styles.contentTitle} style={{ color: `${record?.[item.dataIndex + "_color"]}` }}>
{text}
</span>
2024-10-22 15:32:26 +08:00
{record.lockItems && record.lockItems.includes(item.dataIndex) ? <LockOutlined title={item.i18n["锁定的项目值"]} /> : null}
2025-01-08 18:21:19 +08:00
{!_.isEmpty(record[`${item.dataIndex}_feedback`]) ? (
<Tooltip title={record[`${item.dataIndex}_feedback`]}>
<QuestionCircleOutlined />
</Tooltip>
) : null}
2024-10-18 15:11:20 +08:00
</span>
</Dropdown>
);
}
2023-10-10 09:24:36 +08:00
};
}
});
};
const handleFormulaTd = (dataIndex: string) => {
2024-10-18 15:11:20 +08:00
window.parent.postMessage({ type: "turn", payload: { id: "FORMULA", params: { dataIndex } } }, "*");
2023-10-10 09:24:36 +08:00
};
2025-02-11 14:33:18 +08:00
const handleEdit = (id: string, showSee: boolean) => {
window.parent.postMessage({ type: "turn", payload: { id: "EDIT", params: { id, showSee } } }, "*");
2024-05-29 10:36:46 +08:00
};
2024-10-18 15:11:20 +08:00
const handleLockEmp = (params: any) => {
window.parent.postMessage({ type: "turn", payload: { id: "LOCKEMP", params } }, "*");
2023-10-10 09:24:36 +08:00
};
2025-01-08 18:21:19 +08:00
// 复旦大学附属医院二开-薪资核算项添加右击删除反馈的操作
const handleDelFeedback = (params: any) => {
window.parent.postMessage({ type: "turn", payload: { id: "DELFEEDBACK", params } }, "*");
};
const handleSetFeedback = (params: any) => {
window.parent.postMessage({ type: "turn", payload: { id: "SETFEEDBACK", params } }, "*");
};
2024-10-18 15:11:20 +08:00
const sizeChange = (pageobj: IPage) => {};
2023-10-10 09:24:36 +08:00
const onChange = (pageobj: IPage) => {
setPageInfo(() => {
2024-10-18 16:30:50 +08:00
window.parent.postMessage({ type: "turn", payload: { id: "PAGEINFO", params: { ...pageInfo, ...pageobj } } }, "*");
2023-10-10 09:24:36 +08:00
return { ...pageInfo, ...pageobj };
});
};
const rowSelection = {
2025-02-25 15:22:10 +08:00
columnWidth: 50,
2025-04-24 16:51:07 +08:00
columnTitle: isDetailTable && _.isNil(showSee) ? "序号" : "",
renderCell: (value: boolean, record: any, index: number, originNode: React.ReactNode) => (isDetailTable && _.isNil(showSee) ? <span>{index + 1}</span> : originNode),
2024-10-18 15:11:20 +08:00
selectedRowKeys,
preserveSelectedRowKeys: true,
2024-09-30 10:21:03 +08:00
onChange: (rowKeys: React.Key[]) => {
setSelectedRowKeys(rowKeys);
2023-10-10 09:24:36 +08:00
window.parent.postMessage(
2024-10-18 15:11:20 +08:00
{
type: "turn",
payload: { id: "CHECKBOX", params: { selectedRowKeys: rowKeys } }
},
2023-10-10 09:24:36 +08:00
"*"
);
}
};
2024-10-18 15:11:20 +08:00
return (
<Table
rowKey="id"
size="small"
bordered
className={styles.tableWrapper}
dataSource={dataSource}
rowSelection={rowSelection}
scroll={{
x: 1200,
y: `calc(100vh - ${tableScrollHeight || (!showTotalCell ? 165 : 200)}px)`
}}
2025-02-11 14:33:18 +08:00
columns={!isDetailTable || showSee ? columns : _.filter(columns, (o) => o.dataIndex !== "operate")}
2024-10-18 15:11:20 +08:00
footer={() => (!isDetailTable ? <CalcExplainFooter i18n={i18n} /> : null)}
pagination={
!_.isNil(pageInfo)
? {
...paginationFun(pageInfo, sizeChange, onChange, i18n),
size: "default"
}
: false
}
summary={() =>
!showTotalCell ? (
<></>
) : (
<Table.Summary fixed={fixed}>
<Table.Summary.Row>
<Table.Summary.Cell index={0} align="center">
<Text type="danger">{i18n["总计"]}</Text>
</Table.Summary.Cell>
<CaclFixedTotal columns={columns} dataSourceUrl={sumRowlistUrl} payload={payload} sumRow={sumRow} />
</Table.Summary.Row>
</Table.Summary>
)
}
/>
);
2023-10-10 09:24:36 +08:00
};
export default index;