/*
 * Author: 黎永顺
 * name: 个税申报表详情-基本信息
 * Description:
 * Date: 2023/8/18
 */
import React, { Component } from "react";
import { message, Tag } from "antd";
import { WeaLocaleProvider } from "ecCom";
import DeclareResultDialog from "./declareResultDialog";
import MoreBtnMenu from "../../../components/moreBtnMenu";
import { taxdeclarationUpdateIcon } from "../../../apis/declare";
import { getQueryString } from "../../../util/url";

const { getLabel } = WeaLocaleProvider;

class TaxDeclarationInfo extends Component {
  constructor(props) {
    super(props);
    this.state = {
      resDialog: {
        visible: false, title: "",
        type: []
      }
    };
  }

  handleSeeResult = (type, title) => {
    this.setState({
      resDialog: { ...this.state.resDialog, visible: true, title: `${title}${getLabel(111, "详情")}`, type }
    });
  };
  handleUpdateicon = () => {
    taxdeclarationUpdateIcon({ taxDeclareRecordId: getQueryString("id") })
      .then(({ status, errormsg }) => {
        if (status) {
          message.success(getLabel(502230, "删除成功！"));
        } else {
          message.error(errormsg || getLabel(20462, "删除失败！"));
        }
      });
  };

  render() {
    const { resDialog } = this.state;
    const { declareInfo, onOperate } = this.props;
    const { abnormalSize, declareFailSize } = declareInfo;
    const infoItem = [
      { key: "taxCycle", label: getLabel(542240, "税款所属期") },
      { key: "salaryMonth", label: getLabel(542604, "薪资所属月") },
      { key: "taxAgentName", label: getLabel(537996, "个税扣缴义务人") },
      { key: "declareTypeDesc", label: getLabel(111, "申报类型") },
      { key: "declareStatusDesc", label: getLabel(111, "申报状态") },
      { key: "taxPaidAmount", label: getLabel(111, "已缴金额") }
    ];
    let dropMenuDatas = [];
    if (["DECLARE_SUCCESS_NO_PAY", "DECLARE_SUCCESS_UNPAID", "DECLARE_SUCCESS_PAID", "DECLARE_SUCCESS_PAYING"].includes(declareInfo.declareStatus)) {
      dropMenuDatas = dropMenuDatas.concat([
        {
          key: "exportGetDeclareTaxResultFeedback",
          icon: <i className="icon-coms-download2"/>,
          content: getLabel(111, "下载申报内置算税结果"),
          onClick: onOperate
        },
        {
          key: "onlineComparison",
          icon: <i className="icon-coms-Journal-o"/>,
          content: getLabel(111, "在线对比"),
          onClick: onOperate
        }
      ]);
    }
    return (
      <div className="taxDeclarationInfo_layout">
        <div className="base-info">
          {
            _.map(infoItem, item => {
              return <div className="info-item">
                <span className="label">{item["label"]}：</span>
                <span className="value">
                  {declareInfo[item["key"]]}
                  {
                    (
                      (item["key"] === "declareStatusDesc" && declareInfo["displayIcon"])
                      || (item["key"] === "declareStatusDesc" && declareInfo["declareErrorMsg"])
                    ) &&
                    <span
                      title={declareInfo["declareErrorMsg"] || getLabel(545219, "该个税申报表对应的核算数据被重新核算")}
                      className="icon-span">
                      <Tag closable onClose={this.handleUpdateicon}>
                        <i className="icon-coms02-Warning-01"/>
                      </Tag>
                    </span>
                  }
                </span>
                {
                  item.key === "taxPaidAmount" &&
                  <span className="value">{getLabel(111, "元")}</span>
                }
              </div>;
            })
          }
        </div>
        <div className="weapp-salary-btn-flex tools-line">
          <span className="item"
                onClick={() => this.handleSeeResult([
                  { key: "list4NotDeclare", title: getLabel(111, "待报送") },
                  { key: "list4NoValue", title: getLabel(111, "缺申报数据") }
                ], getLabel(111, "申报校验异常"))}>
            {getLabel(111, "申报校验异常")}（{abnormalSize || 0}）
          </span>
          <span className="item"
                onClick={() => this.handleSeeResult([{ key: "list4Fail" }], getLabel(111, "申报失败数据"))}>
            {getLabel(111, "申报失败数据")}（{declareFailSize || 0}）
          </span>
          <MoreBtnMenu dropMenuDatas={dropMenuDatas}/>
          <DeclareResultDialog
            {...resDialog}
            onCancel={() => {
              this.setState({
                resDialog: { ...resDialog, visible: false, title: "", type: [] }
              });
            }}
          />
        </div>
      </div>
    );
  }
}

export default TaxDeclarationInfo;
