/* * Author: 黎永顺 * name: 薪资核算-列表 * Description: * Date: 2023/9/14 */ import React, { FunctionComponent, useEffect, useState } from "react"; import { Button, Table, Typography } from "antd"; import { LockOutlined } from "@ant-design/icons"; 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"; interface OwnProps { } type Props = OwnProps; type fixedProps = boolean | "top" | "bottom"; const { Text } = Typography; const index: FunctionComponent = (props) => { const [columns, setColumns] = useState[]>([]); const [dataSource, setDataSource] = useState([]); const [selectedRowKeys, setSelectedRowKeys] = useState([]); const [pageInfo, setPageInfo] = useState>({}); const [i18n, setI18n] = useState({}); const [showTotalCell, setShowTotalCell] = useState(false); const [isDetailTable, setIsDetailTable] = useState(false); const [sumRowlistUrl, setSumRowlistUrl] = useState(""); const [payload, setPayload] = useState(""); const [fixed, setFixed] = useState(true); 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, selectedRowKeys, i18n: i18nRes = {}, showTotalCell = false, sumRowlistUrl = "", payload = {}, calcDetail, fixed = true } = data; setSumRowlistUrl(sumRowlistUrl); setShowTotalCell(showTotalCell); setIsDetailTable(calcDetail); setI18n(i18nRes); setPayload(payload); setFixed(fixed); setPageInfo(pageInfo); setDataSource(dataSource); setSelectedRowKeys(selectedRowKeys); setColumns([...convertColumns(_.map(columns, o => ({ ...o, i18n: i18nRes }))), { title: i18nRes["操作"], dataIndex: "operate", fixed: "right", width: 120, render: (__, record) => () }]); } }; const convertColumns: any = (cols: any[]) => { return _.map(cols, item => { if (_.isNaN(parseInt(item.dataIndex))) { return { ...item }; } else { return { ...item, title: , children: convertColumns(_.map(item.children, o => ({ ...o, i18n: item.i18n }))), className: styles["td_odd"], i18n: item.i18n, render: (text: string) => ( {text} { item.lockStatus === "LOCK" ? : null } ) }; } }); }; const handleFormulaTd = (dataIndex: string) => { window.parent.postMessage( { type: "turn", payload: { id: "FORMULA", params: { dataIndex } } }, "*" ); }; const handleEdit = (id: string) => { window.parent.postMessage( { type: "turn", payload: { id: "EDIT", params: { id } } }, "*" ); }; const sizeChange = (pageobj: IPage) => { }; const onChange = (pageobj: IPage) => { setPageInfo(() => { window.parent.postMessage( { type: "turn", payload: { id: "PAGEINFO", params: { ...pageInfo, ...pageobj } } }, "*" ); return { ...pageInfo, ...pageobj }; }); }; const rowSelection = { columnWidth: 60, selectedRowKeys: selectedRowKeys, onChange: (selectedRowKeys: React.Key[]) => { setSelectedRowKeys(selectedRowKeys); window.parent.postMessage( { type: "turn", payload: { id: "CHECKBOX", params: { selectedRowKeys } } }, "*" ); } }; return ( o.dataIndex !== "operate")} footer={() => !isDetailTable ? : null} pagination={{ ...paginationFun(pageInfo, sizeChange, onChange, i18n), size: "default" }} summary={() => ( !showTotalCell ? <> : {i18n["总计"]} )} />); }; export default index;