<!-- 开始节点配置 -->
<template>
  <div class="start-event">
    <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
        v-if="data.conditionsOptions && data.conditionsOptions.length > 0"
        label="流转条件"
      >
        <a-select
          v-model:value="node.lineConditions"
          placeholder="请选择"
          :options="data.conditionsOptions"
          :field-names="{ label: 'name', value: 'code' }"
        >
        </a-select>
      </a-form-item>
    </a-form>
  </div>
</template>

<script lang="ts" setup>
  import { ref, reactive, defineProps, onMounted, watch } from 'vue';
  import { flowStore } from '@/store/modules/flow';
  const flowWfDataStore = flowStore();
  const props = defineProps({
    element: {
      type: Object,
      default: () => {
        return {};
      },
    },
    pageType: String,
  });
  const labelCol = { span: 7 };
  const wrapperCol = { span: 17 };
  let node: any = ref({});
  const data = reactive({
    conditionsOptions: [],
    componentDisabled: props.pageType == 'detail' ? true : false,
  });
  watch(
    () => props.element,
    (newVal, oldVal) => {
      if (newVal.type == 'bpmn:SequenceFlow') {
        console.log(props);

        const currentNode = flowWfDataStore.getWfDataNode(newVal.id);
        if (currentNode) {
          node.value = currentNode;
        } else {
          node.value = newVal;
        }
        getConditions();
      }
    },
  );
  onMounted(() => {});

  function getConditions() {
    /**
       ExclusiveGateway:'排他网关',
       Task:'审核节点',
    */
    let wfdata = flowWfDataStore.getWfData;
    wfdata.forEach((element:{
      id:string;
      conditions:any;
      btnlist:any;
      type:string
    }) => {
      if (element.id == node.value.from) {
        if (element.type == 'bpmn:ExclusiveGateway') {
          data.conditionsOptions = element.conditions;
        } else if (element.type == 'bpmn:Task') {
          data.conditionsOptions = element.btnlist.filter((t) => !t.hidden);
        } else {
          data.conditionsOptions = [];
        }
      }
    });
  }
</script>

<style></style>
