diff --git a/src/pages/payrollFilesTable/index.tsx b/src/pages/payrollFilesTable/index.tsx new file mode 100644 index 0000000..d47ac2c --- /dev/null +++ b/src/pages/payrollFilesTable/index.tsx @@ -0,0 +1,252 @@ +import React, { FC, useEffect, useState } from "react"; +import { Button, Dropdown, Menu, Space, Spin, Table, Typography } from "antd"; +import { DownOutlined } from "@ant-design/icons"; +import { exceptStr, paginationFun } from "@/utils/common"; +import styles from "@/pages/atdTable/components/index.less"; +import { defaultPage, IPage } from "@/common/types"; +import cs from "classnames"; + +const { Text } = Typography; +const payrollFilesTable: FC = (props) => { + const [columns, setColumns] = useState>([]); + const [sumRow, setSumRow] = useState({}); + const [pageInfo, setPageInfo] = useState(defaultPage); + const [dataSource, setDataSource] = useState>([]); + const [showSumrow, setShowSumrow] = useState(false); + const [selected, setSelected] = useState>([]); + + 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, + pageInfo, + showOperateBtn, + selectedKey, + selectedRowKeys + } = data; + const { current: pageNum, pageSize: size, total } = pageInfo; + setDataSource(dataSource); + setColumns(_.map(columns, item => { + if (item.dataIndex === "operate") { + return { + ...item, + render: (text: string, r: { id?: string }) => { + let dom = null; + if (!showOperateBtn) { + dom = ; + } else { + if (selectedKey === "pending") { + dom = + + + + + + + + + + } + > + 更多 + + ; + } else if (selectedKey === "fixed") { + dom = ; + } else if (selectedKey === "suspend") { + dom = + + + + + + + + + + } + > + 更多 + + ; + } else { + dom = + + + ; + } + } + return dom; + } + }; + } + return { ...item }; + })); + setShowSumrow(showSum); + setSumRow(_.isEmpty(countResult) ? { [new Date().getTime()]: new Date().getTime() } : countResult); + setPageInfo({ pageNum, size, total }); + setSelected(selectedRowKeys); + } + }; + const handleMenuClick = (event: any, id?: string) => { + window.parent.postMessage( + { + type: "turn", + payload: { id: "MOREOPT", params: { id, event } } + }, + "*" + ); + }; + const sizeChange = (pageobj: IPage) => { + }; + const onChange = (pageobj: IPage) => { + setPageInfo({ ...pageInfo, ...pageobj }); + window.parent.postMessage( + { + type: "turn", + payload: { id: "PAGEINFO", params: { ...pageInfo, ...pageobj } } + }, + "*" + ); + }; + + const rowSelection = { + columnWidth: 50, + selectedRowKeys: selected, + onChange: (selectedRowKeys: Array) => { + setSelected(selectedRowKeys); + window.parent.postMessage( + { + type: "turn", + payload: { id: "ROWSELECTION", params: { selectedRowKeys } } + }, + "*" + ); + } + }; + return { + if (!showSumrow) return; + let totalColumns: any[] = []; + _.forEach(columns, it => { + if (!it.children) { + totalColumns.push(it); + } else { + totalColumns = [...totalColumns, ...it.children]; + } + }); + return ( + + + { + sumRow.loading ? : + _.map([{},...totalColumns], (item, index) => { + if (index === 0) { + return 总计; + } + return + {!_.isNil(sumRow[item.dataIndex]) ? sumRow[item.dataIndex] : "-"} + ; + }) + } + + + ); + }} + />; +}; + +export default payrollFilesTable;