Merge branch 'master' into custom-新弘农业/V2-薪资核算表格添加序号列
# Conflicts: # src/pages/commonTable/index.tsx # src/pages/payrollFilesTable/index.tsxcustom-新弘农业/V2-薪资核算表格添加序号列
commit
3530b66586
@ -0,0 +1,90 @@
|
|||||||
|
import React, { FC, useEffect, useState } from "react";
|
||||||
|
import { Button, Table, Typography } from "antd";
|
||||||
|
import { exceptStr } from "@/utils/common";
|
||||||
|
import styles from "@/pages/atdTable/components/index.less";
|
||||||
|
|
||||||
|
const { Text } = Typography;
|
||||||
|
const ReportTable: FC = (props) => {
|
||||||
|
const [columns, setColumns] = useState<Array<any>>([]);
|
||||||
|
const [sumRow, setSumRow] = useState<Partial<{}>>({});
|
||||||
|
const [dataSource, setDataSource] = useState<Array<any>>([]);
|
||||||
|
const [showSumrow, setShowSumrow] = useState<boolean>(false);
|
||||||
|
|
||||||
|
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, countResult, showSum } = data;
|
||||||
|
setDataSource(dataSource);
|
||||||
|
setShowSumrow(showSum);
|
||||||
|
setSumRow(countResult);
|
||||||
|
setColumns(_.map(columns, item => {
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
children: _.map(item.children, child => {
|
||||||
|
return {
|
||||||
|
...child,
|
||||||
|
render: (text: string, record: any) => {
|
||||||
|
return <Button type="link" onClick={() => {
|
||||||
|
window.parent.postMessage(
|
||||||
|
{
|
||||||
|
type: "turn",
|
||||||
|
payload: { id: "PIVOTCHART", params: { record } }
|
||||||
|
},
|
||||||
|
"*"
|
||||||
|
);
|
||||||
|
}}>{text}</Button>;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return <Table
|
||||||
|
rowKey="id"
|
||||||
|
className={styles.tableWrapper}
|
||||||
|
columns={columns}
|
||||||
|
dataSource={dataSource}
|
||||||
|
pagination={false}
|
||||||
|
bordered
|
||||||
|
size="small"
|
||||||
|
scroll={{ x: 1200, y: `calc(100vh - 109px)` }}
|
||||||
|
summary={() => {
|
||||||
|
if (!showSumrow) return;
|
||||||
|
let totalColumns: any[] = [];
|
||||||
|
_.forEach(columns, it => {
|
||||||
|
if (!it.children) {
|
||||||
|
totalColumns.push(it);
|
||||||
|
} else {
|
||||||
|
totalColumns = [...totalColumns, ...it.children];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return (
|
||||||
|
<Table.Summary fixed>
|
||||||
|
<Table.Summary.Row>
|
||||||
|
{
|
||||||
|
_.map([{}, ...totalColumns], (item, index) => {
|
||||||
|
if (index === 0) {
|
||||||
|
return <Table.Summary.Cell index={0} key={index} align="center"><Text
|
||||||
|
type="danger">总计</Text></Table.Summary.Cell>;
|
||||||
|
}
|
||||||
|
return <Table.Summary.Cell index={index} key={index} align="center">
|
||||||
|
<Text type="danger">{!_.isNil(sumRow[item.dataIndex]) ? sumRow[item.dataIndex] : "-"}</Text>
|
||||||
|
</Table.Summary.Cell>;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</Table.Summary.Row>
|
||||||
|
</Table.Summary>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ReportTable;
|
Loading…
Reference in New Issue