<template>
  <div class="saga-elevation">
    <div v-if="elevationData.length" class="saga-floor">
      <div class="saga-rf"><p class="saga-floorName">RF</p><div class="saga-spaceList"></div></div>
      <div class="saga-floor-item" v-for="floor in elevationData" :key="floor.FloorSequenceID">
        <p class="saga-floorName">{{floor.FloorLocalName}}<i class="el-icon-right"></i></p>
        <div class="saga-spaceList"></div>
      </div>
    </div>
    <div v-else class="saga-center">
      <i class="icon-wushuju iconfont"></i>
      数据暂无
    </div>
  </div>
</template>

<script>
  import { shaftVerticalSpace } from "@/api/scan/request"

  import {mapGetters} from 'vuex'
  export default {
  data () {
    return {
      elevationData: [
        {
          FloorSequenceID: 5,
          FloorLocalName: 'F5',
          ZoneSpaceList: [
            {
              RoomID: 'f5-001',
              RoomLocalName: '业务空间f5-001',
              SpaceIdList: ['f4-002']
            }
          ]
        },
        {
          FloorSequenceID: 4,
          FloorLocalName: 'F4',
          ZoneSpaceList: [{
            RoomID: 'f4-001',
            RoomLocalName: '业务空间f4-001',
            SpaceIdList: ['f3-002']
          }, {
            RoomID: 'f4-002',
            RoomLocalName: '业务空间f4-002',
            SpaceIdList: ['f5-001']
          }]
        },
        {
          FloorSequenceID: 3,
          FloorLocalName: 'F3',
          ZoneSpaceList: [{
            RoomID: 'f3-001',
            RoomLocalName: '业务空间f3-001',
            SpaceIdList: ['f2-002']
          }, {
            RoomID: 'f3-002',
            RoomLocalName: '业务空间f3-002',
            SpaceIdList: ['f2-002','f4-001']
          }]
        },
        {
          FloorSequenceID: 2,
          FloorLocalName: 'F2',
          ZoneSpaceList: [{
            RoomID: 'f2-001',
            RoomLocalName: '业务空间f2-001',
            SpaceIdList: ['f1-001']
          }, {
            RoomID: 'f2-002',
            RoomLocalName: '业务空间f2-002',
            SpaceIdList: ['f3-001','f3-002']
          }, {
            RoomID: 'f2-003',
            RoomLocalName: '业务空间f2-003',
            SpaceIdList: []
          }]
        },
        {
          FloorSequenceID: 1,
          FloorLocalName: 'F1',
          ZoneSpaceList: [{
            RoomID: 'f1-001',
            RoomLocalName: '业务空间f1-001',
            SpaceIdList: ['f2-001']
          }, {
            RoomID: 'f1-002',
            RoomLocalName: '业务空间f1-002',
            SpaceIdList: []
          }, {
            RoomID: 'f1-003',
            RoomLocalName: '业务空间f1-003',
            SpaceIdList: []
          }]
        }
      ]
    }
  },
  computed: {
    ...mapGetters("layout", ["projectId"])
  },
  props: {
    params: Object
  },
  methods: {
    init () {
      console.log(JSON.stringify(this.elevationData))
      // console.log(this.params)
      //// 查询竖井关联的空间垂直交通关系
      // shaftVerticalSpace(this.params, (res) => {
      //   this.elevationData = res.Content
      // })
      let max = 0, idMap = {};
      this.elevationData.reverse().forEach(floor => {
        if (floor.ZoneSpaceList && floor.ZoneSpaceList.length) {
          floor.ZoneSpaceList.forEach(space => {
            if (idMap[space.RoomID]) {
              space.SpaceIdList.forEach(RoomID =>{
                if (!idMap[RoomID]) {
                  idMap[RoomID] = idMap[space.RoomID];
                }
              })
            } else {
              max++;
              idMap[space.RoomID] = max;
              space.SpaceIdList.forEach(RoomID =>{
                if (!idMap[RoomID]) {
                  idMap[RoomID] = max;
                }
              })
            }
          })
        }
      })
      console.log(idMap)
    }
  },
  watch: {
    projectId() {
      if (this.params.buildingId && this.params.objectType && this.params.shaftId) {
        this.init();
      }
      console.log(this.projectId)
    },
    params: {
      handler(val) {
        if (this.params.buildingId && this.params.objectType && this.params.shaftId) {
          this.init();
        }
      },
      immediate: true,
      deep: true,
    }
  }
}
</script>

<style lang="less">
  .saga-elevation {
    height: 100%;
    position: relative;
    .saga-center{
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%,-60%);
      text-align: center;
    }
    .saga-floor {
      display: flex;
      height: 100%;
      box-sizing: border-box;
      flex-direction: column;
      justify-content: flex-end;
      padding: 0 10px 60px 0;
      .saga-rf {
        display: flex;
        flex-direction: row;
        font-size: 12px;
        color: blue;
      }
      .saga-floor-item {
        display: flex;
        flex-direction: row;
        font-size: 12px;
        height: 60px;
        line-height: 60px;
      }
      .saga-floorName {
        width: 50px;
        text-align: right;
      }
      .saga-spaceList {
        flex: 1;
        border-bottom: 2px solid #c1c6d2;
      }
    }
  }

  .block {
    display: inline-block;
    height: 60px;
    line-height: 60px;
    width: 120px;
    text-align: center;
    position: relative;
  }

  .relate {
    background-color: yellow;
    border: 1px solid black;

  }

  .space {
    background-color: #999;
  }
</style>
