<template>
  <div class="design_contain">
    <el-button @click="getData">获取参数</el-button>
    <WorkFlow ref="workFlow" />
  </div>
</template>

<script>
import WorkFlow from "@/components/work-flow/super-flow";

export default {
  components: {
    WorkFlow
  },
  methods: {
    getData() {
      let self = this;
      let data = self.$refs.workFlow.getData();
      console.log(data);
      let start_num = 0;
      let end_num = 0;
      let start_id = "";
      let end_id = "";
      let start_before = 0;
      let end_after = 0;
      data.nodeList.forEach(item => {
        if (item.meta.type == 0) {
          start_num++;
          start_id = item.id;
        }
        if (item.meta.type == 1) {
          end_num++;
          end_id = item.id;
        }
      });
      data.linkList.forEach(item => {
        if (start_id == item.endId) {
          start_before++;
        }
        if (end_id == item.startId) {
          end_after++;
        }

      });
      if (start_num != 1 || end_num != 1) {
        this.$message({
          message: "开始节点与结束节点均应有且只有一个",
          type: "warning"
        });
      } else if (start_before != 0) {
        this.$message({
          message: "开始节点前面不应连接其它节点",
          type: "warning"
        });
      } else if (end_after != 0) {
        this.$message({
          message: "结束节点后面不应连接其它节点",
          type: "warning"
        });
      }
    }
  }
};
</script>

<style scoped>
.design_contain {
  width: 100%;
  padding: 0 20px;
  margin-bottom: 20px;
}
</style>
