<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"
    >
      <template #menu="{ row }">
        <el-button link icon="el-icon-copy-document" @click="showFlowSteps(row)"
        >流程</el-button>
        <el-button
            link
            icon="el-icon-copy-document"
            @click="showFlowDetail(row)"
        >详情</el-button
        >
      </template>
    </avue-crud>
    <el-dialog
        v-model="dialog.visible"
        :title="dialog.title"
        width="1250px"
        @close="dialog.visible = false"
    >
      <div class="dialog-footer" align="center">
        <el-button @click="dialog.visible = false">取消</el-button>
        <el-button type="primary" @click="printPage">--</el-button>
      </div>
    </el-dialog>

    <LookFlowStep ref="LookFlowStepRef"></LookFlowStep>
    <CheckFlow ref="CheckFlowRef" @finish="onCheckFinish" :operType="operType"></CheckFlow>
  </div>
</template>
<script setup>
import LookFlowStep from "@/views/flow/common/LookFlowStep.vue";
import CheckFlow from "@/views/flow/common/CheckFlow.vue";
import { ref, getCurrentInstance } from "vue";
import { useCrud } from "@/hooks/userCrud";
import { useCommonStoreHook } from "@/store";
import dictDataUtil from "@/common/configs/dictDataUtil";
const { isShowTable, tableType } = toRefs(useCommonStoreHook());
// 传入一个url，后面不带/
const { form, data, option, search, page, toDeleteIds, Methords, Utils } =
    useCrud({
      src: "/api/v1/flowTask",
    });
const { dataList, createRow, updateRow, deleteRow, searchChange, resetChange } =
    Methords; //增删改查
const { selectionChange, multipleDelete } = Methords; //选中和批量删除事件
const { checkBtnPerm, downloadTemplate, exportData } = Utils; //按钮权限等工具
const operType = ref("done")
const crudRef = ref(null); //crudRef.value 获取avue-crud对象
const dialog = reactive({
  title: "二维码打印",
  visible: false,
});
// 设置表格列或者其他自定义的option
option.value = Object.assign(option.value, {
  searchEnter: true,
  delBtn: false,
  selection: false,
  addBtn: false,
  editBtn: false,
  viewBtn: false,
  column: [
    {
      label: "流程类型",
      prop: "taskType",
      type: "select",
      search: true,
      editDisabled: true,
      dicUrl: dictDataUtil.request_url + "flow_type",
      props: {
        label: "dictLabel",
        value: "dictValue",
      },
    },
    {
      label: "流程名称",
      prop: "taskName",
      editDisabled: true,
    },
    {
      label: "业务名称",
      prop: "businessName",
      search: true,
    },
    {
      label: "当前节点",
      prop: "currentStep",
    },
    {
      label: "审核状态",
      prop: "state",
      type: "select",
      dicUrl: dictDataUtil.request_url + "flow_state",
      props: {
        label: "dictLabel",
        value: "dictValue",
      },
    },
    {
      label: "办理时间",
      prop: "updated",
    },
  ],
});

onMounted(() => {
  operType.value = "done"
  dataList();
});

const LookFlowStepRef = ref(null);
const showFlowSteps = (row) => {
  LookFlowStepRef.value && LookFlowStepRef.value.openFlowStepDrawer(row.insId);
};

const CheckFlowRef = ref(null);
const showFlowDetail = (row) => {
  CheckFlowRef.value && CheckFlowRef.value.openCheckDrawer(row);
};
const onCheckFinish = (value) => {
  dataList();
};
</script>
