<template>
  <div class="box">
    <div class="condition">
      <div class="header">
        <el-button style="float:left;" size="small" type="default" icon="el-icon-back" @click="goBack"></el-button>
        <span>{{spaceDetails.RoomLocalName||spaceDetails.RoomName||''}}</span>
      </div>
      <el-row class="spaceTypes">
        <div class="types">
          <el-tabs v-model="activeTab" type='card'>
            <template v-for="(item,index) in tabsList">
              <el-tab-pane :name="item.Code" :key="index" :label="item.Name"></el-tab-pane>
            </template>
          </el-tabs>
        </div>
        <div class="deleBtn">
          <el-button size="small" @click="deleteSpace">删除业务空间</el-button>
        </div>
      </el-row>
      <div v-if="activeTab=='detail'" style="height:calc(100% - 110px)">
        <iframe height="100%" width="100%" :src="iframeSrc"></iframe>
      </div>
      <!-- 空间内设备列表--服务于空间的设备 -->
      <eqToSpaceTable v-else-if="activeTab=='equipment' || activeTab=='equipmentFor'" :params="params" :type="activeTab"></eqToSpaceTable>
      <!-- 空间内系统 -->
      <syInSpaceTable v-else-if="activeTab=='generalSystem'" :params="params" :type="activeTab"></syInSpaceTable>

    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex"
import { queryZone, deleteZone } from '@/api/scan/request'
import eqToSpaceTable from '@/components/business_space/newTables/eqToSpaceTable'
import syInSpaceTable from '@/components/business_space/newTables/syInSpaceTable'
export default {
  data() {
    return {
      params: {}, //参数-包含空间id 分区类型 进入方式（1-平面图 2-列表）
      tabsList: [
        { Code: 'detail', Name: '空间详情' },
        { Code: 'equipment', Name: '空间内设备' },
        { Code: 'equipmentFor', Name: '服务于空间的设备' },
        { Code: 'generalSystem', Name: '空间内系统' },
      ], //tab页
      activeTab: 'detail', //当前选中的tab
      spaceDetails: {}, //空间信息
      iframeSrc: '', //空间详情iframe
    }
  },
  computed: {
    ...mapGetters("layout", ["projectId", "userId", "secret"])
  },
  components: {
    eqToSpaceTable,
    syInSpaceTable
  },
  created() {
    this.params = this.$route.query;
    this.getSpaceDetails();
    this.setFrame()
  },
  mounted() { },
  watch: {
    projectId() { }
  },
  methods: {
    // 返回
    goBack() {
      this.$router.push({
        name: "spacelist",
        params: this.params
      })
    },
    // 查询空间详情
    getSpaceDetails() {
      let pa = {
        data: {
          Filters: `RoomID="${this.params.RoomID}"`
        },
        zone: this.params.zone
      }
      queryZone(pa, res => {
        this.spaceDetails = res.Content[0];
        this.params.BuildingId = this.spaceDetails.BuildingId;
        this.params.FloorId = this.spaceDetails.FloorId;
      })
    },
    // 设置iframe
    setFrame() {
      this.iframeSrc =
        `${process.env.BASE_URL}:8889/#/details?perjectId=${this.projectId}&secret=${this.secret}&FmId=${this.params.RoomID}&type=0&code=${this.params.zone}`;
    },
    // 删除业务空间
    deleteSpace() {
      let pa = {
        data: [{
          Id: this.spaceDetails.RoomID
        }],
        zone: this.params.zone
      }
      deleteZone(pa, res => {
        console.log(res)
      })
    }
  }
};
</script>

<style scoped lang='less'>
.box {
  .condition {
    padding: 10px;
    display: flex;
    height: 100%;
    flex-direction: column;
    border: 1px solid #dfe6ec;
    background: #fff;
    margin-bottom: 10px;
    .header {
      padding-bottom: 10px;
      span {
        line-height: 33px;
        margin-left: 15px;
      }
    }
    .spaceTypes {
      .types {
        float: left;
        width: calc(100% - 200px);
        /deep/ .el-tabs__item.is-top {
          border-top: 2px solid transparent;
          &.is-active {
            border-top: 2px solid #409eff;
          }
        }
      }
      .deleBtn {
        float: left;
        width: 200px;
        text-align: right;
        height: 40px;
        border-bottom: 1px solid #e4e7ed;
      }
    }
    .main {
      margin-top: 10px;
      height: calc(100% - 96px);
    }
    .footer {
      margin-bottom: 10px;
    }
  }
}
</style>

<style lang="less">
.el-table th {
  background-color: #d9d9d9;
  color: #000;
}
</style>

