import { h } from "vue";
import { ContentConfig } from "/@/components/PageContent";
import { httpList } from "/@/api/InvoiceSales/invoiceApply";

import {
  useTypeOptions,
  invoiceTypeList,
  buyer_check_type,
  seller_check_type,
  invoiceApplyStatusOptions
} from "/@/utils/status";

import { ElTag } from "element-plus";
import { renderIconLabelLeft } from "/@/utils/columnRenderHelper";

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

const columns = [
  {
    type: "selection",
    width: 40,
    align: "center",
    fixed: 'left'
  },
  {
    label: "发票申请编码",
    prop: "invNo",
    width: 150
  },
  {
    label: "业务企业公司",
    prop: "inv_out",
    width: 180,
    ...renderIconLabelLeft("inv_out", "inv_company", "业务企业公司编码:")
  },
  {
    label: "客户公司名称",
    prop: "buyer_title",
    width: 175
  },
  {
    label: "申请额度",
    prop: "inv_value",
    width: 110
  },
  {
    label: "申请人",
    prop: "apply_name",
    width: 80
  },
  {
    label: "平台类型",
    prop: "platform_type",
    width: 110,
    cellRenderer: ({ row }) => {
      return h(ElTag, null, {
        default: () => {
          return (
            useTypeOptions.find(item => item.value == row.platform_type + "")
              ?.label || "--"
          );
        }
      });
    }
  },
  {
    label: "是否有备注",
    width: 80,
    cellRenderer: ({ row }) =>
      h(ElTag, null, {
        default: () =>
          row.exam_remark && row.exam_remark.length > 0 ? "是" : "否"
      })
  },
  {
    label: "状态",
    prop: "status",
    width: 125,
    cellRenderer: ({ row }) => {
      return h(ElTag, null, {
        default: () => {
          return (
            invoiceApplyStatusOptions.find(
              item => item.value == row.status + ""
            )?.label || "--"
          );
        }
      });
    }
  },
  {
    label: "开票方式",
    prop: "open_type",
    width: 135,
    cellRenderer: ({ row }) => {
      return h(ElTag, null, {
        default: () => {
          return (
            open_type_list.find(item => item.value == row.open_type + "")
              ?.label || "未选择"
          );
        }
      });
    }
  },
  {
    field: "is_ticket",
    label: "是否支持金税",
    width: 90,
    cellRenderer({ row }) {
      return h(ElTag, null, {
        default: () =>
          String(row.is_ticket) === "2"
            ? "不支持"
            : String(row.is_ticket) === "1"
              ? "支持"
              : "--"
      });
    }
  },
  {
    label: "发票类型",
    prop: "status",
    width: 150,
    cellRenderer: ({ row }) => {
      return h(ElTag, null, {
        default: () =>
          invoiceTypeList.find(item => item.value == row.inv_type + "")
            ?.label || "--"
      });
    }
  },
  {
    label: "发票号码",
    prop: "inv_number",
    width: 130
  },
  {
    label: "发票代码",
    prop: "inv_code",
    width: 100
  },
  {
    label: "购买方抬头状态",
    prop: "seller_check",
    width: 130,
    cellRenderer: ({ row }) => {
      return h(ElTag, null, {
        default: () =>
          seller_check_type.find(item => item.value == row.seller_check + "")
            ?.label || "--"
      });
    }
  },
  {
    label: "销售方抬头状态",
    prop: "buyer_check",
    width: 130,
    cellRenderer: ({ row }) => {
      return h(ElTag, null, {
        default: () =>
          buyer_check_type.find(item => item.value == row.buyer_check + "")
            ?.label || "--"
      });
    }
  },
  {
    label: "创建时间",
    width: 140,
    prop: "addtime"
  },
  // {
  //   label: "操作",
  //   fixed: "right",
  //   width: 140,
  //   slot: "operation"
  // }
];

const contentConfig: ContentConfig = {
  title: "发票申请管理",
  columns,
  superUserNoAction: true,
  companyProp: "inv_out",
  apis: {
    httpList: (parameter) => httpList({ ...parameter, status: '4' }),
    httpAdd: true
  }
};

export default contentConfig;
