<template>
  <div>
    <div class="node-wrap" v-if="nodeConfig.laneLevel === 1">
      <div class="node-wrap-box">
        <div class="node-box-after">
          <div class="nodeBoxTop">
            <nameSplit :item="nodeConfig" areaName="partyOrgName" peopleName="principalName" />
          </div>
        </div>
      </div>
    </div>
    <div class="branch-wrap">
      <div class="branch-box-wrap">
        <div class="branch-box">
          <div class="col-box" v-for="(item, index) in nodeConfig.children" :key="index">
            <div class="condition-node">
              <div class="condition-node-box">
                <div class="auto-judge">
                  <div v-if="item.laneLevel >= 2 && item.laneLevel <= 7 && item.partyOrgLevel < 8">
                    <div class="wgdzb">
                      <div :title="getAllName(item.partyOrgName)">{{ spliceNameFun(item.partyOrgName, 8) }}</div>
                      <!-- <div class="gotoDesc" @click="gotoPersonnel(item.resiId)" :title="getAllName(item.principalName)">{{ spliceNameFun(item.principalName, 12) }}</div> -->
                      <div class="gotoDesc" v-if="item.principalName && !item.principalName.includes(',')" @click="gotoPersonnel(item.resiId)" :title="getAllName(item.principalName)">{{ spliceNameFun(item.principalName, 12) }}</div>
                      <div class="gotoDesc name_more" v-if="item.principalName && item.principalName.includes(',')">
                        <span v-for="(i, k) in getItemNameArr(item.principalName)" :key="i" @click="gotoPersonnel(item.resiId[k])" :title="getAllName(i)">{{ spliceNameFun(i, 12) }}{{ k === getItemNameArr(item.principalName).length - 1 ? "" : "," }}</span>
                        <popTips :item="item" />
                      </div>
                    </div>
                  </div>
                  <div v-if="item.partyOrgLevel === 8">
                    <div class="lydxz">
                      <div :title="getAllName(item.partyOrgName)">{{ spliceNameFun(item.partyOrgName, 8) }}</div>
                      <div class="gotoDesc" v-if="item.principalName && !item.principalName.includes(',')" @click="gotoPersonnel(item.resiId)" :title="getAllName(item.principalName)">{{ spliceNameFun(item.principalName, 12) }}</div>
                      <div class="gotoDesc name_more" v-if="item.principalName && item.principalName.includes(',')">
                        <span v-for="(i, k) in getItemNameArr(item.principalName)" :key="i" @click="gotoPersonnel(item.resiId[k])" :title="getAllName(i)">{{ spliceNameFun(i, 12) }}{{ k === getItemNameArr(item.principalName).length - 1 ? "" : "," }}</span>
                        <popTips :item="item" />
                      </div>
                    </div>
                  </div>
                  <div v-if="item.partyOrgLevel === 9">
                    <div class="dyzxh">
                      <div class="gotoDesc" v-if="item.principalName && !item.principalName.includes(',')" @click="gotoPersonnel(item.resiId)" :title="getAllName(item.principalName)">{{ spliceNameFun(item.principalName, 12) }}</div>
                      <div class="gotoDesc name_more" v-if="item.principalName && item.principalName.includes(',')">
                        <span v-for="(i, k) in getItemNameArr(item.principalName)" :key="i" @click="gotoPersonnel(item.resiId[k])" :title="getAllName(i)">{{ spliceNameFun(i, 12) }}{{ k === getItemNameArr(item.principalName).length - 1 ? "" : "," }}</span>
                        <popTips :item="item" />
                      </div>
                    </div>
                  </div>
                  <div class="lxjtWrap" v-if="item.partyOrgLevel === 10">
                    <el-popover popper-class="popperClass" placement="right" trigger="hover">
                      <div class="popperList">
                        <div style="margin-bottom: 13px">家庭类别</div>
                        <div class="listMsg" v-for="item in homeTypeArr" :key="item">
                          <img :src="require(`@/assets/images/home/${getHomeTypesMap(item)[1]}.png`)" alt="" />
                          <span style="margin-left: 3px">{{ getHomeTypesMap(item)[0] }}</span>
                        </div>
                      </div>
                      <div @click="gotoPersonnel(item.resiId)" @mouseover="getHomeTypes(item.id)" slot="reference" class="lxjt gotoDesc" :title="item.principalName">
                        {{ spliceNameFun(item.principalName, 3) }}
                        <img src="@/assets/images/home/cjr.png" alt="" />
                      </div>
                    </el-popover>
                  </div>
                </div>
              </div>
            </div>
            <nodeWrap v-if="item.children" :nodeConfig.sync="item"></nodeWrap>
            <template v-if="index == 0">
              <div class="top-left-cover-line"></div>
              <!-- <div class="bottom-left-cover-line"></div> -->
            </template>
            <template v-if="index == nodeConfig.children.length - 1">
              <div class="top-right-cover-line"></div>
              <!-- <div class="bottom-right-cover-line"></div> -->
            </template>
          </div>
        </div>
        <!-- <addNode :childNodeP.sync="nodeConfig.childNode"></addNode> -->
      </div>
    </div>
    <nodeWrap v-if="nodeConfig.childNode" :nodeConfig.sync="nodeConfig.childNode"></nodeWrap>
  </div>
