/*
 * Author: 黎永顺
 * name: 薪资核算-人员异常
 * Description:
 * Date: 2023/8/18
 */
import React, { Component } from "react";
import { WeaDialog, WeaLocaleProvider, WeaTable } from "ecCom";
import { listPage4NotDeclare } from "../../../../../apis/calculate";

const { getLabel } = WeaLocaleProvider;

class PersonAbnormalDialog 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.queryList(nextProps);
  }

  queryList = (props) => {
    const { salaryAcctRecordId } = props, { pageInfo } = this.state;
    const payload = { ...pageInfo, recordId: salaryAcctRecordId };
    this.setState({ loading: true });
    listPage4NotDeclare(payload).then(({ status, data }) => {
      this.setState({ loading: false });
      if (status) {
        const { columns, list: dataSource, pageNum: current, pageSize, total } = data;
        this.setState({
          dataSource, pageInfo: { ...pageInfo, current, pageSize, total }, columns
        });
      } else {

      }
    }).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.queryList(this.props));
      },
      onChange: current => {
        this.setState({
          pageInfo: { ...pageInfo, current }
        }, () => this.queryList(this.props));
      }
    };
    return (
      <WeaDialog
        {...this.props}
        scalable hasScroll className="declareResultDialog" initLoadCss
        title={getLabel(111, "未报送人员")} ref={dom => this.errorRef = dom}
        style={{
          width: 1150, height: 606.6, minHeight: 200, minWidth: 380, maxHeight: "90%",
          maxWidth: "90%", overflow: "hidden", transform: "translate(0px, 0px)"
        }}
      >
        <div className="declareResultDialogContent">
          <WeaTable
            columns={columns} dataSource={dataSource}
            loading={loading} className="declareTable"
            pagination={pagination} scroll={{ y: this.errorRef ? this.errorRef.state.height - 124 : 600 }}
          />
        </div>
      </WeaDialog>
    );
  }
}

export default PersonAbnormalDialog;
