/*
 * Author: 黎永顺
 * name: 人员信息报送-基础信息
 * Description:
 * Date: 2023/8/14
 */
import React, { Component } from "react";
import { WeaLocaleProvider } from "ecCom";
import { getQueryString } from "../../../util/url";
import EmployeeDeclareDetailCalcDialog from "./employeeDeclareDetailCalcDialog";
import { getEmployeeDeclareInfo } from "../../../apis/declare";

const { getLabel } = WeaLocaleProvider;

class BaseInfo extends Component {
  constructor(props) {
    super(props);
    this.state = {
      declareCalcDialog: {
        visible: false, taxCycle: ""
      },
      declareInfo: {}
    };
  }

  /*
   * Author: 黎永顺
   * Description: 人员报送-获取整体的报送情况
   * Params:
   * Date: 2023/8/14
   */
  getEmployeeDeclareInfo = () => {
    const payload = {
      taxAgentId: getQueryString("id"),
      taxCycle: this.props.taxCycle
    };
    getEmployeeDeclareInfo(payload).then(({ status, data }) => {
      if (status) this.setState({ declareInfo: data });
    });
  };
  handleOpenFailDialog = () => {
    this.setState({
      declareCalcDialog: {
        visible: true, taxCycle: this.props.taxCycle
      }
    });
  };

  render() {
    const { declareCalcDialog, declareInfo } = this.state;
    const { declareFailSize, notDeclareSize } = declareInfo;
    return (
      <div className="base-info">
        <div className="left">
          <span>{getLabel(537996, "个税扣缴义务人")}：{decodeURIComponent(getQueryString("taxName") || "")}</span></div>
        <div className="right">
          <div className="header-declare-info">
            <a href="javascript:void(0);" className="fail"
               onClick={this.handleOpenFailDialog}>{getLabel(111, "报送失败")}:&nbsp;&nbsp;{declareFailSize || 0}</a>
            <span className="not">{getLabel(111, "未报送")}:&nbsp;&nbsp;{notDeclareSize || 0}</span>
          </div>
        </div>
        {/*报送失败数据查看*/}
        <EmployeeDeclareDetailCalcDialog
          {...declareCalcDialog}
          onCancel={() => {
            this.setState({
              declareCalcDialog: {
                visible: false, taxCycle: ""
              }
            });
          }}
        />
      </div>
    );
  }
}

export default BaseInfo;
