salary-management-front/pc4mobx/hrmSalary/pages/mobilePayroll/index.js

100 lines
3.2 KiB
JavaScript

import React from "react";
import { inject, observer } from "mobx-react";
import { getQueryString } from "../../util/url";
import Authority from "../mySalary/authority";
import ComputerTemplate from "../payroll/templatePreview/computerTemplate";
import PhoneTemplate from "../payroll/templatePreview/phoneTemplate";
import "../payroll/templatePreview/index.less";
@inject("mySalaryStore")
@observer
export default class MobilePayroll extends React.Component {
constructor(props) {
super(props);
this.state = {
mySalaryBillData: {
employeeInformation: {},
salaryTemplate: []
}
};
this.id = "";
}
componentWillMount() {
const type = getQueryString("type");
this.id = getQueryString("id");
const { mySalaryStore: { init } } = this.props;
type !== "phone" && init(false);
this.getMySalaryBill(this.id);
}
getMySalaryBill = (salaryInfoId) => {
const { mySalaryStore: { getMySalaryBill } } = this.props;
const params = this.getUrlkey();
const payload = {
salaryInfoId,
..._.omit(params, ["id", "_key", "type"])
};
getMySalaryBill(payload).then(result => {
this.setState({
mySalaryBillData: result
});
});
};
getUrlkey = () => {
let url = window.location.href;
let params = {},
arr = url.split("?");
if (arr.length <= 1)
return params;
arr = arr[1].split("&");
for (var i = 0, l = arr.length; i < l; i++) {
var a = arr[i].split("=");
params[a[0]] = a[1];
}
return params;
};
render() {
const { mySalaryBillData } = this.state;
const type = getQueryString("type");
const employeeInformation = mySalaryBillData.employeeInformation ? mySalaryBillData.employeeInformation : {};
const salaryGroups = mySalaryBillData.salaryGroups ? mySalaryBillData.salaryGroups : [];
return (
<div className="computerTemplate" style={{
height: "100%",
overflowY: "hidden",
paddingBottom: "20px"
}}>
{
type === "phone" ?
<div className="templatePreview">
<div className="contentWrapper">
<PhoneTemplate
isPreview
isMsgPreview
salaryTemplateShowSet={JSON.stringify(mySalaryBillData.salaryTemplate)}
salaryItemSet={!_.isEmpty(salaryGroups) ? JSON.stringify([employeeInformation, ...salaryGroups]) : []}
/>
</div>
</div>
:
<Authority ecId={`${this && this.props && this.props.ecId || ""}_Authority@lulowc`}
store={this.props.mySalaryStore}>
<div className="templatePreview">
<div className="contentWrapper">
<ComputerTemplate
isPreview
isMsgPreview
salaryTemplateShowSet={JSON.stringify(mySalaryBillData.salaryTemplate)}
salaryItemSet={!_.isEmpty(salaryGroups) ? JSON.stringify([employeeInformation, ...salaryGroups]) : JSON.stringify([])}
/>
</div>
</div>
</Authority>
}
</div>
);
}
}