<template>
  <div class="flow-open-page">
    <FlowBox v-if="initialized" ref="flowBox" @close="onClose" />
  </div>
</template>

<script>
import FlowBox from '../components/FlowBox'

export default {
  name: 'WorkFlowFlowOpen',
  components: { FlowBox },
  data() {
    return {
      initialized: false
    }
  },
  mounted() {
    const q = this.$route.query || {}
    if (!q.id) {
      this.$message.error('缺少流程参数，无法打开详情')
      this.$router.back()
      return
    }
    this.initialized = true
    this.$nextTick(() => {
      const formType = q.formType !== undefined && q.formType !== '' ? Number(q.formType) : 1
      const status = q.status !== undefined && q.status !== '' ? Number(q.status) : 2
      this.$refs.flowBox.init({
        id: q.id,
        enCode: q.flowCode || '',
        flowId: q.flowId || '',
        formType: Number.isNaN(formType) ? 1 : formType,
        opType: 0,
        status: Number.isNaN(status) ? 2 : status,
        taskNodeId: q.taskNodeId || undefined
      })
    })
  },
  methods: {
    onClose() {
      if (window.history.length > 1) {
        this.$router.back()
      } else {
        this.$router.replace('/dashboard')
      }
    }
  }
}
</script>

<style scoped>
.flow-open-page {
  min-height: 100%;
}
</style>
