import { ContentConfig } from "/@/components/PageContent";
import { httpList } from "/@/api/purchase/ticketReturn";

import dayjs from "dayjs";
import { h } from "vue";
import { ElImage, ElTag } from "element-plus";
import { status_options } from "./configs";

const columns = [
  {
    type: "selection",
    width: 55,
    hide: ({ checkList }) => !checkList.includes("勾选列")
  },
  {
    label: "序号",
    type: "index",
    width: 70,
    hide: ({ checkList }) => !checkList.includes("序号列")
  },
  {
    label: "对账编号",
    prop: "payNo",
    width: 180
  },
  {
    label: "对账回票申请",
    prop: "hpNo",
    width: 180
  },
  {
    label: "申请人",
    prop: "apply_name"
  },
  {
    label: "发票类型",
    width: 110,
    prop: "invoiceType_cn"
  },
  {
    label: "发票状态",
    width: 110,
    prop: "invStatus_cn"
  },
  {
    label: "状态",
    prop: "status",
    width: 160,
    cellRenderer: ({ row, props }) =>
      h(
        ElTag,
        {
          size: props.size
        },
        {
          default: () => status_options.find(s => row.status === s.value)?.label
        }
      )
  },
  {
    label: "发票图片",
    prop: "inv_img",
    width: 100,
    cellRenderer: ({ row }) =>
      h(ElImage, {
        src: row.inv_img,
        style: { height: "20px" },
        previewSrcList: [row.inv_img],
        previewTeleported: true
      })
  },
  {
    label: "发票票面额度",
    width: "130px",
    prop: "inv_subtotal_amount"
  },
  {
    label: "开票时间",
    prop: "open_time",
    width: 180,
    formatter: ({ open_time }) =>
      open_time ? dayjs(open_time).format("YYYY-MM-DD HH:mm:ss") : ""
  },
  {
    label: "创建时间",
    prop: "addtime",
    width: 180,
    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
  },
  powers: ["001", "002", "003", "004", "005", "006", "007", "008"]
};

export default contentConfig;
