<template>
  <div class="add-node-btn-box">
    <div class="add-node-btn">
      <el-popover placement="right-start" v-model="visible">
        <div class="add-node-popover-body">
          <a class="add-node-popover-item approver" @click="addType(1)">
            <div class="item-wrapper">
              <i class="el-icon-user" />
            </div>
            <p>审批人</p>
          </a>
          <a class="add-node-popover-item condition" @click="addType(4)">
            <div class="item-wrapper">
              <i class="el-icon-share" />
            </div>
            <p>条件分支</p>
          </a>
        </div>
        <button class="btn" type="button" slot="reference" v-show="modifiable">
          <div style="width: 30px;height: 30px;border-radius: 50%;background-color: #fff;">
            <i class="el-icon-plus" />
          </div>
        </button>
      </el-popover>

    </div>
  </div>
</template>
<script>
import yid from "yid";

export default {
  props: ["childNodeP", "modifiable"],
  data() {
    return {
      visible: false,
    };
  },
  methods: {
    addType(type) {
      this.visible = false;
      if (type != 4) {
        var data;
        if (type == 1) {
          data = {
            nodeId: yid(),
            nodeName: "审核人",
            error: true,
            type: 1,
            childNode: this.childNodeP,
            companyId: undefined,
            auditorType: { value: "1", label: "指定用户审批" },
            users: [],
            roles: [],
            signType: { value: "2", label: "或签" },
          };
        } else if (type == 2) {
          data = {
            nodeId: yid(),
            nodeName: "抄送人",
            error: true,
            type: 2,
            companyId: this.companyId,
            ccSelfSelectFlag: 1,
            childNode: this.childNodeP,
            nodeUserList: [],
          };
        }
        this.$emit("update:childNodeP", data);
      } else {
        this.$emit("update:childNodeP", {
          nodeId: yid(),
          nodeName: "路由",
          type: 4,
          childNode: null,
          conditionNodes: [
            {
              nodeId: yid(),
              nodeName: "条件1",
              error: true,
              type: 3,
              priorityLevel: 1,
              childNode: this.childNodeP,
              expression: "",
            },
            {
              nodeId: yid(),
              nodeName: "其他",
              type: 3,
              priorityLevel: 999,
              childNode: null,
              expression: "",
            },
          ],
        });
      }
    },
  },
};
</script>

<style scoped>
.dingflow-design .add-node-btn {
  user-select: none;
  width: 240px;
  padding: 20px 0 32px;
  display: flex;
  -webkit-box-pack: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-box-flex: 1;
  flex-grow: 1;
}

.dingflow-design .add-node-btn .btn {
  outline: none;
  box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.1);
  width: 40px;
  height: 40px;
  background: #abb4cb;
  border-radius: 50%;
  position: relative;
  border: none;
  line-height: 30px;
  -webkit-transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
  transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
  cursor: pointer;
  display: flex;
  justify-items: center;
  align-items: center;
}

.dingflow-design .add-node-btn .btn .iconfont {
  color: #fff;
  font-size: 16px;
}

.dingflow-design .add-node-btn .btn:hover {
  transform: scale(1.3);
  box-shadow: 0 13px 27px 0 rgba(0, 0, 0, 0.1);
}

.dingflow-design .add-node-btn .btn:active {
  transform: none;
  background: #1e83e9;
  box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.1);
}

.item-wrapper .el-icon-plus,
.btn .el-icon-plus {
  color: #abb4cb;
}

.add-node-popover-body {
  display: flex;
}

.approver_content .vue-treeselect .vue-treeselect__control,
.approver_content .el-input,
.approver_content .el-input__inner {
  width: 220px;
}

.add-node-popover {
  min-height: 160px;
}

.add-node-popover-header {
  position: relative;
  margin-bottom: 15px;
}

.add-node-popover-close {
  cursor: pointer;
  position: absolute;
  top: 5px;
  right: 5px;
  color: rgba(0, 0, 0, 0.25);
}

.add-node-popover-body {
  display: flex;
}

.add-node-popover-item {
  margin-right: 10px;
  cursor: pointer;
  text-align: center;
  flex: 1;
  color: #191f25 !important;
}

.add-node-popover-item .item-wrapper {
  user-select: none;
  display: inline-block;
  width: 80px;
  height: 80px;
  margin-bottom: 5px;
  padding-top: 3px;
  background: #fff;
  border: 1px solid #e2e2e2;
  border-radius: 50%;
  transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
  font-size: 50px;
}

.add-node-popover-item .iconfont {
  font-size: 35px;
  line-height: 80px;
}

.add-node-popover-item.approver .item-wrapper {
  color: #ff943e;
}

.add-node-popover-item.notifier .item-wrapper {
  color: #3296fa;
}

.add-node-popover-item.condition .item-wrapper {
  color: #15bc83;
}

.add-node-popover-item.auto .item-wrapper {
  color: #1059fb;
}

.add-node-popover-item:hover .item-wrapper {
  background: #3296fa;
  box-shadow: 0 10px 20px 0 rgba(50, 150, 250, 0.4);
}

.add-node-popover-item:hover .iconfont {
  color: #fff;
}

.add-node-popover-item:active .item-wrapper {
  box-shadow: none;
  background: #eaeaea;
}
</style>
