/*
 * Author: 黎永顺
 * name: 薪资项目拓扑图-查看
 * Description:
 * Date: 2023/10/26
 */
import React, { Component } from "react";
import { WeaLocaleProvider } from "ecCom";
import SalaryItemDiagram from "../salaryItemDiagram";
import { getQueryString } from "../../util/url";

const getLabel = WeaLocaleProvider.getLabel;

class Index extends Component {
  componentDidMount() {
    window.addEventListener("message", this.handleReceive, false);
  }

  handleReceive = async ({ data }) => {
    const { type } = data;
    if (type === "initDiagram") this.postMessageToChild();
  };

  componentWillUnmount() {
    window.removeEventListener("message", this.handleReceive, false);
  }

  postMessageToChild = () => {
    const i18n = { "公式": getLabel(18125, "公式") };
    const { params: payload = {} } = this.props;
    const acctEmpId = getQueryString("acctEmpId");
    const childFrameObj = document.getElementById("topologyDiagram");
    childFrameObj.contentWindow.postMessage(JSON.stringify({ ...payload, i18n, acctEmpId }), "*");
  };

  render() {
    return (
      <div style={{ width: "100%", height: "100%" }}>
        <SalaryItemDiagram/>
      </div>
    );
  }
}

export default Index;
