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

import dayjs from "dayjs";
import {
  httpAdd,
  httpList,
  httpUpdate,
  httpDelete,
  httpStatus
} from "/@/api/parameter/setProcess";
import { h } from "vue";
import { ElTag } from "element-plus";

const columns = [
  {
    type: "selection",
    width: 55,
    hide: ({ checkList }) => !checkList.includes("勾选列")
  },
  {
    label: "序号",
    type: "index",
    width: 70,
    hide: ({ checkList }) => !checkList.includes("序号列")
  },
  {
    label: "节点名称",
    prop: "status_name"
  },
  {
    label: "节点值",
    prop: "order_process"
  },
  {
    label: "节点类型",
    prop: "status",
    cellRenderer({ row }) {
      return h(ElTag, null, {
        default: () => "TODO"
      });
    }
  },
  {
    label: "操作类型",
    prop: "status",
    cellRenderer({ row }) {
      return h(ElTag, null, {
        default: () => "TODO"
      });
    }
  },
  {
    label: "状态",
    prop: "status",
    cellRenderer({ row }) {
      return h(
        ElTag,
        {
          type: row.status === "0" ? "danger" : "success"
        },
        {
          default: () => (row.status === "0" ? "禁用" : "启用")
        }
      );
    }
  },
  {
    label: "下一节点",
    prop: "status",
    width: "200px",
    cellRenderer({ row }) {
      return h("div", null, {
        default: () =>
          row.next_actions.map(n =>
            h(
              ElTag,
              {
                style: {
                  marginRight: "10px"
                }
              },
              {
                default: () => n
              }
            )
          )
      });
    }
  },
  {
    label: "创建人",
    prop: "creater"
  },
  {
    label: "创建时间",
    prop: "addtime",
    formatter: ({ createTime }) =>
      dayjs(createTime).format("YYYY-MM-DD HH:mm:ss")
  },
  {
    label: "操作",
    fixed: "right",
    width: 150,
    slot: "operation"
  }
];

const contentConfig: ContentConfig = {
  title: "流程节点设置",
  powers: ["001", "002", "003", "004", "005", "006", "007", "008"],
  notReuqiredInit: true,
  mockData: [
    {
      id: "116",
      status_name: "取消订单",
      order_process: "7",
      status: "1",
      action_type: "3",
      operation_type: "2",
      next_action_ids: "",
      creater: "",
      addtime: "2022-07-26 20:21:17",
      remark: "",
      next_actions: []
    },
    {
      id: "115",
      status_name: "成功转单",
      order_process: "6",
      status: "1",
      action_type: "4",
      operation_type: "2",
      next_action_ids: "",
      creater: "",
      addtime: "2022-07-26 00:00:00",
      remark: "",
      next_actions: []
    },
    {
      id: "114",
      status_name: "财务驳回",
      order_process: "5",
      status: "1",
      action_type: "4",
      operation_type: "2",
      next_action_ids: "",
      creater: "",
      addtime: "2022-07-26 00:00:00",
      remark: "",
      next_actions: []
    },
    {
      id: "113",
      status_name: "待财务审核",
      order_process: "4",
      status: "1",
      action_type: "2",
      operation_type: "1",
      next_action_ids: "114,115",
      creater: "",
      addtime: "2022-07-26 00:00:00",
      remark: "",
      next_actions: ["财务驳回", "成功转单"]
    },
    {
      id: "112",
      status_name: "产品驳回",
      order_process: "3",
      status: "1",
      action_type: "4",
      operation_type: "2",
      next_action_ids: "",
      creater: "",
      addtime: "2022-07-26 00:00:00",
      remark: "",
      next_actions: []
    },
    {
      id: "111",
      status_name: "待产品审核",
      order_process: "2",
      status: "1",
      action_type: "2",
      operation_type: "1",
      next_action_ids: "112,113",
      creater: "",
      addtime: "2022-07-26 00:00:00",
      remark: "",
      next_actions: ["产品驳回", "待财务审核"]
    },
    {
      id: "110",
      status_name: "处理中",
      order_process: "1",
      status: "1",
      action_type: "2",
      operation_type: "2",
      next_action_ids: "115,111",
      creater: "",
      addtime: "2022-07-26 00:00:00",
      remark: "",
      next_actions: ["成功转单", "待产品审核"]
    },
    {
      id: "109",
      status_name: "待系统处理",
      order_process: "0",
      status: "1",
      action_type: "1",
      operation_type: "2",
      next_action_ids: "110",
      creater: "",
      addtime: "2022-07-26 00:00:00",
      remark: "",
      next_actions: ["处理中"]
    }
  ],
  columns,
  apis: {
    httpAdd,
    httpList,
    httpUpdate,
    httpDelete,
    httpStatus
  }
};

export default contentConfig;
