// 开票历史记录--日志弹窗
import React, { Component } from "react";
import { Button, message, Modal, Spin, Table } from "antd";
import { ShowModal } from "../../tools";
import $ from "jquery/src/ajax";

class LogPopup extends Component {
  constructor(props) {
    super(props);
    this.state = {
      visible: false,
      columnsDate: [
        {
          title: "编号",
          dataIndex: "id",
          key: "id",
        },
        {
          title: "操作人",
          dataIndex: "adminName",
          key: "adminName",
        },
        {
          title: "操作时间",
          dataIndex: "createTimes",
          key: "createTimes",
        },
        {
          title: "操作",
          dataIndex: "status",
          key: "status",
          render: (text, record) => {
            return (
              <div>
                {
                  [
                    "发起",
                    "开票通过",
                    "开票拒绝",
                    "特批通过",
                    "特批拒绝",
                    "修改提交",
                  ][text]
                }
              </div>
            );
          },
        },
      ],
      recordData: [],
    };
  }

  componentDidMount() {}

  getData() {
    $.ajax({
      method: "get",
      dataType: "json",
      crossDomain: false,
      url: globalConfig.context + "/api/admin/orderInvoice/invoice/log",
      data: {
        id: this.props.id,
      },
      success: function (data) {
        ShowModal(this);
        let theArr = [];
        if (!data.data) {
          if (data.error && data.error.length) {
            message.warning(data.error[0].message);
          }
        } else {
          this.setState({
            recordData: data.data,
          });
        }
      }.bind(this),
    }).always(
      function () {
        this.setState({
          loading: false,
        });
      }.bind(this)
    );
  }

  render() {
    return (
      <span>
        <Button
          type="primary"
          onClick={(e) => {
            e.stopPropagation();
            this.getData();
            this.setState({
              visible: true,
            })
          }}
          style={{ marginLeft: "10px" }}
        >
          日志
        </Button>
        <Modal
          maskClosable={false}
          visible={this.state.visible}
          footer=""
          title="开票日志"
          className="admin-desc-content"
          width="600px"
          onCancel={(e) => {
            this.setState({
              visible: false,
            });
          }}
          style={{ zIndex: 10 }}
        >
          <Spin spinning={this.state.loading}>
            <div className="patent-table">
              <Table
                columns={this.state.columnsDate}
                dataSource={this.state.recordData || []}
                pagination={false}
              />
            </div>
          </Spin>
        </Modal>
      </span>
    );
  }
}

export default LogPopup;
