/**
 * 开票申请详情
 */
import { h } from "vue";
import { ElTable, ElTableColumn, ElTag } from "element-plus";
import { DescriptionColumns } from "/@/components/BasicDescriptions";
import { createTooltip } from "/@/utils/tootip";
import { invoiceApplyStatusOptions, invoiceTypeList } from "/@/utils/status";

export const INV_TYPE = [
  { value: "1", label: "纸质专用发票", type: "primary" },
  { value: "2", label: "纸质普通发票", type: "success" },
  { value: "3", label: "电子普通发票", type: "primary" },
  { value: "4", label: "电子专用发票", type: "success" }
];

export const OPEN_TYPE = [
  { value: "1", label: "金税开票" },
  { value: "2", label: "金税线下" },
  { value: "3", label: "纯线下" }
];

// export const INV_OPEN_STATUS = [
//   { value: "0", label: "待财务开票/待金税开票", type: "" },
//   { value: "1", label: "待财务审核", type: "warning" },
//   { value: "2", label: "开票中/验票", type: "warning" },
//   { value: "3", label: "开票完成", type: "warning" },
//   { value: "4", label: "财务驳回 ", type: "warning" },
//   { value: "5", label: "开票失败/开票驳回", type: "warning" },
//   { value: "6", label: "退票/废弃", type: "warning" }
// ];

export const invOpenColumns: DescriptionColumns = [
  {
    field: "invNo",
    label: "发票编码",
    span: 2,
    labelWidth: "100px"
  },
  {
    field: "seller_title",
    label: "开票业务公司",
    span: 2,
    render: (seller_title, { inv_out }) =>
      createTooltip(seller_title, "业务公司编码 : " + inv_out, 300)
  },
  {
    field: "inv_in",
    span: 2,
    label: "客户公司"
  },
  {
    field: "inv_value",
    label: "发票金额"
  },
  {
    field: "apply_name",
    label: "申请人",
    render: (apply_name, { apply_id }) =>
      createTooltip(apply_name, "申请人ID : " + apply_id, 90)
  },
  {
    field: "status",
    label: "开票状态",
    render(data) {
      return h(
        ElTag,
        {
          type: invoiceApplyStatusOptions.find(s => s.value === String(data))
            ?.type as any
        },
        {
          default: () =>
            invoiceApplyStatusOptions.find(s => s.value === String(data))
              ?.label || "--"
        }
      );
    }
  },
  {
    field: "inv_type",
    label: "发票类型",
    render(data) {
      return h(ElTag, null, {
        default: () =>
          invoiceTypeList.find(t => t.value === String(data))?.label || "--"
      });
    }
  },
  {
    field: "open_type",
    label: "开票方式",
    render(data) {
      return h(ElTag, null, {
        default: () =>
          OPEN_TYPE.find(t => t.value === String(data))?.label || "--"
      });
    }
  },
  {
    field: "is_ticket",
    label: "是否支持金税",
    render(data) {
      return h(ElTag, null, {
        default: () => (data === "0" ? "不支持" : "支持")
      });
    }
  },

  {
    field: "winv_fee",
    label: "未开票"
  },
  {
    field: "ainv_fee",
    label: "已开票"
  },
  {
    field: "email",
    span: 2,
    label: "电子邮箱"
  },
  {
    field: "post_code",
    label: "快递编码",
    span: 2
  },
  {
    field: "post_company",
    label: "快递公司",
    span: 2
  },
  {
    field: "post_fee",
    span: 2,
    label: "快递费"
  },
  {
    field: "buyer_title",
    label: "买方抬头",
    span: 2
  },
  {
    field: "buyer_code",
    label: "买方纳税识别号",
    span: 2
  },
  {
    field: "buyer_addr",
    label: "买方注册地址",
    span: 2
  },
  {
    field: "buyer_mobile",
    label: "买方联系方式",
    span: 2
  },
  {
    field: "buyer_bank",
    label: "买方银行",
    span: 2
  },
  {
    field: "seller_title",
    label: "销售方抬头",
    span: 2
  },
  {
    field: "seller_code",
    label: "销售方纳税识别号",
    span: 2
  },
  {
    field: "seller_addr",
    label: "销售方地址",
    span: 2
  },
  {
    field: "seller_mobile",
    label: "销售方联系方式",
    span: 2
  },
  {
    field: "seller_bank",
    label: "销售方银行",
    span: 2
  },
  {
    field: "seller_bankNo",
    label: "销售方账户",
    span: 2
  },
  {
    field: "voider",
    label: "作废人"
  },
  {
    field: "payee",
    label: "收款人"
  },
  {
    field: "drawer",
    label: "开票人"
  },
  {
    field: "reviewer",
    label: "复核人"
  },
  {
    field: "exam_remark",
    label: "审核备注",
    span: 6
  },
  {
    field: "remark",
    label: "发票备注",
    span: 6
  },
  {
    field: "cancel_fee",
    label: "订单信息:",
    render(_, { orderinfo }) {
      return h(
        ElTable,
        {
          data: orderinfo,
          border: true,
          size: "small"
        },
        {
          default: () => [
            h(ElTableColumn, {
              prop: "orderCode",
              label: "编码",
              width: "180px",
              showOverflowTooltip: true
            }),
            h(ElTableColumn, {
              prop: "goodName",
              label: "商品名称",
              showOverflowTooltip: true
            }),
            h(ElTableColumn, {
              prop: "goodPrice",
              label: "商品单价",
              showOverflowTooltip: true
            }),
            h(ElTableColumn, {
              prop: "goodNum",
              label: "商品数量",
              showOverflowTooltip: true
            }),
            h(
              ElTableColumn,
              {
                prop: "catInfo",
                label: "分类",
                showOverflowTooltip: true
              },
              {
                default: ({ row }) =>
                  JSON.parse(row.catInfo)
                    .map(({ cat_name }) => cat_name)
                    .join("/")
              }
            ),
            h(ElTableColumn, {
              prop: "cancel_fee",
              showOverflowTooltip: true,
              label: "开票金额"
            }),
            h(
              ElTableColumn,
              {
                prop: "tax",
                showOverflowTooltip: true,
                label: "税率"
              },
              {
                default: ({ row }) => row.tax + "%"
              }
            )
          ]
        }
      );
    }
  }
];

