<template>
  <div>
    <div class="node-wrap" v-if="nodeConfig.laneLevel === 1">
      <div class="node-wrap-box">
        <div class="node-box-after">
          <div class="nodeBoxTop">{{ spliceNameFun(nodeConfig, 18) }}</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" :title="getAllName(item)">{{ spliceNameFun(item, 18) }}</div>
                  </div>
                  <div v-if="item.partyOrgLevel === 8">
                    <div class="lydxz" :title="getAllName(item)">
                      {{ spliceNameFun(item, 18) }}
                    </div>
                  </div>
                  <div v-if="item.partyOrgLevel === 9">
                    <div class="dyzxh" :title="item.principalName">
                      {{ spliceNameFun(item, 3) }}
                    </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 class="listMsg">
                          <img src="@/assets/images/home/cjr.png" alt="" />
                          <span>残疾人</span>
                        </div>
                        <div class="listMsg">
                          <img src="@/assets/images/home/kclr.png" alt="" />
                          <span>空巢老人</span>
                        </div> -->
                      </div>
                      <div @mouseover="getHomeTypes(item.id)" slot="reference" class="lxjt" :title="item.principalName">
                        {{ spliceNameFun(item, 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: {
    getIncludes(name) {
      if (name.includes("街道党工委") || name.includes("街道党总支")) {
        return true;
      }
    },

    getAllName(item) {
      return item.partyOrgName + item.principalName;
    },

    spliceNameFun(row, num) {
      let allName = row.principalName;
      if (num === 18) {
        allName = row.partyOrgName + row.principalName;
      }
      if (allName.length > num) {
        return allName.substring(0, num) + "...";
      }
      return allName;
    },

    // 家庭类别Map
    getHomeTypesMap(item) {
      const homeTypeMap = new Map([
        ["partyFlag", { name: "党员", icon: "dy" }],
        ["subsistenceAllowanceFlag", { name: "低保人员", icon: "dbry" }],
        ["ensureHouseFlag", { name: "保障房人员", icon: "bzfry" }],
        ["unemployedFlag", { name: "失业人员", icon: "syry" }],
        ["fertileWomanFlag", { name: "育龄妇女", icon: "ylfn" }],
        ["veteranFlag", { name: "退役军人", icon: "tyjr" }],
        ["unitedFrontFlag", { name: "统战人员", icon: "tzry" }],
        ["petitionOfficerFlag", { name: "信访人员", icon: "xfry" }],
        ["volunteerFlag", { name: "志愿者", icon: "zyz" }],
        ["oldPeopleFlag", { name: "老年人", icon: "lnr" }],
        ["emptyNesterFlag", { name: "空巢老人", icon: "kclr" }],
        ["specialSupportFlag", { name: "特扶人员", icon: "tfry" }],
        ["disabledFlag", { name: "失能人员", icon: "snry" }],
        ["dementedFlag", { name: "失智人员", icon: "szry" }],
        ["disabilityFlag", { name: "残疾人", icon: "cjr" }],
        ["seriousIllnessFlag", { name: "大病人员", icon: "dbry" }],
        ["chronicDiseaseFlag", { name: "慢性病人员", icon: "mxbry" }],
        ["specialCrowdFlag", { name: "特殊人群", icon: "tsry" }],
        ["tenantFlag", { name: "租户", icon: "zh" }],
        ["floatingFlag", { name: "流动人员", icon: "ldry" }],
        ["liveAloneFlag", { name: "独居老人", icon: "kclr" }],
        ["publicWelfareFlag", { name: "公益岗人员", icon: "gyg" }],
      ]);
      return [homeTypeMap.get(item).name, homeTypeMap.get(item).icon];
    },

    getHomeTypes(id) {
      this.$http.get(`/actual/base/organizational/structure/getResidentCategoryByHouseId?houseId=${"1495582904602800129"}`).then((res) => {
        const { code, data } = res.data;
        if (code === 0) {
          const newItem = data[0];
          const itemNumOne = Object.keys(newItem).filter((key) => newItem[key] === 1);
          this.homeTypeArr = itemNumOne;
        }
      });
    },
  },
};
</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;
}
.node-box-after {
  .nodeBoxTop {
    font-size: 14px;
    cursor: pointer;
    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%;
    // &::after {
    //   position: absolute;
    //   content: "";
    //   display: block;
    //   top: -7px;
    //   left: -16px;
    //   width: 168px;
    //   height: 164px;
    //   background-image: url(~@/assets/images/home/firstLevel.png);
    //   background-size: 100%;
    // }
  }
}
.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%;
    // &::after {
    //   position: absolute;
    //   content: "";
    //   display: block;
    //   top: -7px;
    //   left: 0;
    //   width: 132px;
    //   height: 96px;
    //   background-image: url(~@/assets/images/home/zbbg.png);
    //   background-size: 100%;
    // }
  }
  .lydxz {
    @include spanLevel;
    @include normalLevel;
    width: 216px;
    height: 50px;
    padding-top: 5px;
    background-image: url(~@/assets/images/home/lydxzTree.png);
    background-size: 100%;
    // &::after {
    //   position: absolute;
    //   content: "";
    //   display: block;
    //   top: -2px;
    //   left: -40px;
    //   width: 216px;
    //   height: 50px;
    //   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%;
    // &::after {
    //   position: absolute;
    //   content: "";
    //   display: block;
    //   top: -19px;
    //   left: -8px;
    //   width: 30px;
    //   height: 118px;
    //   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%;
    // &::after {
    //   position: absolute;
    //   content: "";
    //   display: block;
    //   top: -19px;
    //   left: -8px;
    //   width: 30px;
    //   height: 118px;
    // }
  }
}
</style>
