<script setup name="childFlow">
import { inject } from 'vue'
defineProps({
  nodeData: Array
})
// 注入父组件方法
const showApprovalDialog = inject('showApprovalDialog'),
  addNode = inject('addNode'),
  removeNode = inject('removeNode')
// 添加节点
const add = (arg) => {
    addNode(arg)
  },
  // 删除
  remove = (con_index, item, index, nodeData) => {
    removeNode(con_index, item, index, nodeData)
  },
  // 配置节点
  choseNode = ({ key, type, item }) => {
    showApprovalDialog({ key, type, item })
  }
</script>

<template>
  <div
    v-for="(item, index) in nodeData"
    :key="index"
    class="childFlow"
  >
    <!--    审批节点-->
    <div v-if="!item.branchs">
      <div class="node flex flex-col justify-center items-center">
        <div
          :class="`box box_${item.type} px-24 py-16 bg-white rounded-4`"
          @click="choseNode({ key: index, type: item.type, item: nodeData })"
        >
          <svg-icon
            name="delIcon"
            svg-class="delIcon"
            @click.stop="remove(index, nodeData)"
          />
          <p class="tit">{{ item.name }}</p>
          <div class="content">
            <template v-if="item.props&&item.props.assignedUser?.length">
              <el-tag
                v-for="(i,key) in item.props.assignedUser"
                :key="key"
                type="info"
                class="mr-4"
              >{{ i.name }}</el-tag>
            </template>
            <span
              v-else
              class="text-info"
            >{{ item.placeholder||'请选择' }}</span>
          </div>
        </div>
        <el-popover
          placement="right"
          :width="100"
          trigger="hover"
        >
          <template #reference>
            <el-icon class="add_icon mt-20 mb-20 cursor-pointer">
              <Plus />
            </el-icon>
          </template>
          <div class="flex flex-col">
            <p>
              <el-button
                class="mb-8 w-full"
                @click="add({ key: index, type: 'APPROVAL', item:nodeData })"
              >
                审批人
              </el-button>
            </p>
            <p>
              <el-button
                class="ml-1 mb-8 w-full"
                @click="add({ key: index, type: 'SEAL', item:nodeData })"
              >
                盖章人
              </el-button>
            </p>
            <p>
              <el-button
                class="ml-1 mb-8 w-full"
                @click="add({ key: index, type: 'CC', item:nodeData })"
              >
                抄送人
              </el-button>
            </p>
            <p>
              <el-button
                class="mb-8 w-full"
                @click="addNode({ key: index, type: 'CONSTRCTION',item:nodeData })"
              >
                建设审批人
              </el-button>
            </p>
          </div>
        </el-popover>
      </div>
    </div>
  </div>
</template>

<style lang="less">
.childFlow{
  width: 100%;
  .node{
    font-size: 14px;
    .line {
      width: 4px;
      height: 20px;
      background: #dcdee2;
    }
    .add_icon{
      width: 24px;
      height: 24px;
      background: #ffffff;
      box-shadow: 0px 4px 8px 0px rgb(9 103 253 / 8%), 0px 6px 13px 0px rgb(9 103 253 / 8%);
      border: 1px solid rgba(9, 103, 253, 0.06);
      border-radius: 100%;
      color: #0967fd;
      z-index:2;
      &:after{
        width: 4px;
        height: 20px;
        background: #dcdee2;
        content: '';
        display: block;
        position: absolute;
        left: 50%;
        transform: translate(-50%, 100%);
        bottom: 0;
      }
      &:before{
        width: 4px;
        height: 20px;
        background: #dcdee2;
        content: '';
        display: block;
        position: absolute;
        left: 50%;
        transform: translate(-50%, 0);
        top: -20px;
      }
    }
    .box{
      z-index: 2;
      background: #ffffff;
      box-shadow: 0px 4px 8px 0px rgba(9, 103, 253, 0.1);
      border-radius: 4px;
      border: 1px solid rgba(9, 103, 253, 0.06);
      width: 200px;
      padding: 8px;
      cursor: pointer;
      position: relative;
      //&:after{
      //  width: 4px;
      //  height: 20px;
      //  background: #dcdee2;
      //  content: '';
      //  display: block;
      //  position: absolute;
      //  left: 50%;
      //  transform: translate(-50%, 100%);
      //  bottom: 0;
      //}
      .tit{
        padding: 4px 8px;
        border-radius: 4px;
        font-weight: 600;
        line-height: 20px;
        margin-bottom: 8px;
        position: relative;
      }
      &.box_APPROVAL{
        .tit {
          background: linear-gradient(270deg, #ffae00 0%, #ff8600 100%);
          color: #ffffff;
        }
      }
      &.box_CONSTRCTION{
        .tit{
          background: linear-gradient(270deg, #D4AA00 0%, #D48600 100%);
          color: #ffffff;
        }
      }
      &.box_condition {
        .tit {
          background: #f5f8fa;
          color: #333333;
        }
      }
      &.box_SEAL{
        .tit{
          background: linear-gradient(270deg, #FE7875 0%, #F5222D 100%);
          color: #ffffff;
        }
      }
      &.box_CC{
        .tit{
          background: #f5f8fa;
          color: #333333;
        }
      }
      &.box_virtualNode {
        display: none;
      }
      &:hover {
        .delIcon {
          display: block;
        }
      }
    }
  }
  .conNode{
    position: relative;
    .conOut{
      background: #fff;
    }
    .topLine{
      height: 4px;
      background: #dcdee2;
      position: absolute;
      left: 0;
      right: 0;
      span {
        display: inline-block;
        position: absolute;
        z-index: 10;
        left: 50%;
        transform: translateX(-50%);
        top: -10px;
        width: 88px;
        height: 24px;
        line-height: 24px;
        border: 1px solid #1b71e3;
        border-radius: 4px;
      }
    }
    &:after{
      height: 4px;
      background: #dcdee2;
      position: absolute;
      left: 0;
      right: 0;
      bottom:0
    }
    .conModel{
      position: relative;
      &:nth-of-type(1) {
        background: #fff;
        z-index: 3;
        &:after {
          content: '';
          position: absolute;
          top: 0;
          width: 50%;
          height: 4px;
          background: #dcdee2;
          right: 0;
        }
        &:before {
          bottom: 0;
          content: '';
          background: #dcdee2;
          height: 4px;
          width: 50%;
          right: 0;
          position: absolute;
        }
      }
      &:last-of-type {
        background: #fff;
        margin-right: 0;
        z-index: 3;
        &:after {
          content: '';
          position: absolute;
          top: 0;
          width: 50%;
          height: 4px;
          background: #dcdee2;
          left: 0;
        }
        &:before {
          bottom: 0;
          content: '';
          background: #dcdee2;
          height: 4px;
          width: 50%;
          left: 0;
          position: absolute;
        }
      }
      &:after{
        content: '';
        position: absolute;
        top: 0;
        width: 50%;
        height: 4px;
        background: #dcdee2;
        right: 0;
      }
    }
    .bot_line{
      height: 4px;
      background: #dcdee2;
      position: absolute;
      left: 0;
      right: 0;
      bottom: 0;
      z-index:2
    }
    .spec_line{
      width: 4px;
      height: 100%;
      position: absolute;
      top: 0;
      left: 50%;
      transform: translateX(-50%);
      background: #dcdee2;
      z-index: 0;
    }
  }
  .delIcon{
    position: absolute;
    width: 24px;
    height: 24px;
    right: -12px;
    top: -12px;
    display: none;
    z-index:99
  }
}

</style>