export const ORDER_COLUMNS = [
  {
    field: "invNo",
    label: "发票编码"
  },
  {
    field: "inv_value",
    label: "发票金额"
  },
  {
    field: "buyer_title",
    label: "开票公司",
    render: (buyer_title, { inv_out }) =>
      createTooltip(buyer_title, "开票公司编码 : " + inv_out, 360)
  },
  {
    field: "buyer_title",
    label: "客户公司"
  },
  {
    field: "apply_name",
    label: "申请人"
  },
  {
    field: "status",
    label: "开票状态",
    render(data) {
      return h(
        ElTag,
        {
          type: invoiceApplyStatusOptions.find(s => s.value === data)
            ?.type as any
        },
        {
          default: () =>
            invoiceApplyStatusOptions.find(s => s.value === data)?.label || "--"
        }
      );
    }
  },
  {
    field: "inv_type",
    label: "发票类型",
    render(data) {
      return h(
        ElTag,
        {
          type: invoiceTypeList.find(s => s.value === data)?.type as any
        },
        {
          default: () => {
            return invoiceTypeList.find(t => t.value === data)?.label || "--";
          }
        }
      );
    }
  },
  {
    field: "open_type",
    label: "开票方式",
    render(data) {
      return h(ElTag, null, {
        default: () => OPEN_TYPE.find(t => t.value === data)?.label || "--"
      });
    }
  },
  {
    field: "is_ticket",
    label: "是否支持金税",
    render(data) {
      return h(ElTag, null, {
        default: () => (data === "0" ? "不支持" : "支持")
      });
    }
  },
  {
    field: "exam_remark",
    label: "审核备注"
  },
  {
    field: "remark",
    label: "备注"
  },
  {
    field: "email",
    label: "电子邮箱"
  },
  {
    field: "winv_fee",
    label: "未开票"
  },
  {
    field: "ainv_fee",
    label: "已开票"
  },
  {
    field: "post_fee",
    label: "快递费"
  },
  {
    field: "post_code",
    label: "快递编码"
  },
  {
    field: "post_company",
    label: "快递公司"
  }
];

export const INVOICE_COLUMNS = [
  {
    field: "buyer_title",
    label: "买方抬头"
  },
  {
    field: "buyer_code",
    label: "买方纳税识别号"
  },
  {
    field: "buyer_addr",
    label: "买方注册地址"
  },
  {
    field: "buyer_mobile",
    label: "买方联系方式"
  },
  {
    field: "buyer_bank",
    label: "买方银行"
  },
  {
    field: "seller_title",
    label: "销售方抬头"
  },
  {
    field: "seller_code",
    label: "销售方纳税识别号"
  },
  {
    field: "seller_addr",
    label: "销售方地址"
  },
  {
    field: "seller_mobile",
    label: "销售方联系方式"
  },
  {
    field: "seller_bank",
    label: "销售方银行"
  },
  {
    field: "seller_bankNo",
    label: "销售方账户"
  },
  {
    field: "voider",
    label: "作废人"
  },
  {
    field: "payee",
    label: "收款人"
  },
  {
    field: "drawer",
    label: "开票人"
  },
  {
    field: "reviewer",
    label: "复核人"
  }
];
