<!-- 开始节点配置 -->
<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-form-item>
      <a-form-item label="流程版本">
        <a-select
          v-model:value="node.wfVersionId"
          :options="verisons"
          :fieldNames="{ value: 'id', label: 'createDate' }"
        />
      </a-form-item>
    </a-form>
  </div>
</template>

<script lang="ts" setup>
  import { reactive, defineProps, ref, watch, onMounted } from 'vue';
  import { getLoad, getVerisonsLoad } from '@/api/sys/WFSchemeInfo';
  import { flowStore } from '@/store/modules/flow';

  const flowWfDataStore = flowStore();
  const labelCol = { span: 7 };
  const wrapperCol = { span: 17 };
  const props = defineProps({
    element: {
      type: Object,
      default: () => {
        return {};
      },
    },
    schemeCode: String,
    pageType: String,
    pageView: String,
  });
  let node: any = ref({});
  const data = reactive({
    componentDisabled: props.pageType == 'detail' ? true : false,
  });
  const list: any = ref([]);
  const verisons: any = ref([]);
  watch(
    () => props.element,
    (newVal) => {
      if (newVal.type == 'bpmn:SubProcess') {
        const currentNode = flowWfDataStore.getWfDataNode(newVal.id);
        if (currentNode) {
          node.value = currentNode;
        } else {
          node.value = newVal;
        }
      }
    },
  );

  async function getSchemeList() {
    const data = await getLoad();
    list.value = data;
  }

  async function changeScheme() {
    const data = await getVerisonsLoad({ id: node.value.wfschemeId });
    verisons.value = data;
  }
  onMounted(() => {
    getSchemeList();
    if (props.element.type == 'bpmn:SubProcess') {
      const currentNode = flowWfDataStore.getWfDataNode(props.element.id);
      if (currentNode) {
        node.value = currentNode;
      } else {
        node.value = props.element;
      }
    }
  });

  defineExpose({});
</script>

<style></style>