</template>
<script>
// import { mapState, mapMutations } from "vuex";
export default {
  props: ["nodeConfig"],
  data() {
    return {
      homeTypeArr: [],
    };
  },
  mounted() {},
  computed: {},
  watch: {},
  methods: {
    getAllName(item) {
      return item;
    },

    getItemNameArr(str) {
      return str.split(",").slice(0, 2);
    },

    spliceNameFun(row, num) {
      if (row && row.length > num) {
        return row.substring(0, num) + "...";
      }
      return row;
    },

    getHomeTypes(id) {
      this.$http.get(`/actual/base/organizational/structure/getResidentCategoryByHouseId?houseId=${"1495582904602800129"}`).then((res) => {
        const { code, msg, data } = res.data;
        if (code === 0) {
          const newItem = data[0];
          const itemNumOne = Object.keys(newItem).filter((key) => newItem[key] === 1);
          this.homeTypeArr = itemNumOne;
        } else {
          this.$message.error(msg);
        }
      });
    },

    gotoPersonnel(id) {
      if (id) {
        this.$router.push({ path: "/organizational/orgPersonnel", query: { user_id: id } });
      } else {
        this.$message.error("无法跳转！");
      }
    },
  },
};
</script>
<style scoped lang="scss">
@mixin spanLevel {
  font-size: 14px;
  color: #fff;
  word-break: break-all;
}
@mixin normalLevel {
  display: flex;
  align-items: center;
  justify-content: space-around;
}

.name_more {
  span {
    &:hover {
      font-weight: bold;
      cursor: pointer;
    }
  }
}
.node-box-after {
  .nodeBoxTop {
    font-size: 14px;
    position: relative;
    color: #fff;
    display: inline-block;
    width: 168px;
    height: 164px;
    padding-top: 10px;
    text-align: center;
    background-image: url(~@/assets/images/home/firstLevel.png);
    background-size: 100%;
    div:nth-child(2) {
      cursor: pointer;
    }
  }
}
.auto-judge {
  .wgdzb {
    @include spanLevel;
    width: 132px;
    height: 96px;
    text-align: center;
    padding-top: 5px;
    background-image: url(~@/assets/images/home/zbbg.png);
    background-size: 100%;
  }
  .lydxz {
    @include spanLevel;
    // @include normalLevel;
    text-align: center;
    width: 216px;
    height: 50px;
    padding-top: 5px;
    background-image: url(~@/assets/images/home/lydxzTree.png);
    background-size: 100%;
  }
  .dyzxh {
    @include spanLevel;
    @include normalLevel;
    height: 118px;
    width: 30px;
    writing-mode: tb-rl;
    margin-top: -12px;
    background-image: url(~@/assets/images/home/dyzxhTree.png);
    background-size: 100%;
  }
  .lxjt {
    @include spanLevel;
    display: flex;
    align-items: center;
    justify-content: space-around;
    height: 118px;
    width: 30px;
    writing-mode: tb-rl;
    margin-top: -12px;
    background-image: url(~@/assets/images/home/dyzxhTree.png);
    background-size: 100%;
  }
}
</style>
