<!-- 开始节点配置 -->
<template>
  <div class="subprocess">
    <a-form ref="formRef" :model="node" labelAlign="left" :label-col="labelCol" :wrapper-col="wrapperCol" :disabled="data.componentDisabled">
      <a-form-item label="节点标识">
        <a-input v-model:value="node.id" placeholder="请输入" readonly />
      </a-form-item>
      <a-form-item label="是否异步">
        <a-switch v-model:checked="node.isAsync" />
      </a-form-item>
      <a-form-item label="流程模版">
        <a-select v-model:value="node.wfschemeId" :options="list" @change="changeScheme" :fieldNames="{ value: 'id', label: 'name' }">
        </a-select>
      </a-form-item>
      <a-form-item label="流程版本">
        <a-select v-model:value="node.wfVersionId" :options="verisons" :fieldNames="{value:'id',label:'createDate'}">
        </a-select>
      </a-form-item>
    </a-form>
  </div>
</template>

<script lang="ts" setup>
  import { reactive, defineProps, computed, inject, ref, watch, h ,onMounted} from 'vue'
  import { getDetail ,getLoad,getVerisonsLoad} from '@/api/sys/WFSchemeInfo'
  const labelCol = { span: 7 };
  const wrapperCol = { span: 17 };
  const props = defineProps({
    element: Object,
    schemeCode:String,
    pageType: String,
    pageView: String,
  })
  let node = ref({
    id: '',
    isAsync: false,
    wfschemeId: '',
    wfVersionId: '',
  })
  const data = reactive({
    componentDisabled: props.pageType == 'detail' ? true : false
  })
  const list = ref([])
  const verisons = ref([])
  watch(
    () => props.element,
    (newVal, oldVal) => {
      if (newVal.type == "bpmn:SubProcess") {
        node.value.id = newVal.id
        node.value.type = newVal.type
        if(props.pageType == 'detail'){
          getNode()
        }
        if(props.schemeCode) {
          getDetailInfo()
        }
      }
    }
  )
  function getNode(){
    var content = JSON.parse(props.pageView)
      content.wfData.forEach(element => {
        if (element.id == node.value.id) {
          node.value = element
        }
      });
  }
  async function getSchemeList(){
    const data = await getLoad()
    list.value = data
  }
  async function getDetailInfo() {
    let data = await getDetail({ code: props.schemeCode })
    let scheme = JSON.parse(data.scheme.content);
    let wfData = scheme.wfData
    wfData.forEach(element => {
      if(element.id == node.value.id){
        node.value = element
      }
    });
   
  }
 async function changeScheme(){
  const data = await getVerisonsLoad({id:node.value.wfschemeId})
  verisons.value = data
 }
  onMounted(() => {
    getSchemeList()
    if (props.schemeCode) {
      getDetailInfo()
    }
  })
  function getForm() {
    if (node.value.id != '') {
      return node.value
    }
  }
  defineExpose({
    getForm
  })
</script>

<style>
</style>