/*
 * Author: 黎永顺
 * name: 报送信息-失败查看弹框
 * Description:
 * Date: 2023/8/14
 */
import React, { Component } from "react";
import { WeaDialog, WeaLocaleProvider, WeaTable } from "ecCom";
import { employeedeclareList4Fail } from "../../../apis/declare";
import { Button, Col, Row } from "antd";
import { getQueryString } from "../../../util/url";

const { getLabel } = WeaLocaleProvider;

class EmployeeDeclareDetailCalcDialog extends Component {
  constructor(props) {
    super(props);
    this.state = {
      pageInfo: { current: 1, pageSize: 10, total: 0 },
      loading: false, columns: [], dataSource: []
    };
  }

  componentWillReceiveProps(nextProps, nextContext) {
    if (nextProps.visible !== this.props.visible && nextProps.visible) this.employeedeclareList4Fail(nextProps);
  }

  employeedeclareList4Fail = (props) => {
    const { pageInfo } = this.state;
    const payload = {
      ...pageInfo,
      taxAgentId: getQueryString("id"),
      taxCycle: props.taxCycle
    };
    this.setState({ loading: true });
    employeedeclareList4Fail(payload).then(({ status, data }) => {
      this.setState({ loading: false });
      if (status) {
        const { columns, list: dataSource, pageNum: current, pageSize, total } = data;
        this.setState({
          columns, dataSource,
          pageInfo: { ...pageInfo, current, pageSize, total }
        });
      }
    }).catch(() => this.setState({ loading: false }));
  };

  render() {
    const { loading, columns, dataSource, pageInfo } = this.state;
    const pagination = {
      ...pageInfo,
      showTotal: total => `${getLabel(18609, "共")} ${total} ${getLabel(18256, "条")}`,
      showQuickJumper: true,
      showSizeChanger: true,
      pageSizeOptions: ["10", "20", "50", "100"],
      onShowSizeChange: (current, pageSize) => {
        this.setState({
          pageInfo: { ...pageInfo, current, pageSize }
        }, () => this.employeedeclareList4Fail(this.props));
      },
      onChange: current => {
        this.setState({
          pageInfo: { ...pageInfo, current }
        }, () => this.employeedeclareList4Fail(this.props));
      }
    };
    return (
      <WeaDialog
        {...this.props}
        scalable hasScroll className="declareCalcDialog" initLoadCss
        title={(<Row className="declareCalcDialogTitle" type="flex">
          <Col span={12} className="declareCalcDialogTitle-left">
            <span className="title">{getLabel(111, "报送失败数据详情")}</span>
          </Col>
          <Col span={12} className="declareCalcDialogTitle-right">
            {/*<Button type="primary" onClick={this.handleSubmit}>{getLabel(81272, "导出全部")}</Button>*/}
          </Col>
        </Row>)}
        style={{
          width: 1150,
          height: 606.6,
          minHeight: 200,
          minWidth: 380,
          maxHeight: "90%",
          maxWidth: "90%",
          overflow: "hidden",
          transform: "translate(0px, 0px)"
        }}
      >
        <div className="declareCalcDialogContent">
          <WeaTable
            columns={columns} dataSource={dataSource}
            loading={loading} className="declareTable"
            pagination={pagination}
          />
        </div>
      </WeaDialog>
    );
  }
}

export default EmployeeDeclareDetailCalcDialog;
