import { ContentConfig } from "/@/components/PageContent";

import {
  httpList,
  httpAdd,
  httpDelete
} from "/@/api/reportForm/personnelReportRecord";

import { h } from "vue";
import dayjs from "dayjs";
import { ElTag } from "element-plus";
import { type_options, tag_type } from "./_options";

const columns = [
  {
    type: "selection",
    width: 40,
    align: "center",
    hide: ({ checkList }) => !checkList.includes("勾选列")
  },
  {
    label: "序号",
    type: "index",
    width: 70,
    hide: ({ checkList }) => !checkList.includes("序号列")
  },
  {
    label: "报表名称",
    prop: "name"
  },
  {
    label: "执行类型",
    prop: "type",
    width: "90px",
    cellRenderer: ({ row, props }) =>
      h(
        ElTag,
        {
          size: props.size,
          type: String(row.type) === "1" ? "" : "success"
        },
        {
          default: () =>
            type_options.find(s => String(row.type) === s.value)?.label
        }
      )
  },
  {
    label: "状态",
    prop: "status",
    width: "90px",
    cellRenderer: ({ row, props }) => {
      const { type, label } = tag_type.find(
        s => String(row.status) === s.value
      );
      return h(
        ElTag,
        {
          size: props.size,
          type: type
        },
        {
          default: () => label
        }
      );
    }
  },
  {
    label: "开始时间",
    prop: "start",
    width: "140px",
    formatter: ({ start }) => dayjs(start).format("YYYY-MM-DD HH:mm:ss")
  },
  {
    label: "结束时间",
    prop: "end",
    width: "140px",
    formatter: ({ end }) => dayjs(end).format("YYYY-MM-DD HH:mm:ss")
  },
  {
    label: "申请人",
    prop: "apply_name",
    width: "70px"
  },
  {
    label: "创建时间",
    prop: "addtime",
    width: "140px",
    formatter: ({ addtime }) => dayjs(addtime).format("YYYY-MM-DD HH:mm:ss")
  },
  {
    label: "操作",
    fixed: "right",
    width: 80,
    slot: "operation"
  }
];

const contentConfig: ContentConfig = {
  title: "报表申请记录",
  columns,
  showDelete: row => {
    return String(row.status) == "1" || String(row.status) === "3";
  },
  apis: {
    httpList,
    httpAdd,
    httpDelete
  }
};

export default contentConfig;
