<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 { zoneQuery, zoneCreate } 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 = {
        Filters: `RoomID="${this.params.RoomID}"`,
        ZoneType: this.params.zone
      }
      zoneQuery(pa, res => {
        this.spaceDetails = res.Content[0];
      })
    },
    // 设置iframe
    setFrame() {
      this.iframeSrc = this.params.isMyTab == 2 ?
        `${process.env.BASE_URL}:8889/#/details?perjectId=${this.projectId}&secret=${this.secret}&FmId=${this.params.RoomID}&type=0&code=${this.params.zone}`
        : `${process.env.BASE_URL}:8889/#/changeMess?perjectId=${this.projectId}&secret=${this.secret}&id=${this.params.RoomID}&type=${this.params.zone}`;
    },
    // 删除业务空间
    deleteSpace() {
      this.$confirm("此操作将删除业务空间，是否继续？", "提示", {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let pa = [{RoomID: this.spaceDetails.RoomID}]
        zoneCreate(pa, res => {
          this.$message.success('删除成功')
          this.goBack()
        })
      }).catch(() => {
        this.getData()
        this.$message("取消删除")
      })
    }
  }
};
</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>
