salary-management-front/pc4mobx/hrmSalary/pages/payroll/templatePreview/computerTemplate/index.js

118 lines
3.8 KiB
JavaScript
Raw Normal View History

2022-09-08 17:04:36 +08:00
import React from "react";
import moment from "moment";
import { inject, observer } from "mobx-react";
2022-04-18 09:31:06 +08:00
2022-09-08 17:04:36 +08:00
@inject("payrollStore")
2022-05-05 15:53:35 +08:00
@observer
2022-09-08 17:04:36 +08:00
2022-04-18 09:31:06 +08:00
export default class ComputerTemplate extends React.Component {
2022-09-08 17:04:36 +08:00
constructor(props) {
super(props);
this.state = {
salaryItemSet: [],
salaryTemplateShowSet: {
2022-09-09 10:29:12 +08:00
theme: "",
background: "",
textContentPosition: "",
textContent: ""
2022-09-08 17:04:36 +08:00
}
};
}
componentWillMount() {
2022-09-09 10:29:12 +08:00
if (this.props.isPreview) return;
2023-01-09 14:04:08 +08:00
let salaryTemplateShowSetStr = window.localStorage.getItem("salary-showset") || "{}";
let salaryItemSetStr = window.localStorage.getItem("salaryItemSet") || "{}";
2022-09-08 17:04:36 +08:00
this.setState({
salaryItemSet: JSON.parse(salaryItemSetStr),
salaryTemplateShowSet: JSON.parse(salaryTemplateShowSetStr)
});
}
2022-09-09 10:29:12 +08:00
componentDidMount() {
if (this.props.isMsgPreview && this.props.salaryItemSet) {
2022-09-09 10:29:12 +08:00
this.setState({
salaryItemSet: JSON.parse(this.props.salaryItemSet),
salaryTemplateShowSet: JSON.parse(this.props.salaryTemplateShowSet)
});
}
}
2022-09-08 17:04:36 +08:00
componentWillReceiveProps(nextProps) {
2022-09-09 10:29:12 +08:00
if (nextProps.salaryTemplateShowSet !== this.props.salaryTemplateShowSet) {
2022-09-08 17:04:36 +08:00
this.setState({
salaryItemSet: JSON.parse(nextProps.salaryItemSet),
2022-09-09 10:29:12 +08:00
salaryTemplateShowSet: JSON.parse(nextProps.salaryTemplateShowSet)
2022-09-08 17:04:36 +08:00
});
2022-05-05 15:53:35 +08:00
}
2022-09-08 17:04:36 +08:00
}
renderTableTr = (data, groupId) => {
2022-09-08 17:04:36 +08:00
const tables = [];
const len = data.length;
const rowNum = 3;
const sumRows = len % rowNum;
const sumRowMod = len / rowNum;
const rows = (sumRows == 0 ? sumRowMod : parseInt(sumRowMod.toString()) + 1);
2022-09-08 17:04:36 +08:00
for (let j = 0; j < rows; j++) {
let iLen = (j + 1) * rowNum;
iLen = iLen > len ? len : iLen;
tables.push("<tr class='descriptions-row'>");
for (let i = j * rowNum; i < iLen; i++) {
const key = (!this.props.isPreview && groupId !== "111111111111111111") ? data[i].salaryItemShowName : data[i].name;
2022-09-08 17:04:36 +08:00
const value = data[i].salaryItemValue || "-";
tables.push("<th class=\"descriptions-item-label\">" + key + "</th>" + "<td class=\"descriptions-item-content\">" + value + "</td>");
2022-09-08 17:04:36 +08:00
}
tables.push("</tr>");
2022-05-05 15:53:35 +08:00
}
2022-09-08 17:04:36 +08:00
return tables;
};
2022-05-05 15:53:35 +08:00
2022-09-08 17:04:36 +08:00
render() {
2022-09-09 10:29:12 +08:00
const { salaryTemplateShowSet, salaryItemSet } = this.state;
2022-09-08 17:04:36 +08:00
return (
<div className="computerTemplate">
{salaryTemplateShowSet.theme &&
<div className="titleWrapper">
{salaryTemplateShowSet.theme.replace("${companyName}", "").replace("${salaryMonth}", moment(new Date()).format("YYYY-MM"))}
</div>
}
2023-03-03 09:14:35 +08:00
{/*{*/}
{/* salaryTemplateShowSet.background && <div className="background-wrapper">*/}
{/* <img className="background-img" src={salaryTemplateShowSet.background} alt=""/>*/}
{/* </div>*/}
{/*}*/}
2022-05-05 15:53:35 +08:00
2022-09-08 17:04:36 +08:00
<div className="sobItemDiv" style={{ margin: "20px 10px" }}>
{
salaryTemplateShowSet.textContentPosition == 1 && salaryTemplateShowSet.textContent
2022-09-08 17:04:36 +08:00
}
</div>
2022-04-18 09:31:06 +08:00
2022-09-08 17:04:36 +08:00
<div className="sobItemWrapper">
{
salaryItemSet.length > 0 &&
salaryItemSet.map((group, index) => {
return <div className="sobItem">
<div className="descript-title">{group.groupName}</div>
<div className="descriptions-view">
<table
dangerouslySetInnerHTML={{ __html: this.renderTableTr(group.items, group.groupId).join(",").replace(/,/g, "") }}/>
2022-05-05 15:53:35 +08:00
</div>
2022-09-08 17:04:36 +08:00
</div>;
})
}
</div>
<div style={{ margin: "20px 10px" }}>
{
salaryTemplateShowSet.textContentPosition == 2 && salaryTemplateShowSet.textContent
2022-09-08 17:04:36 +08:00
}
</div>
2023-07-12 10:14:38 +08:00
{this.props.children}
2022-09-08 17:04:36 +08:00
</div>
);
}
}