import React from "react";
import { Popover, Table } from "antd";
import { useStore } from "../index";
import { CompanyCategoryTypeEnum, ExpireRepayRuleEnum } from "@/pages/finance/entitys";
import rmb from "@/utils/rmb";
import { ExclamationCircleFilled } from "@ant-design/icons";

const { Column } = Table;

enum DepositPayMethodEnum {
  "前期一次性支付" = 1,
  "每张票支付",
}

export default function SalesFinanceList() {
  const { setCurrent, setVisible, companyList, loading } = useStore();

  return (
    <Table dataSource={companyList} rowKey="compId" pagination={false} loading={loading} scroll={{ x: 1400 }}>
      <Column
        title="公司名称"
        dataIndex="compName"
        fixed="left"
        render={(name, row: SpecialAccount.Companylist) => `${name}(${CompanyCategoryTypeEnum[row.compCategory!]})`}
        width={120}
      />

      <Column
        title={
          <Popover
            placement="topLeft"
            content={
              <div>
                <p>
                  <span style={{ color: "red" }}>提示：</span>
                  <span>保证金指真实的保证金，而非票据保证金账户上的钱</span>
                </p>
              </div>
            }
          >
            <span>
              还款保证金账户&nbsp;&nbsp;
              <ExclamationCircleFilled style={{ color: "#40a9ff" }} />
            </span>
          </Popover>
        }
        dataIndex="depositAccountName"
        align="center"
        render={(name) => name || "-"}
        width={120}
      />

      <Column title="一般账户" dataIndex="accountName" width={120} />
      <Column title="还款账户" dataIndex="repayAccountName" width={120} />
      <Column title="最大授信额度(元)" dataIndex="maxCreditQuota" render={(count) => count.toFixed(2)} width={120} />
      <Column
        title="保证金固定金额或比例"
        dataIndex="depositValue"
        render={(count, row: SpecialAccount.Companylist) => `${rmb.p(count)}${row.depositType == 1 ? "元" : "%"}`}
        width={120}
      />
      <Column title="保证金支付方式" dataIndex="depositPayMethod" render={(v) => DepositPayMethodEnum[v]} width={120} />
      <Column title="出票手续费(%)" dataIndex="billServiceFee" render={(count) => `${count.toFixed(2)}%`} width={120} />
      <Column title="期限(自然月)" dataIndex="billLimitDates" render={(m) => (m ? `${m}个月` : "-")} width={120} />
      <Column
        title="票据到期提前还款天数"
        dataIndex="repayAdvanceDays"
        render={(d) => (d ? `${d}个工作日` : "-")}
        width={120}
      />
      {/* 票据到期还款推送 */}
      <Column
        title={
          <Popover
            placement="topLeft"
            content={
              <>
                <p> 票据内剩余总金额=票据内已还款总金额-票据到期金额</p>
                <p> 票据内剩余总金额≥0，不推票据到期还款待办</p>
                <p>票据内剩余总金额＜0，推票据到期还款待办，金额对应为票据内剩余总金额</p>
              </>
            }
          >
            <span>
              票据到期还款推送&nbsp;&nbsp;
              <ExclamationCircleFilled style={{ color: "#40a9ff" }} />
            </span>
          </Popover>
        }
        dataIndex="expireRepayRule"
        render={(d: number) => d && ExpireRepayRuleEnum[d]}
        width={120}
      />

      <Column title="是否支持票转贷" dataIndex="toLoan" width={120} render={(val) => (val ? "支持" : "不支持")} />
      <Column
        title="票转贷最长期限"
        dataIndex="toLoanDueTime"
        render={(v, r: SpecialAccount.Companylist) => (r.toLoan ? `${v}${r.toLoanDueTimeTypeName}` || "-" : "-")}
        width={120}
      />
      <Column
        title="票转贷年利率(%)"
        dataIndex="billTransferInterest"
        render={(count, row: any) => (row.toLoan ? (count ? `${count.toFixed(2)}%` : "-") : "-")}
        width={120}
      />
      <Column
        title="票转贷结息日"
        dataIndex="interestSettleDay"
        render={(day, row: any) => (row.toLoan ? (day ? `每月${day}日` : "-") : "-")}
        width={120}
      />
      <Column
        title="票转贷还款提前天数"
        dataIndex="toLoanRepayAdvanceDays"
        render={(day, row: any) => (row.toLoan ? (day ? `${day || 0}工作日` : "-") : "-")}
        width={120}
      />
      <Column title="是否支持贷款启票" dataIndex="loan" width={120} render={(val) => (val ? "支持" : "不支持")} />
      <Column
        title="贷款启票年利率(%)"
        dataIndex="loanInterest"
        render={(count, row: any) => (row.loan ? (count ? `${count.toFixed(2)}%` : "-") : "-")}
        width={120}
      />
      <Column
        title="贷款启票结息日"
        dataIndex="loanRepayAdvanceDays"
        render={(day, row: any) => (row.loan ? (day ? `每月${day}日` : "-") : "-")}
        width={120}
      />
      <Column
        title="贷款启票还款提前天数"
        dataIndex="loanInterestSettleDay"
        render={(day, row: any) => (row.loan ? (day ? `${day || 0}工作日` : "-") : "-")}
        width={120}
      />
      <Column
        title="操作"
        align="center"
        render={(text, record: SpecialAccount.Companylist) => (
          <>
            <a
              onClick={(e) => {
                e.preventDefault();
                setCurrent(record);
                setVisible(true);
              }}
            >
              编辑
            </a>
          </>
        )}
        width={180}
      />
    </Table>
  );
}
