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

import {
  httpList,
  httpAdd,
  httpUpdate,
  httpDelete,
  httpStatus
} from "/@/api/parameter/tagManage";

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

const columns = [
  {
    type: "selection",
    width: 55,
    hide: ({ checkList }) => !checkList.includes("勾选列")
  },
  {
    label: "序号",
    type: "index",
    width: 70,
    hide: ({ checkList }) => !checkList.includes("序号列")
  },
  {
    label: "id",
    prop: "id"
  },
  {
    label: "标签类型",
    prop: "type",
    cellRenderer: ({ row, props }) =>
      h(
        ElTag,
        {
          size: props.size
        },
        {
          default: () => tag_type.find(s => row.type === s.value)?.label
        }
      )
  },
  {
    label: "状态",
    prop: "status",
    cellRenderer: ({ row, props }) =>
      h(
        ElTag,
        {
          size: props.size,
          type: row.status === "1" ? "success" : "danger"
        },
        {
          default: () => (row.status === "1" ? "启用" : "禁用")
        }
      )
  },
  {
    label: "标签名称",
    prop: "tag_name"
  },
  {
    label: "申请人",
    prop: "apply_name"
  },
  {
    label: "创建时间",
    prop: "addtime",
    formatter: ({ addtime }) => dayjs(addtime).format("YYYY-MM-DD HH:mm:ss")
  },
  {
    label: "操作",
    fixed: "right",
    width: 150,
    slot: "operation"
  }
];

const contentConfig: ContentConfig = {
  title: "标签管理",
  columns,
  powers: ["001", "002", "003", "004", "005", "006", "007", "008"],
  apis: {
    httpList,
    httpAdd,
    httpUpdate,
    httpStatus,
    httpDelete
  }
};

export default contentConfig;
