/*
  *
  * 工资单预览
  * @Author:    黎永顺
  * @Date:      2024/6/17
  * @Wechat:
  * @Email:     971387674@qq.com
  * @description:
*/
import React, { Component } from "react";
import { WeaDialog, WeaLocaleProvider } from "ecCom";
import { salaryBillPreview } from "../../../../apis/payroll";
import Content from "../../../../components/pcTemplate/content";
import "./index.less";

const getLabel = WeaLocaleProvider.getLabel;

class PayrollPreviewDialog extends Component {
  constructor(props) {
    super(props);
    this.state = {
      salaryBillData: { salaryTemplate: {}, salaryGroups: [], employeeInformation: {} }
    };
    this.preRef = null;
  }

  componentWillReceiveProps(nextProps, nextContext) {
    if (nextProps.visible !== this.props.visible && nextProps.visible) {
      const { salaryInfoId, recipient } = nextProps;
      salaryBillPreview({ salaryInfoId, recipient }).then(({ status, data }) => {
        if (status) {
          this.setState({ salaryBillData: data });
        }
      });
    }
  }


  render() {
    const {
      salaryTemplate, salaryGroups, employeeInformation, sendTime
    } = this.state.salaryBillData;
    const salaryProps = {
      theme: salaryTemplate.theme, tip: salaryTemplate.textContent, sendTime,
      background: salaryTemplate.background, tipPosi: salaryTemplate.textContentPosition || "",
      itemTypeList: [employeeInformation, ...salaryGroups]
    };
    return (
      <WeaDialog
        {...this.props} ref={dom => this.preRef = dom} scalable hasScroll className="payPreBox" initLoadCss
        style={{
          width: 998, height: window.innerHeight - 40, minHeight: 200, minWidth: 380, maxHeight: "90%",
          maxWidth: "90%", overflow: "hidden", transform: "translate(0px, 0px)"
        }}
      >
        <div className="pay-preview-layout">{!_.isEmpty(salaryGroups) && <Content {...salaryProps}/>}</div>
      </WeaDialog>
    );
  }
}

export default PayrollPreviewDialog;
