/**
 * 采购回票详情
 */

import { ElButton, ElTag, ElTooltip } from "element-plus";
import { h } from "vue";
import { createTooltip } from "../../tootip";
import { DescriptionColumns } from "/@/components/BasicDescriptions";

import {
  invoiceTypeList,
  seller_check_type,
  buyer_check_type,
  ticketReturnStatusOptions,
  sendTicketReturnStatusOptions,
  invoiceStatusOptions
} from "/@/utils/status";
import { useRenderIcon } from "/@/components/ReIcon/src/hooks";



export const createTicketReturnColumns = ( onClick: Function ): DescriptionColumns => ([
  {
    field: "hpNo",
    label: "对账回票编码"
  },
  {
    field: "status",
    label: "状态",
    render(data) {
      return h(ElTag, null, {
        default: () =>
          ticketReturnStatusOptions.find(s => s.value === String(data))?.label
      });
    }
  },
  {
    field: "apply_name",
    label: "申请人"
  },
  {
    field: "addtime",
    label: "创建时间"
  },
  {
    field: "supplierName",
    span: 12,
    label: "卖方公司名称",
    render(supplierName, { supplierNo }) {
      return createTooltip(supplierName, "卖方公司编码 : " + supplierNo, 360);
    }
  },
  {
    field: "companyName",
    label: "买方公司名称",
    span: 12,
    render(companyName, { companyNo }) {
      return createTooltip(companyName, "买方公司编码 : " + companyNo, 360);
    }
  },
  {
    field: "inv_fee",
    label: "回票金额"
  },
  {
    field: "invoiceType",
    label: "发票类型",
    render(data) {
      return h(ElTag, null, {
        default: () =>
          invoiceTypeList.find(s => s.value === String(data))?.label || "--"
      });
    }
  },

  {
    field: "open_time",
    label: "发票日期"
  },
  {
    field: "invoiceNumber",
    label: "发票号码",
    render(_, context) {
        return h('div', { style: { display: 'flex', 'justify-content': 'space-between', width: '100%' } }, [
          context.invoiceNumber,
          h(ElTooltip, {
            content: '查看发票详情',
            placement: 'top'
          },h(ElButton, {
            style: {'margin-right': '10px'},
            link: true,
            type: 'primary',
            onClick: () => onClick(context),
            icon: useRenderIcon('eye-view')
          }))
        ])
    },
  },

  {
    label: "购买方抬头状态",
    field: "seller_check",
    render(data) {
      return h(
        ElTag,
        {
          type: seller_check_type.find(s => s.value === String(data))
            ?.type as any
        },
        {
          default: () =>
            seller_check_type.find(s => s.value === String(data))?.label || "--"
        }
      );
    }
  },
  {
    field: "inv_subtotal_amount",
    label: "税前总金额"
  },
  {
    field: "invoiceCode",
    label: "发票代码",
    span: 12
  },
  {
    label: "销售方抬头状态",
    field: "buyer_check",
    render(data) {
      return h(
        ElTag,
        {
          type: buyer_check_type.find(s => s.value === String(data))
            ?.type as any
        },
        {
          default: () =>
            buyer_check_type.find(s => s.value === String(data))?.label || "--"
        }
      );
    }
  },
  {
    field: "inv_amount",
    label: "税后总金额"
  },
  {
    field: "checkNumber",
    span: 12,
    label: "校验码"
  },
  {
    field: "remark",
    span: 24,
    label: "审核备注"
  }
]);



export const invoicePoolColumns = [
  {
    field: "InvCode",
    label: "发票编码",
    span: 8
  },
  {
    field: 'apply_name',
    label: '创建人',
    span: 8
  },
  {
    field: 'createTime',
    label: '创建时间',
    span: 8
  },
  {
    label: '买方公司',
    span: 12,
    render(_, { companyNo, companyName }) {
      return createTooltip(companyName, "买方公司编码 : " + companyNo, 360);
    }
  },
  {
    label: '卖方公司',
    span: 12,
    render(_, { supplierNo, supplierName }) {
      return createTooltip(supplierName, "卖方公司编码 : " + supplierNo, 360);
    }
  },
  {
    label: '发票号码',
    field: 'invoice_number'
  },
  {
    label: '发票代码',
    field: 'invoice_code'
  },
  {
    label: '发票类型',
    render(_, { invoice_type }) {
      return h(ElTag, null, {
        default: () =>
          invoiceTypeList.find(s => s.value === String(invoice_type))?.label || "--"
      });
    }
  },
  {
    field: "status",
    label: "状态",
    render(_, { status }) {
      return h(ElTag, null, {
        default: () =>
          invoiceStatusOptions.find(s => s.value === String(status))?.label
      });
    }
  },
  {
    label: '发票税前金额',
    field: 'invoice_subtotal'
  },
  {
    label: '发票税后金额',
    field: 'invoice_total'
  },
  {
    label: '校验码',
    field: 'check_code',
    span: 12
  },
]


