<!--流程的流转记录-->
<template>
  <div class="tels-restApply-precess-record">
    <el-dialog :title="state.dialogTitle" v-model="state.dialogVisible" width="80%" draggable destroy-on-close append-to-body>
      <div v-loading="state.loading">
        <slot name="header"></slot>
        <slot>
          <process-time-line :data="state.traces" defaultExpandAll />
        </slot>
        <slot name="footer"></slot>
      </div>
    </el-dialog>
  </div>
</template>

<script setup lang="ts" name="auditRecord">
import { reactive, defineAsyncComponent } from 'vue';
import { workflowTraces } from '@/api/system/workflow';
import {transformFile} from "@/utils/tools";

// 引入组件
const ProcessTimeLine = defineAsyncComponent(() => import('@/components/ProcessTimeLine/index.vue'));

// 定义变量内容
const state = reactive<any>({
  dialogVisible: false,
  traces: [],
  loading: false,
  dialogTitle: '',
});
// 打开弹窗
const openDialog = async (row: any) => {
  state.dialogVisible = true;
  try {
    state.loading = true;
    // 查询审核记录
    const res = await workflowTraces(row.workflowId);
    state.traces = res.result?.traces ?? [];
    state.traces = formatTraces(state.traces);
    state.dialogTitle = row.dialogTitle ?? '';
    state.loading = false;
  } catch (error) {
		console.log(error,'错误')
    state.loading = false;
    state.dialogVisible = false;
  }
};
const formatTraces = (val: any) => {
  if (!val || !val.length) return [];
  val.forEach((item: any) => {
    item.files = transformFile(item.files);
    switch (item.expiredStatus) {
      case 0:
        item.type = 'success';
        break;
      case 1:
        item.type = 'primary';
        break;
      case 2:
        item.type = 'danger';
        break;
      default:
        break;
    }
    if (item.traces?.length) {
      formatTraces(item.traces);
    }
  });
  return val;
};
// 关闭弹窗
const closeDialog = () => {
  state.dialogVisible = false;
};
// 暴露变量
defineExpose({
  openDialog,
  closeDialog,
});
</script>
