泛微薪资核算iframe表格
parent
1aa1930cf1
commit
5c1dc110aa
@ -0,0 +1,77 @@
|
||||
import React, { FC, useEffect, useState } from "react";
|
||||
import { Table, Typography } from "antd";
|
||||
import styles from "@/pages/atdTable/components/index.less";
|
||||
import { exceptStr, paginationFun } from "@/utils/common";
|
||||
import { defaultPage, IPage } from "@/common/types";
|
||||
|
||||
const { Text } = Typography;
|
||||
const PreviewTable: FC = (props) => {
|
||||
const [columns, setColumns] = useState<Array<any>>([]);
|
||||
const [dataSource, setDataSource] = useState<Array<any>>([]);
|
||||
const [pageInfo, setPageInfo] = useState<IPage>(defaultPage);
|
||||
const [sumRow, setSumRow] = useState<Partial<{}>>({});
|
||||
|
||||
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 { columns, dataSource, pageInfo, salaryBillSendSum } = data;
|
||||
const { current: pageNum, pageSize: size, total } = pageInfo;
|
||||
setDataSource(dataSource);
|
||||
setColumns(columns);
|
||||
setSumRow(salaryBillSendSum);
|
||||
setPageInfo({ pageNum, size, total });
|
||||
}
|
||||
};
|
||||
const sizeChange = (pageobj: IPage) => {
|
||||
};
|
||||
const onChange = (pageobj: IPage) => {
|
||||
setPageInfo({ ...pageInfo, ...pageobj });
|
||||
window.parent.postMessage(
|
||||
{
|
||||
type: "turn",
|
||||
payload: { id: "PAGEINFO", params: { ...pageInfo, ...pageobj } }
|
||||
},
|
||||
"*"
|
||||
);
|
||||
};
|
||||
return <Table
|
||||
rowKey="id"
|
||||
className={styles.tableWrapper}
|
||||
columns={columns}
|
||||
dataSource={dataSource}
|
||||
size="small"
|
||||
pagination={{
|
||||
...paginationFun(pageInfo, sizeChange, onChange),
|
||||
size: "default"
|
||||
}}
|
||||
scroll={{ x: 1200, y: "calc(100vh - 193px)" }}
|
||||
summary={() => {
|
||||
if (_.isEmpty(columns)) return;
|
||||
return (
|
||||
<Table.Summary fixed>
|
||||
<Table.Summary.Row>
|
||||
{
|
||||
_.map(columns, (item, index) => {
|
||||
if (index === 0) {
|
||||
return <Table.Summary.Cell index={0} key={index}><Text type="danger">总计</Text></Table.Summary.Cell>;
|
||||
}
|
||||
return <Table.Summary.Cell index={index} key={index}>
|
||||
<Text type="danger">{sumRow[item.dataIndex] || "-"}</Text>
|
||||
</Table.Summary.Cell>;
|
||||
})
|
||||
}
|
||||
</Table.Summary.Row>
|
||||
</Table.Summary>
|
||||
);
|
||||
}}
|
||||
/>;
|
||||
};
|
||||
|
||||
export default PreviewTable;
|
Loading…
Reference in New Issue