<template>
  <div class="gl-page-content-full page-approval-preview">
    <div class="content">
      <TaskPool v-if="data.approveType === 1" :data="data" />
      <Knowledge v-else-if="data.approveType === 2" :data="data" />
      <FlowView type="approve" v-else-if="data.approveType === 3" :data="data" />
      <DeliverableFile v-else-if="data.approveType === 4" :data="data" />
      <Parameter v-else-if="data.approveType === 5" :data="data" />
      <div v-else>其他审核预览{{ data.cidFlowId }}</div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, watch } from 'vue';
import { useRoute } from 'vue-router';
import { systemQueryApproveInstanceApi } from '@/api/system/systemApprove';
import TaskPool from './components/taskPool.vue';
import Knowledge from './components/knowledge.vue';
import FlowView from '@/components/common/flow/flowView.vue';
import DeliverableFile from './components/deliverableFile.vue';
import Parameter from './components/parameter.vue';

const w: any = window;
const $wujie: any = w.$wujie;

const route = useRoute();
const data = ref<any>({});

onMounted(() => {
  getDetailDataFun();
});

watch(() => route.query, () => {
  getDetailDataFun();
}, { deep: true });

const getDetailDataFun = () => {
  if (!route.query.processId) {
    return;
  }
  const params = {
    flowId: route.query.processId,
  };
  systemQueryApproveInstanceApi(params).then((res: any) => {
    if (res.code === 200) {
      data.value = res.data;
      let width: any = '100%';
      if (data.value.approveType === 2) {
        width = '100%';
      }
      $wujie.bus.$emit('APPROVAL_PREVIEW_LOADED', width);
    }
  });
};
</script>

<style lang="scss" scoped>
.page-approval-preview {
  border: 0;
  overflow-y: auto;
  .content {
    height: 100%;
  }
}
</style>
