/* eslint-disable prettier/prettier */
/**
 * 开票申请详情
 */
import { h } from "vue";
import {
  ElButton,
  ElPopover,
  ElTable,
  ElTableColumn,
  ElTag
} from "element-plus";
import { DescriptionColumns } from "/@/components/BasicDescriptions";
import { createTooltip } from "../tootip";

import {
  invoiceTypeList,
  seller_check_type,
  buyer_check_type,
  inv_type_list
} from "../status";
import { useRenderIcon } from "/@/components/ReIcon/src/hooks";

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" },
  { value: "7", label: "已取消申请", type: "warning" },
  { value: "8", label: "财务驳回", type: "warning" },
  { value: "9", label: "验票失败", type: "warning" }
];

export const INV_OPEN_COLUMNS: DescriptionColumns = [
  {
    field: "invNo",
    label: "发票编码",
    labelWidth: "100px"
  },

  {
    field: "inv_value",
    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 || "--"
        }
      );
    }
  },
  {
    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: "status",
    label: "开票状态",
    render(data, { status, check_remark }) {
      return h(
        "div",
        {},
        {
          default: () => [
            h(
              ElTag,
              {
                type: INV_OPEN_STATUS.find(s => s.value === data)?.type as any
              },
              {
                default: () =>
                  INV_OPEN_STATUS.find(s => s.value === data)?.label || "--"
              }
            ),
            String(status) !== "5"
              ? null
              : h(
                ElPopover,
                {
                  placement: "top",
                  content: `异常原因 : ${check_remark}`,
                  width: "300px"
                },
                {
                  reference: () =>
                    h(ElButton, {
                      link: true,
                      icon: useRenderIcon("information-line")
                    })
                }
              )
          ]
        }
      );
    }
  },
  {
    field: "inv_type",
    label: "发票类型",
    render(data, context) {
      return h(ElTag, null, {
        default: () => {
          return (
            invoiceTypeList.find(t => t.value === String(data))?.label || "--"
          );
        }
      });
    }
  },
  {
    field: "open_type",
    label: "开票方式",
    render(data) {
      return h(ElTag, null, {
        default: () => {
          return OPEN_TYPE.find(t => t.value === String(data))?.label || "--";
        }
      });
    }
  },
  {
    field: "is_ticket",
    label: "是否支持金税",
    render(data) {
      return h(ElTag, null, {
        default: () =>
          String(data) === "2" ? "不支持" : String(data) === "1" ? "支持" : "--"
      });
    }
  },
  {
    field: "inv_company",
    label: "销售方公司编码",
    span: 12,
    render: (inv_company, { inv_out }) =>
      createTooltip(inv_company, "销售方公司编码 : " + inv_out, 300)
  },
  {
    field: "email",
    label: "电子邮箱"
  },
  {
    field: "post_code",
    label: "快递编码",
    render: (post_code, { post_company }) =>
      createTooltip(post_code, "快递公司 : " + post_company, 300)
  },
  // {
  //   field: "post_company",
  //   label: "快递公司"
  // },
  // {
  //   field: "post_fee",
  //   label: "快递费"
  // },
  {
    field: "seller_title",
    label: "销售方抬头",
    span: 12,
    render: (seller_title, { seller_code }) =>
      createTooltip(seller_title, "纳税人识别号 : " + seller_code, 300)
  },

  {
    field: "buyer_title",
    label: "购买方抬头",
    span: 12,
    render: (buyer_title, { buyer_code }) =>
      createTooltip(buyer_title, "纳税人识别号 : " + buyer_code, 300)
  },

  {
    field: "seller_bank",
    label: "销售方银行",
    span: 12,
    render: (seller_bank, { seller_bankNo }) =>
      createTooltip(seller_bank, "销售方账户 : " + seller_bankNo, 300)
  },

  {
    field: "buyer_bank",
    label: "购买方银行",
    span: 12,
    render: (buyer_bank, { buyer_bankNo }) =>
      createTooltip(buyer_bank, "购买方账户 : " + buyer_bankNo, 300)
  },
  {
    field: "seller_addr",
    label: "销售方地址",
    span: 12,
    render: (seller_addr, { seller_mobile }) =>
      createTooltip(seller_addr, "销售方联系方式 : " + seller_mobile, 300)
  },
  {
    field: "buyer_addr",
    label: "购买方地址",
    span: 12,
    render: (buyer_addr, { buyer_mobile }) =>
      createTooltip(buyer_addr, "购买方联系方式 : " + buyer_mobile, 300)
  },
  {
    field: "voider",
    label: "作废人"
  },
  {
    field: "payee",
    label: "收款人"
  },
  {
    field: "drawer",
    label: "开票人"
  },
  {
    field: "reviewer",
    label: "复核人"
  },

  {
    field: "cancel_fee",
    label: "订单信息:",
    span: 24,
    render(_, { orderinfo }) {
      return h(
        ElTable,
        {
          data: orderinfo,
          border: true,
          size: "small",
          width: "100%"
        },
        {
          default: () => [
            h(ElTableColumn, {
              prop: "sequenceNo",
              label: "订单编码",
              width: "150px",
              fixed: "left",
              showOverflowTooltip: true
            }),
            h(ElTableColumn, {
              prop: "goodName",
              label: "商品名称",
              "min-width": "110px",
              showOverflowTooltip: true
            }),

            h(
              ElTableColumn,
              {
                prop: "tax",
                showOverflowTooltip: true,
                label: "税率",
                width: "50px"
              },
              {
                default: ({ row }) => row.tax + "%"
              }
            ),
            h(ElTableColumn, {
              prop: "goodPrice",
              label: "商品单价",
              "min-width": "100px",
              showOverflowTooltip: true
            }),
            h(ElTableColumn, {
              prop: "goodNum",
              label: "商品总数量",
              "min-width": "100px",
              showOverflowTooltip: true
            }),
            h(ElTableColumn, {
              prop: "ainv_num",
              label: "已开票数量",
              "min-width": "100px",
              showOverflowTooltip: true
            }),
            h(ElTableColumn, {
              prop: "inv_num",
              label: "此次开票数量",
              "min-width": "100px",
              showOverflowTooltip: true
            }),
            h(ElTableColumn, {
              prop: "totalPrice",
              label: "订单总金额",
              "min-width": "100px",
              showOverflowTooltip: true
            }),
            h(ElTableColumn, {
              prop: "ainv_fee",
              label: "已开票金额",
              "min-width": "100px",
              showOverflowTooltip: true
            }),
            h(ElTableColumn, {
              prop: "cancel_fee",
              label: "此次开票金额",
              "min-width": "100px",
              showOverflowTooltip: true
            })
          ]
        }
      );
    }
  },

  {
    field: "remark",
    label: "发票备注",
    span: 24
  },
  {
    field: "exam_remark",
    label: "审核备注",
    span: 24
  }
];

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(
        "div",
        {},
        {
          default: () => [
            h(
              ElTag,
              {
                type: INV_OPEN_STATUS.find(s => s.value === data)?.type as any
              },
              {
                default: () =>
                  INV_OPEN_STATUS.find(s => s.value === data)?.label || "--"
              }
            ),
            h(
              ElPopover,
              {
                placement: "top",
                content: "111px",
                width: "200px"
              },
              {
                reference: () =>
                  h(ElButton, {
                    link: true,
                    icon: useRenderIcon("information-line")
                  })
              }
            )
          ]
        }
      );
    }
  },
  {
    field: "inv_type",
    label: "发票类型",
    render(data) {
      return h(ElTag, null, {
        default: () => {
          //console.log(invoiceTypeList, data);
          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",
    // span: 12,
    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: "ownerPlace",
    label: "复核人"
  }
];
