<template>
  <div class="business-detail">
    <iframe :src="workflowUrl" class="workflow-iframe" frameborder="0" scrolling="auto" allowfullscreen allow="fullscreen" width="100%" height="100%"/>
    <!-- <component :is="currentComponent"></component> -->
  </div>
</template>

<script setup lang="ts">
import type { WorkflowParams } from '@/types/workflow'
import {
  ref,
  inject,
  reactive,
  onMounted,
  onActivated,
  getCurrentInstance,
  nextTick,
  defineAsyncComponent
} from 'vue'
import { showToast, showDialog, showLoadingToast, showSuccessToast, closeToast } from 'vant'

const {
  proxy
} = getCurrentInstance()
import {
  useRoute
} from 'vue-router';
const route = useRoute();

import {
		useWorkflowStore
	} from "@/stores/workflow"

const workflow = useWorkflowStore()

const workflowParams = inject<WorkflowParams>('workflowParams')

const currentComponent = ref<any>('')
const workflowUrl = ref<any>('')
const flowId = ref<any>('')
flowId.value = workflowParams?.flowId

const getBusinessPage = () => {
  var url = 'framework/BusinessProcess/queryBusinessPageByFlowId'
  var param = {
    flowId: flowId.value
  }
  proxy.$axios.post(url, param).then(response => {
    if (response.data.code == '0') {

      if(response.data === null || response.data.data === null || response.data.data.pathApplet === undefined){
        // currentComponent.value = defineAsyncComponent(() =>
        //   import('../biz/error/index.vue')
        // )
        workflowUrl.value = `${import.meta.env.VITE_H5_URL}` + '/error'
      }else{
        // currentComponent.value = defineAsyncComponent(() =>
      	//   import(`..${response.data.data.pathApplet}.vue`)
        // );
        workflowUrl.value = `${import.meta.env.VITE_H5_URL}` + response.data.data.pathApplet + '?workId=' + workflowParams?.workId
      }

    } else {
      showToast({ type: 'fail', message: '操作失败！' + response.data.msg })
    }
  })
}

onMounted(() => {
  workflow.setWorkId(workflowParams?.workId)
  getBusinessPage()
})

onActivated(() => {
  workflow.setWorkId(workflowParams?.workId)

  getBusinessPage()
})


</script>

<style lang="scss" scoped>
.business-detail {
  padding: 16px 0;
  height: calc(100vh - 0px);
  
  .exp-iframe {
    width: 100%;
    height: 100%;
    border: none;
    overflow: hidden;
  }
}
</style> 