import { ContentConfig } from "/@/components/PageContent";
import { httpList } from "/@/api/purchase/ticketReturnRelive";
import { renderIconLabelLeft, renderProp } from "/@/utils/columnRenderHelper";

import dayjs from "dayjs";
import { h } from "vue";
import { ElTag } from "element-plus";

import { hasAccountOptions, orderTypeCgOptions, ticketReturnReliveStatusOptions } from "/@/utils/status";

const columns = [
  {
    label: "回票解除编码",
    prop: "returnCode",
    width: 150
  },
  {
    label: "对账回票编码",
    prop: "orderCode",
    width: 150
  },

  {
    label: "对账编码",
    prop: "payNo",
    width: 150
  },
  {
    label: "供应商端",
    prop: "has_account",
    width: 80,
    ...renderProp(hasAccountOptions, "has_account")
  },
  {
    label: "状态",
    prop: "status",
    width: 120,
    cellRenderer: ({ row, props }) =>
      h(
        ElTag,
        { size: props.size },
        { default: () => ticketReturnReliveStatusOptions.find(s => String(row.status) === s.value)?.label }
      )
  },
  {
    label: '业务类型',
    width: 95,
    ...renderProp(orderTypeCgOptions, 'is_comon')
  },
  {
    label: "卖出方公司",
    prop: "supplierName",
    minWidth: 160,
    ...renderIconLabelLeft('supplierNo', 'supplierName', '卖出方公司编码:')
  },
  {
    label: "买入方公司",
    prop: "companyNo",
    minWidth: 160,
    ...renderIconLabelLeft('companyNo', 'companyName', '买入方公司编码:')
  },
  {
    label: "退票理由",
    prop: "reason",
    minWidth: 160,
  },
  {
    label: "申请人",
    prop: "apply_name",
    width: 80
  },
  {
    label: "创建时间",
    prop: "addtime",
    width: 140,
    formatter: ({ addtime }) => dayjs(addtime).format("YYYY-MM-DD HH:mm:ss")
  },
  {
    label: "操作",
    fixed: "right",
    slot: "operation",
    width: 60
  }
];

const contentConfig: ContentConfig = {
  title: "采购回票",
  statusProp: "companyNo",
  columns,
  apis: {
    httpList: (data) => httpList({ ...data, noRela: true })
  },
  transformCompany: true,
  companyProp: 'supplierNo',
};

export default contentConfig;
