salary-management-front/pc4mobx/hrmSalary/pages/custom-pages/guangyang/printReport/index.js

134 lines
4.3 KiB
JavaScript

/*
* 光阳摩托薪酬二开
* 报表打印
* @Author: 黎永顺
* @Date: 2025/7/23
* @Wechat:
* @Email: 971387674@qq.com
* @description:
*/
import React, { Component } from "react";
import { WeaLocaleProvider, WeaTools } from "ecCom";
import cs from "classnames";
import moment from "moment";
import * as API from "../api";
import "../index.less";
const getLabel = WeaLocaleProvider.getLabel;
const getList = {
"actual": API.getQysfgzReportList, "summary": API.getGyDepartmentSalaryReport
};
class Index extends Component {
constructor(props) {
super(props);
this.state = {
columns: [], dataSource: [], userInfo: {}
};
}
async componentDidMount() {
const { data: userInfo } = await API.getAccountList();
const { employeeName, kbIds, salaryMonth, salarySobIds, type, ygxzs } = WeaTools.getUrlParams();
let payload = {};
if (type === "actual") {
payload = {
employeeName,
salaryMonth: moment(salaryMonth).startOf("month").format("YYYY-MM-DD"),
salarySobIds: salarySobIds ? salarySobIds.split(",") : [],
ygxzs: ygxzs ? ygxzs.split(",") : [],
kbIds: kbIds ? kbIds.split(",") : []
};
} else {
payload = {
salaryMonth: moment(salaryMonth).startOf("month").format("YYYY-MM-DD"),
salarySobIds: salarySobIds ? salarySobIds.split(",") : [],
ygxzs: ygxzs ? ygxzs.split(",") : [],
kbIds: kbIds ? kbIds.split(",") : []
};
}
getList[type](payload).then(({ status, data }) => {
if (status) {
const { column: columns, data: dataSource } = data;
this.setState({ columns: _.filter(columns, o => o.column !== "workcode"), dataSource, userInfo });
}
});
}
componentDidUpdate() {
const { columns, dataSource } = this.state;
if (!_.isEmpty(columns) && !_.isEmpty(dataSource)) {
setTimeout("window.print()", 500);
//window.print()
}
}
render() {
const { columns, dataSource, userInfo } = this.state, { salaryMonth, type } = WeaTools.getUrlParams();
return (
<div
className={cs("print-salary-detail-container", { "print-summary-salary-detail-container": type === "summary" })}>
<table>
<colgroup>
<col style={{ width: 30 }}/>
{
_.map(columns, o => {
let width = 60;
switch (o.column) {
case "userName":
width = 110;
break;
case "gfr":
width = 70;
break;
default:
break;
}
return <col style={{ width }}/>;
})
}
</colgroup>
<thead>
{type === "actual" && <tr>
<th colSpan={columns.length + 1}>
<span>{`常州光阳摩托车有限公司${moment(salaryMonth).subtract(1, "month").format("YYYY年MM月")}发放工资明细`}</span>
</th>
</tr>}
{type === "summary" && <tr>
<th colSpan={columns.length + 1}>
<span>{`常州光阳摩托车有限公司${moment(salaryMonth).subtract(1, "month").format("YYYY年MM月")}发放工资汇总`}</span>
</th>
</tr>}
<tr>
<th><span>{getLabel(111, "序号")}</span></th>
{_.map(columns, col => (<th key={col.column}>
<span>{col.text}</span></th>))}
</tr>
</thead>
<tbody>
{_.map(dataSource, (item, index) => (<tr>
<td><span>{index + 1}</span></td>
{_.map(columns, col => (<td key={col.column}>
<span>{item[col.column]}</span></td>))}
</tr>))}
</tbody>
<tfoot>
<tr>
<td colSpan={columns.length + 1}>
<div className="print-table-bottom-info">
<p>{getLabel(111, "总经理:")}<span></span></p>
<p>{getLabel(111, "副总经理:")}<span></span></p>
<p>{getLabel(111, "管理中心:")}<span></span></p>
<p>{getLabel(111, "制表人:")}<span>{userInfo.username}</span></p>
</div>
</td>
</tr>
</tfoot>
</table>
</div>);
}
}
export default Index;