import React from "react"; import "../index.less"; import { inject, observer } from "mobx-react"; import moment from "moment"; @inject("payrollStore") @observer export default class PhoneTemplate extends React.Component { constructor(props) { super(props); this.state = { salaryItemSet: [], salaryTemplateShowSet: { theme: "", background: "", textContentPosition: "", textContent: "" } }; } componentWillMount() { if (this.props.isPreview) return; let salaryTemplateShowSetStr = window.localStorage.getItem("salary-showset"); let salaryItemSetStr = window.localStorage.getItem("salaryItemSet"); this.setState({ salaryItemSet: JSON.parse(salaryItemSetStr), salaryTemplateShowSet: JSON.parse(salaryTemplateShowSetStr) }); } componentDidMount() { // && window.em if (this.props.isMsgPreview && this.props.salaryItemSet) { this.setState({ salaryItemSet: JSON.parse(this.props.salaryItemSet), salaryTemplateShowSet: JSON.parse(this.props.salaryTemplateShowSet) }); } } componentWillReceiveProps(nextProps) { if (nextProps.salaryTemplateShowSet !== this.props.salaryTemplateShowSet) { this.setState({ salaryItemSet: JSON.parse(nextProps.salaryItemSet), salaryTemplateShowSet: JSON.parse(nextProps.salaryTemplateShowSet) }); } } render() { const { salaryTemplateShowSet, salaryItemSet } = this.state; return (
{salaryTemplateShowSet.theme.replace("${companyName}", "上海泛微").replace("${salaryMonth}", moment(new Date()).format("YYYY-MM"))}
{/*{*/} {/* salaryTemplateShowSet.background &&
*/} {/* */} {/*
*/} {/*}*/}
{ salaryTemplateShowSet.textContentPosition == 1 && salaryTemplateShowSet.textContent }
{ salaryItemSet.length > 0 && salaryItemSet.map((group, index) => (
{group.groupName}
{ _.map(group.items, item => { return ; }) }
{(!this.props.isPreview && group.groupId !== "111111111111111111") ? item.salaryItemShowName : item.name} {item.salaryItemValue || "-"}
)) }
{ salaryTemplateShowSet.textContentPosition == 2 && salaryTemplateShowSet.textContent }
{this.props.children}
); } }