/* * 大成二开项目 * 薪酬统计报表-薪资明细表格 * @Author: 黎永顺 * @Date: 2024/5/24 * @Wechat: * @Email: 971387674@qq.com * @description: */ import React, { FunctionComponent, useEffect, useState } from "react"; import { exceptStr, paginationAction } from "@/utils/common"; import { PaginationData } from "rc-pagination"; import { Table, Typography } from "antd"; import SumTotal from "./sumTotal"; import styles from "../index.less"; const { Text } = Typography; export type extraType = { selectedRowKeys: React.Key[]; i18n: Partial<{}>; sumRow: Partial<{}>; scrollHeight: number; showTotalCell: boolean } interface OwnProps { } type Props = OwnProps; const salaryDetailTable: FunctionComponent = (props) => { const [columns, setColumns] = useState>([]); const [dataSource, setDataSource] = useState>([]); const [pageInfo, setPageInfo] = useState>({}); const [parent, setParent] = 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 { i18n, columns, dataSource, pageInfo, showTotalCell, tableScrollHeight: scrollHeight, selectedRowKeys, sumRow } = data; setColumns(_.map(columns, item => ({ ...item, render: (text: string, record: any) => { if (record.showRed) { return ({text}); } else { return ({text}); } } }))); setDataSource(dataSource); setPageInfo(pageInfo); setParent({ i18n, showTotalCell, scrollHeight, selectedRowKeys, sumRow }); } }; const onChange = (current: number, pageSize: number) => { setPageInfo((prevState) => { const { pageSize: size } = prevState; window.parent.postMessage( { type: "turn", payload: { id: "PAGEINFO", params: { ...pageInfo, current: size === pageSize ? current : 1, pageSize } } }, "*" ); return { ...pageInfo, current: size === pageSize ? current : 1, pageSize }; }); }; const rowSelection = { columnWidth: 60, selectedRowKeys: parent.selectedRowKeys, renderCell: (value: boolean, record: any, index: number, originNode: React.ReactNode) => (record?.showCheck === "1" ? originNode : null), onChange: (selectedRowKeys: React.Key[]) => { setParent({ ...parent, selectedRowKeys: selectedRowKeys }); window.parent.postMessage( { type: "turn", payload: { id: "CHECKBOX", params: { selectedRowKeys } } }, "*" ); } }; return ( it.id), expandIcon: () => null }} summary={() => (!parent.showTotalCell ? <> : {parent["i18n"]?.["总计"]} )} />); }; export default salaryDetailTable;