<script setup name="FlowDesign">
import { onMounted, ref } from 'vue'
import ScWorkflow from '@/components/scWorkflow'
import useFlowStore from '@/store/modules/flow'
import { storeToRefs } from 'pinia'

defineProps({
	label: {
		type: String
	},
	name: {
		type: String
	}
})

const flowStore = useFlowStore()
const { modelContent } = storeToRefs(flowStore)
const formRef = ref()
let form = ref({
	processConfig: {
		nodeName: '发起人',
		type: 0,
		nodeRoleList: []
	}
})

// 接口保存审批流程
const saveDesign = json => {
	modelContent.value = JSON.stringify(form.value.processConfig)
}
const updateCompInfo = () => {
	if (modelContent.value) {
		const _val = JSON.parse(modelContent.value)
		form.value = Object.assign({ processConfig: _val }, {})
	}
}
onMounted(() => {
	updateCompInfo()
})
const validate = () => {
	// 保存表单设计
	saveDesign()
	// 根据后续的业务需求 调整 validate 的功能
	return new Promise((resolve, reject) => {
		resolve()
	})
}
defineExpose({
	formRef,
	saveDesign,
	validate,
	updateCompInfo
})
</script>

<template>
	<ScWorkflow v-model="form.processConfig"></ScWorkflow>
</template>