export const invoicePoolColumnsTwo = [
  {
    field: "InvCode",
    label: "发票编码",
    span: 6
  },
  {
    field: 'apply_name',
    label: '创建人',
    span: 6
  },
  {
    field: 'createTime',
    label: '创建时间',
    span: 6
  },
  {
    field: "status",
    label: "状态",
    span: 6,
    render(_, { status }) {
      return h(ElTag, null, {
        default: () =>
          invoiceStatusOptions.find(s => s.value === String(status))?.label
      });
    }
  },
  {
    label: '买方公司',
    span: 12,
    render(_, { companyNo, companyName }) {
      return createTooltip(companyName, "买方公司编码 : " + companyNo, 360);
    }
  },
  {
    label: '卖方公司',
    span: 12,
    render(_, { supplierNo, supplierName }) {
      return createTooltip(supplierName, "卖方公司编码 : " + supplierNo, 360);
    }
  }
]


export const ticketReturnColumns: DescriptionColumns = [
  {
    field: "hpNo",
    label: "对账回票编码"
  },
  {
    field: "status",
    label: "状态",
    render(data) {
      return h(ElTag, null, {
        default: () =>
          ticketReturnStatusOptions.find(s => s.value === String(data))?.label
      });
    }
  },
  {
    field: "apply_name",
    label: "申请人"
  },
  {
    field: "addtime",
    label: "创建时间"
  },
  {
    field: "supplierName",
    span: 12,
    label: "卖方公司名称",
    render(supplierName, { supplierNo }) {
      return createTooltip(supplierName, "卖方公司编码 : " + supplierNo, 360);
    }
  },
  {
    field: "companyName",
    label: "买方公司名称",
    span: 12,
    render(companyName, { companyNo }) {
      return createTooltip(companyName, "买方公司编码 : " + companyNo, 360);
    }
  },
  {
    field: "inv_fee",
    label: "回票金额"
  },
  {
    field: "invoiceType",
    label: "发票类型",
    render(data) {
      return h(ElTag, null, {
        default: () =>
          invoiceTypeList.find(s => s.value === String(data))?.label || "--"
      });
    }
  },

  {
    field: "open_time",
    label: "发票日期"
  },
  {
    field: "invoiceNumber",
    label: "发票号码"
  },

  {
    label: "购买方抬头状态",
    field: "seller_check",
    render(data) {
      return h(
        ElTag,
        {
          type: seller_check_type.find(s => s.value === String(data))
            ?.type as any
        },
        {
          default: () =>
            seller_check_type.find(s => s.value === String(data))?.label || "--"
        }
      );
    }
  },
  {
    field: "inv_subtotal_amount",
    label: "税前总金额"
  },
  {
    field: "invoiceCode",
    label: "发票代码",
    span: 12
  },
  {
    label: "销售方抬头状态",
    field: "buyer_check",
    render(data) {
      return h(
        ElTag,
        {
          type: buyer_check_type.find(s => s.value === String(data))
            ?.type as any
        },
        {
          default: () =>
            buyer_check_type.find(s => s.value === String(data))?.label || "--"
        }
      );
    }
  },
  {
    field: "inv_amount",
    label: "税后总金额"
  },
  {
    field: "checkNumber",
    span: 12,
    label: "校验码"
  },
  {
    field: "remark",
    span: 24,
    label: "审核备注"
  }
];

export const sendTicketReturnColumns: DescriptionColumns = [
  {
    field: "hpNo",
    label: "对账回票编码"
  },
  {
    field: "status",
    label: "状态",
    render(data) {
      return h(ElTag, null, {
        default: () =>
          sendTicketReturnStatusOptions.find(s => s.value === String(data))?.label
      });
    }
  },
  {
    field: "apply_name",
    label: "申请人"
  },
  {
    field: "addtime",
    label: "创建时间"
  },
  {
    field: "supplierName",
    span: 12,
    label: "物流供应商名称",
    render(supplierName, { supplierNo }) {
      return createTooltip(supplierName, "物流供应商编码 : " + supplierNo, 360);
    }
  },
  {
    field: "companyName",
    label: "业务公司",
    span: 12,
    render(companyName, { companyNo }) {
      return createTooltip(companyName, "业务公司 : " + companyNo, 360);
    }
  },
  {
    field: "inv_fee",
    label: "回票金额"
  },
  {
    field: "invoiceType",
    label: "发票类型",
    render(data) {
      return h(ElTag, null, {
        default: () =>
          invoiceTypeList.find(s => s.value === String(data))?.label || "--"
      });
    }
  },

  {
    field: "open_time",
    label: "发票日期"
  },
  {
    field: "invoiceNumber",
    label: "发票号码"
  },

  {
    label: "购买方抬头状态",
    field: "seller_check",
    render(data) {
      return h(
        ElTag,
        {
          type: seller_check_type.find(s => s.value === String(data))
            ?.type as any
        },
        {
          default: () =>
            seller_check_type.find(s => s.value === String(data))?.label || "--"
        }
      );
    }
  },
  {
    field: "inv_subtotal_amount",
    label: "税前总金额"
  },
  {
    field: "invoiceCode",
    label: "发票代码",
    span: 12
  },
  {
    label: "销售方抬头状态",
    field: "buyer_check",
    render(data) {
      return h(
        ElTag,
        {
          type: buyer_check_type.find(s => s.value === String(data))
            ?.type as any
        },
        {
          default: () =>
            buyer_check_type.find(s => s.value === String(data))?.label || "--"
        }
      );
    }
  },
  {
    field: "inv_amount",
    label: "税后总金额"
  },
  {
    field: "checkNumber",
    span: 12,
    label: "校验码"
  },
  {
    field: "remark",
    span: 24,
    label: "审核备注"
  }
];

