import { ContentConfig } from "/@/components/PageContent";
import { httpList } from "/@/api/purchase/inputInvoicePool";
import { ElTag } from "element-plus";
import dayjs from "dayjs";
import { h } from "vue";

import {
  invoiceTypeList,
  seller_check_type,
  buyer_check_type,
  invoiceStatusOptions,
  checkTypeOptions,
  hasAccountOptions,
  orderTypeCgOptions
} from "/@/utils/status";
import { renderIconLabelLeft, renderProp } from "/@/utils/columnRenderHelper";

const columns = [
  {
    type: "selection",
    width: 40,
    align: "center",
    fixed: 'left'
  },
  {
    label: "发票编码",
    prop: "InvCode",
    width: 140
  },
  {
    label: "税前金额",
    prop: "invoice_total",
    width: 100
  },
  {
    label: "税后金额",
    prop: "invoice_subtotal",
    width: 100
  },
  {
    label: "状态",
    prop: "status",
    width: 120,
    cellRenderer: ({ row, props }) =>
      h(
        ElTag,
        { size: props.size },
        {
          default: () => invoiceStatusOptions.find(s => String(row.status) === String(s.value))?.label
        }
      )
  },
  {
    label: "卖出方公司",
    prop: "supplierName",
    width: 145,
    ...renderIconLabelLeft("supplierNo","supplierName","卖出方公司编码:")
  },
  {
    label: "买入方公司",
    prop: "companyName",
    width: 145,
    ...renderIconLabelLeft('companyNo','companyName','买入方公司编码:')
  },
  {
    label: "发票类型",
    width: 185,
    cellRenderer({ row }) {
      return h(ElTag, null, {
        default: () =>
          invoiceTypeList.find(({ value }) => value === row.invoice_type)
            ?.label || "--"
      });
    }
  },
  {
    label: "发票号码",
    width: 110,
    prop: "invoice_number"
  },
  {
    label: "申请人",
    prop: "apply_name"
  },
  {
    label: "创建时间",
    prop: "addtime",
    width: 150,
    formatter: ({ addtime }) => dayjs(addtime).format("YYYY-MM-DD HH:mm:ss")
  }
];

const contentConfig: ContentConfig = {
  title: "采购回票",
  statusProp: "companyNo",
  columns,
  apis: { 
    httpList: (parameter = {}) => httpList({ ...parameter, status: '2' }) 
  },
};

export default contentConfig;
