master
lys 4 months ago
parent ccdd0b8818
commit ed8f9a056b

@ -1,8 +1,9 @@
import React, { FC, useEffect, useState } from "react"; import React, { FC, useEffect, useState } from "react";
import { Button, Table, Typography } from "antd"; import { Button, Spin, Table, Typography } from "antd";
import { exceptStr, paginationFun } from "@/utils/common"; import { exceptStr, paginationFun } from "@/utils/common";
import { defaultPage, IPage } from "@/common/types"; import { defaultPage, IPage } from "@/common/types";
import styles from "@/pages/atdTable/components/index.less"; import styles from "@/pages/atdTable/components/index.less";
import API from "@/api";
const { Text } = Typography; const { Text } = Typography;
const StandingbookTable: FC = (props) => { const StandingbookTable: FC = (props) => {
@ -11,6 +12,7 @@ const StandingbookTable: FC = (props) => {
const [dataSource, setDataSource] = useState<Array<any>>([]); const [dataSource, setDataSource] = useState<Array<any>>([]);
const [pageInfo, setPageInfo] = useState<IPage>(defaultPage); const [pageInfo, setPageInfo] = useState<IPage>(defaultPage);
const [sumRow, setSumRow] = useState<Partial<{}>>({}); const [sumRow, setSumRow] = useState<Partial<{}>>({});
const [showSumrow, setShowSumrow] = useState<boolean>(false);
useEffect(() => { useEffect(() => {
window.parent.postMessage({ type: "init" }, "*"); window.parent.postMessage({ type: "init" }, "*");
@ -22,33 +24,30 @@ const StandingbookTable: FC = (props) => {
const receiveMessageFromIndex = async (event: any) => { const receiveMessageFromIndex = async (event: any) => {
const data: any = exceptStr(event.data); const data: any = exceptStr(event.data);
if (!_.isEmpty(data)) { if (!_.isEmpty(data)) {
const { columns, dataSource, pageInfo, showOperates, selectedRowKeys, sumRow } = data; const {
columns, dataSource, pageInfo, showOperates, selectedRowKeys,
sumpayload, selectedKey
} = data;
const { current: pageNum, pageSize: size, total } = pageInfo; const { current: pageNum, pageSize: size, total } = pageInfo;
const conventColumns = _.map( const conventColumns = _.map(_.filter(columns, it => it.dataIndex !== "id"), item => {
_.filter(columns, (it) => it.dataIndex !== "id"),
(item) => {
const { dataIndex } = item; const { dataIndex } = item;
if (dataIndex === "employeeId") { if (dataIndex === "employeeId") {
return { return {
title: "姓名", title: "姓名", dataIndex, fixed: "left", width: 150,
dataIndex, render: (_: any, record: Partial<any>) => (
fixed: "left", <span>{record?.userName}</span>
width: 150, )
render: (_: any, record: Partial<any>) => <span>{record?.userName}</span>
}; };
} }
return { return {
dataIndex, dataIndex, width: 150,
width: 150, title: <span dangerouslySetInnerHTML={{ __html: item.title }}/>
title: <span dangerouslySetInnerHTML={{ __html: item.title }} />
}; };
} });
);
setDataSource(dataSource); setDataSource(dataSource);
setColumns( setColumns(
!showOperates !showOperates ? conventColumns :
? conventColumns [
: [
...conventColumns, ...conventColumns,
{ {
title: "操作", title: "操作",
@ -57,9 +56,7 @@ const StandingbookTable: FC = (props) => {
width: 120, width: 120,
render: (_: any, record: any) => { render: (_: any, record: any) => {
return ( return (
<Button type="link" onClick={() => handleEdit(record)}> <Button type="link" onClick={() => handleEdit(record)}></Button>
</Button>
); );
} }
} }
@ -67,27 +64,61 @@ const StandingbookTable: FC = (props) => {
); );
setPageInfo({ pageNum, size, total }); setPageInfo({ pageNum, size, total });
setSelected(selectedRowKeys); setSelected(selectedRowKeys);
setSumRow(sumRow); const confCode: any = await API.CalculateService.getSysconfcode({ code: "OPEN_ACCT_RESULT_SUM" });
setShowSumrow(confCode.data.status && confCode.data.data === "1");
if (confCode.data.status && confCode.data.data === "1") {
const sumRowlist: any = selectedKey === "1" ? await API.CalculateService.siaccountDetailCommonListSum(sumpayload) :
selectedKey === "3" ? await API.CalculateService.siaccountDetailSupplementaryListSum(sumpayload) :
selectedKey === "regression" ? await API.CalculateService.siaccountDetailRecessionListSum(sumpayload) :
selectedKey === "difference" ? await API.CalculateService.siaccountDetailBalanceListSum(sumpayload) : {
data: {
status: false,
data: { sumRow: {} }
}
};
if (sumRowlist.data.status) {
if (!_.isEmpty(sumRowlist.data.data.sumRow)) {
setSumRow(sumRowlist.data.data.sumRow);
} else {
setSumRow({ [new Date().getTime()]: new Date().getTime() });
}
}
if (sumRowlist.data.status && _.isNil(sumRowlist.data.data.sumRow)) {
setSumRow({ [new Date().getTime()]: new Date().getTime() });
}
}
} }
}; };
const handleEdit = (record: any) => { const handleEdit = (record: any) => {
window.parent.postMessage({ type: "turn", payload: { id: "EDIT", params: { ...record } } }, "*"); window.parent.postMessage({ type: "turn", payload: { id: "EDIT", params: { ...record } } }, "*");
}; };
const sizeChange = (pageobj: IPage) => {}; const sizeChange = (pageobj: IPage) => {
};
const onChange = (pageobj: IPage) => { const onChange = (pageobj: IPage) => {
setPageInfo({ ...pageInfo, ...pageobj }); setPageInfo({ ...pageInfo, ...pageobj });
window.parent.postMessage({ type: "turn", payload: { id: "PAGEINFO", params: { ...pageInfo, ...pageobj } } }, "*"); window.parent.postMessage(
{
type: "turn",
payload: { id: "PAGEINFO", params: { ...pageInfo, ...pageobj } }
},
"*"
);
}; };
const rowSelection = { const rowSelection = {
selectedRowKeys: selected, selectedRowKeys: selected,
columnWidth: 60, columnWidth: 80,
onChange: (selectedRowKeys: Array<any>) => { onChange: (selectedRowKeys: Array<any>) => {
setSelected(selectedRowKeys); setSelected(selectedRowKeys);
window.parent.postMessage({ type: "turn", payload: { id: "ROWSELECT", params: { selectedRowKeys } } }, "*"); window.parent.postMessage(
{
type: "turn",
payload: { id: "ROWSELECT", params: { selectedRowKeys } }
},
"*"
);
} }
}; };
return ( return <Table
<Table
rowKey="id" rowKey="id"
className={styles.tableWrapper} className={styles.tableWrapper}
columns={columns} columns={columns}
@ -100,30 +131,27 @@ const StandingbookTable: FC = (props) => {
}} }}
scroll={{ x: 1200, y: `calc(100vh - 172px)` }} scroll={{ x: 1200, y: `calc(100vh - 172px)` }}
summary={() => { summary={() => {
if (_.isEmpty(sumRow)) return; if (_.isEmpty(columns) || !showSumrow) return;
return ( return (
<Table.Summary fixed> <Table.Summary fixed>
<Table.Summary.Row> <Table.Summary.Row>
{_.map([{}, ...columns], (item, index) => { {
_.isEmpty(sumRow) ? <Spin tip="加载中"/> :
_.map([{}, ...columns], (item, index) => {
if (index === 0) { if (index === 0) {
return ( return <Table.Summary.Cell index={0} key={index} align="center"><Text
<Table.Summary.Cell index={0} key={index} align="center"> type="danger"></Text></Table.Summary.Cell>;
<Text type="danger"></Text>
</Table.Summary.Cell>
);
} }
return ( return <Table.Summary.Cell index={index} key={index}>
<Table.Summary.Cell index={index} key={index}>
<Text type="danger">{!_.isNil(sumRow[item.dataIndex]) ? sumRow[item.dataIndex] : "-"}</Text> <Text type="danger">{!_.isNil(sumRow[item.dataIndex]) ? sumRow[item.dataIndex] : "-"}</Text>
</Table.Summary.Cell> </Table.Summary.Cell>;
); })
})} }
</Table.Summary.Row> </Table.Summary.Row>
</Table.Summary> </Table.Summary>
); );
}} }}
/> />;
);
}; };
export default StandingbookTable; export default StandingbookTable;

Loading…
Cancel
Save