salary-management-front/pc4mobx/hrmSalary/pages/calculate/doCalc/components/salaryDeptSummary/index.js

101 lines
3.5 KiB
JavaScript

/*
* 杭州五院二开
* 部门汇总表
* @Author: 黎永顺
* @Date: 2025/10/20
* @Wechat:
* @Email: 971387674@qq.com
* @description:
*/
import React, { Component } from "react";
import { WeaLocaleProvider } from "ecCom";
import { Spin } from "antd";
import { postFetch } from "../../../../../util/request";
import { traverse } from "../salaryEditCalc/editCalcTable";
const getLabel = WeaLocaleProvider.getLabel;
class Index extends Component {
constructor(props) {
super(props);
this.state = {
showTotalCell: false, loading: false, dataSource: [], sumRow: {}
};
}
componentDidMount() {
window.addEventListener("message", this.handleReceive, false);
}
componentWillUnmount() {
window.removeEventListener("message", this.handleReceive, false);
}
handleReceive = async ({ data }) => {
const { type, payload: { id, params } = {} } = data;
if (type === "init") this.getAcctresultDepartmentList();
};
getAcctresultDepartmentList = () => {
const { routeParams: { salaryAcctRecordId } } = this.props;
this.setState({ loading: true });
const payload = { salaryAcctRecordId };
postFetch("/api/bs/hrmsalary/salaryacct/acctresult/department/list", payload).then(({ status, data }) => {
this.setState({ loading: false });
if (status && !_.isEmpty(data)) {
const { columns, list: dataSource } = data;
this.setState({ dataSource }, () => {
this.postMessageToChild({
dataSource, showTotalCell: true, sumRowlistUrl: "", calcDetail: true, tableScrollHeight: 156,
columns: _.every(traverse(columns, true), (it, idx) => !it.fixed) ? _.map(traverse(columns, true), (it, idx) => ({
...it, fixed: idx < 2 ? "left" : false
})) : traverse(columns, true)
});
});
this.getAcctresultDeptSum({
dataSource, showTotalCell: true, sumRowlistUrl: "", calcDetail: true, tableScrollHeight: 156,
columns: _.every(traverse(columns, true), (it, idx) => !it.fixed) ? _.map(traverse(columns, true), (it, idx) => ({
...it, fixed: idx < 2 ? "left" : false
})) : traverse(columns, true)
});
}
}).catch(() => this.setState({ loading: false }));
};
getAcctresultDeptSum = (tableData) => {
const { routeParams: { salaryAcctRecordId } } = this.props, payload = { salaryAcctRecordId };
postFetch("/api/bs/hrmsalary/salaryacct/acctresult/department/sum", payload)
.then(({ status, data }) => {
if (status) {
const { sumRow } = data;
this.setState({ sumRow }, () => {
this.postMessageToChild({ ...tableData, sumRow });
});
}
});
};
postMessageToChild = (payload = {}) => {
const i18n = {
"共": getLabel(18609, "共"), "条": getLabel(18256, "条"),
"总计": getLabel(523, "总计")
};
const childFrameObj = document.getElementById("deptTable");
childFrameObj.contentWindow.postMessage(JSON.stringify({ ...payload, i18n }), "*");
};
render() {
const { loading, dataSource } = this.state;
return (<div className="salary-edit-calc-content">
<div style={{ height: `calc((39px * ${dataSource.length}) + 188.53px)`, minHeight: "287px" }}>
<Spin spinning={loading}>
<iframe
style={{ border: 0, width: "100%", height: "100%" }}
src="/spa/hrmSalary/hrmSalaryCalculateDetail/index.html#/calcTable"
id="deptTable"
/>
</Spin>
</div>
</div>);
}
}
export default Index;