<template>
  <div class="mainContentBox">
    <avue-crud
      ref="crudRef"
      v-model:search="search"
      v-model="form"
      :data="data"
      :option="option"
      v-model:page="page"
      @row-save="createRow"
      @row-update="updateRow"
      @row-del="deleteRow"
      @search-change="searchChange"
      @search-reset="resetChange"
      @size-change="dataList"
      @current-change="dataList"
      @selection-change="selectionChange1"
    >
      <template #menu="{ size, row }">
        <!--        <el-button icon="el-icon-setting" text type="primary" :size="size"-->
        <!--          >编辑</el-button-->
        <!--        >-->
        <el-button
          icon="el-icon-setting"
          text
          type="primary"
          :size="size"
          @click="defineFlow(row)"
          >定义</el-button
        >
      </template>
    </avue-crud>
  </div>
</template>
<script setup>
import { ref, getCurrentInstance } from "vue";
import { useCrud } from "@/hooks/userCrud";
import { useCommonStoreHook } from "@/store/index";
import dictDataUtil from "@/common/configs/dictDataUtil";
const { isShowTable, tableType } = toRefs(useCommonStoreHook());
const test = () => {
  isShowTable.value = true;
  tableType.value = tableType.value == 1 ? 2 : 1;
};
const clickRows = ref([]);
// 传入一个url，后面不带/
const { form, data, option, search, page, toDeleteIds, Methords, Utils } =
  useCrud({
    src: "/api/v1/definition",
  });
const { dataList, createRow, updateRow, deleteRow, searchChange, resetChange } =
  Methords; //增删改查
const { selectionChange, multipleDelete } = Methords; //选中和批量删除事件
const { checkBtnPerm, downloadTemplate, exportData } = Utils; //按钮权限等工具

const crudRef = ref(null); //crudRef.value 获取avue-crud对象

// 设置表格列或者其他自定义的option
option.value = Object.assign(option.value, {
  searchEnter: true,
  delBtn: false,
  selection: false,
  addBtn: true,
  editBtn: true,
  viewBtn: false,
  column: [
    /*{
      label: "流程编码",
      prop: "flowCode",
    },*/
    {
      label: "流程名称",
      prop: "flowName",
      search: true,
    },
    {
      label: "流程类型",
      prop: "flowType",
      type: "select",
      search: true,
      dicUrl: dictDataUtil.request_url + dictDataUtil.TYPE_CODE.flow_type,
      props: {
        label: "dictLabel",
        value: "dictValue",
      },
    },
    {
      label: "流程版本",
      prop: "flowVersion",
      hide: true,
      type: 'number',
      value: 1.0,
      precision: 1,
    },
    {
      label: "流程版本",
      html: true,
      addDisplay: false,
      editDisplay: false,
      formatter: (val) => {
        return (
            '<b class="el-tag el-tag--success el-tag--light">V' +
            val.flowVersion +
            "</b>"
        );
      },
    },
    {
      label: "状态",
      prop: "enable",
      type: "select",
      search: true,
      dicData: [
        { label: "启用", value: "0" },
        { label: "禁用", value: "1" },
      ],
    },
    {
      label: "创建时间",
      prop: "created",
      display: false,
    },
    {
      label: "创建人",
      prop: "creator",
      display: false,
    },
  ],
});

onMounted(() => {
  // console.log("crudRef", crudRef)
  dataList();
});

const router = useRouter();
// 定义流程
const defineFlow = (row) => {
  console.log("row", row.id);
  router.push({
    path: `/flow/definition-edit/${row.id}`,
  });
};
</script>
