import React, { Component } from "react";
import TabelContent from "../../../common/tabelContent";
import LegalRecd from "../collectioning/legalRecd";
import DunningRecord from "../../order/pressMoney/dunningRecord";
import { Form, Button, message } from "antd";
import $ from "jquery/src/ajax";
class CompletedLegalAffairs extends Component {
  constructor(props) {
    super(props);
    this.state = {
      columns: [
        {
          title: "序号",
          dataIndex: "key",
          key: "key",
          width: 45,
        },
        {
          title: "合同编号",
          dataIndex: "contractNo",
          key: "contractNo",
          width: 70,
        },
        {
          title: "客户名称",
          dataIndex: "buyerName",
          key: "buyerName",
          width: 150,
        },
        {
          title: "订单负责人",
          dataIndex: "salesmanName",
          key: "salesmanName",
          width: 120,
        },
        {
          title: "订单部门",
          dataIndex: "depName",
          key: "depName",
          width: 120,
        },
        {
          title: "签单金额（万元）",
          dataIndex: "totalAmount",
          key: "totalAmount",
          width: 80,
        },
        {
          title: "已收款（万元）",
          dataIndex: "settlementAmount",
          key: "settlementAmount",
          width: 80,
        },
        {
          title: "欠款（万元）",
          dataIndex: "orderArrears",
          key: "orderArrears",
          width: 80,
        },
        {
          title: "法务类型",
          dataIndex: "type",
          key: "type",
          width: 80,
        },
        {
          title: "法务时间",
          dataIndex: "operationDate",
          key: "operationDate",
          width: 125,
        },
        {
          title: "操作",
          dataIndex: "id",
          key: "id",
          width: 290,
          render: (text, record, index) => {
            let _this = this;
            return (
              <div style={{ display: "flex", alignItems: "center" }}>
                <Button
                  disabled={record.daysRemaining === 0}
                  type="primary"
                  style={{ marginRight: "10px" }}
                  onClick={(e) => {
                    this.setState({
                      visible: true,
                      dataInfor: record,
                    });
                  }}
                >
                  催款记录
                </Button>
                {/* 法务记录 */}
                <Button
                  type="primary"
                  style={{ marginRight: "10px" }}
                  onClick={(e) => {
                    e.stopPropagation();
                    this.setState({
                      visibleRecd: true,
                      dataInfor: record,
                    });
                  }}
                >
                  法务记录
                </Button>
              </div>
            );
          },
        },
      ],
      searchList: [
        {
          type: "text",
          dataKey: "userName",
          placeholder: "请输入客户名称",
        },
        {
          type: "text",
          dataKey: "contractNo",
          placeholder: "请输入合同编号",
        },
        {
          type: "autoComplete",
          dataKey: "aid",
          api: "/api/admin/customer/listAdminByName",
          search: "adminName",
          placeholder: "请输入营销人名称",
        },
        {
          type: "newDepartmentSelect",
          dataKey: "deps",
          placeholder: "请选择订单部门",
        },
        {
          type: "times",
          title: "法务时间",
          dataKey: ["startTime", "endTime"],
        },
        {
          type: "types",
          title: "法务类型",
          dataKey: "status",
          placeholder: "请选择法务类型",
        },
      ],
      visibleRecd: false,
      visible: false,
      adminHid:"inline-block"
    };
    this.onFresh = this.onFresh.bind(this); 
  }
  onFresh() {
    this.setState({
      visibleRecd: false,
    });
    this.tabelContentRef && this.tabelContentRef.onRefresh();
  }
  componentDidMount() {
    if(!adminData.isLegal) {
      this.setState({
        adminHid:"none"
      })
      console.log(adminData.isLegal);
    }
  }
  render() {
    return (
      <div className="user-content signatureStatistics">
        <div className="content-title">
          <span>已完成法务</span>
        </div>
        <TabelContent
          ref={(ref) => (this.tabelContentRef = ref)}
          scroll={{ x: 0, y: 1000 }}
          searchList={this.state.searchList}
          columns={this.state.columns}
          tabelApi={"/api/admin/lagalAffairs/orderList"}
          exportApi={"/api/admin/lagalAffairs/orderList/Exprot"}
          query={{ type: 3 }}
          //修改type类型
          exportExecProcessing={(data) => {
            data.type = 3;
            return data;
          }}
          dataProcessing={(data) => {
            let theArr = [];
            for (let i = 0; i < data.data.list.length; i++) {
              let thisdata = data.data.list[i];
              thisdata.key = i + 1;

             let status;
              if (thisdata.status == 0) {
                status = "否";
              } else if (thisdata.status == 1) {
                status = "已回款";
              } else if (thisdata.status == 2) {
                status = "已诉讼";
              } else if (thisdata.status == 3) {
                status = "已坏账处理";
              }
              // console.log(status);
              //
              if (thisdata.type == 0) {
                thisdata.type = "法务催收中";
              } else if (thisdata.type == 1) {
                thisdata.type = "延期法务";
              } else if (thisdata.type == 2) {
                thisdata.type = `已完成法务/${status || ''}`;
              } else if (thisdata.type == 3) {
                thisdata.type = "自动转交";
              } else if (thisdata.type == 4) {
                thisdata.type = "营销转交";
              }
              theArr.push(thisdata);
            }
            return theArr;
          }}
          onRowClick={this.tableRowClick}
        />
        {this.state.visibleRecd && (
          <LegalRecd
            hid={this.state.adminHid}
            searchList={this.state.searchList}
            dataInfor={this.state.dataInfor}
            onFresh={this.onFresh}
            visibleRecd={this.state.visibleRecd}
            modelBack={this.modelBack}
            onCancel={() => {
              this.setState({
                visibleRecd: false,
                dataInfor: {},
              });
            }}
          />
        )}
        {this.state.visible ? (
          <DunningRecord
            hid={"none"}
            dataInfor={this.state.dataInfor}
            visible={this.state.visible}
            onCancel={() => {
              this.setState({
                visible: false,
                dataInfor: {},
              });
            }}
          />
        ) : (
          ""
        )}
      </div>
    );
  }
}
export default CompletedLegalAffairs;
