<template>
	<div class="layout-pd h100" v-loading="loading">
		<LogicFlow ref="designerRef" v-model="flowData" />
	</div>
</template>
<script setup lang="ts" name="workflowAddEdit">
import { defineAsyncComponent, ref, onMounted } from 'vue';
import { ElMessage } from 'element-plus';
import { useRoute } from 'vue-router';
import { getWorkFlowDetail } from '/@/api/system/workflow';
import { auth } from '/@/utils/authFunction';
const LogicFlow = defineAsyncComponent(() => import('/@/components/LogicFlow/index.vue'));  // 流程设计器
const designerRef = ref(null as any);
let flowData = ref({
	name: '', // 流程名称
	code: '', // 流程编码
	id: '', // 流程id
	moduleName: '', // 模块名称
	moduleCode: '', // 模块编码
	nodes: [  // 节点
		{
			id: 'start',
			type: 'hotline:start',
			x: 780,
			y: 120,
			properties: {},
			text: {
				x: 780,
				y: 80,
				value: '开始',
			},
		},
		{
			id: 'end',
			type: 'hotline:end',
			x: 780,
			y: 400,
			properties: <EmptyObjectType>{},
			text: {
				x: 780,
				y: 440,
				value: '结束',
			},
		},
	],
	edges: [],
});
const route = useRoute(); // 路由
const loading = ref(false); // 加载状态
onMounted(async () => {
	// 查询详情
	if (route.params.id) {
		loading.value = true;
		try {
			if (!auth('system:workflow:detail')) ElMessage.error('抱歉，您没有权限获取流程详情！');
			else {
				const res: any = await getWorkFlowDetail(route.params.id);
				flowData.value = res.result;
				loading.value = false;
			}
		} catch (error) {
			loading.value = false;
		}
	}
});
</script>
