<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>{{exampleData.RoomLocalName||exampleData.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'"  class="content">
        <iframe v-if="params.isMyTab == 1" height="100%" width="100%" :src="iframeSrc"></iframe>
        <div v-else class="content-left">
          <div class="content-showType"></div>
          <div class="content-point">
            <div class="content-point-left">
              <el-scrollbar style="height:100%;">
                <div style="height:1000px"></div>
              </el-scrollbar>
            </div>
            <div class="content-point-right">
              <el-scrollbar style="height:100%;">
                <div style="height:1000px"></div>
              </el-scrollbar>
            </div>
          </div>
        </div>
        <div class="content-right">
          <div class="content-repair"></div>
          <div class="content-media">
            <el-scrollbar style="height:100%;">
              <div style="height:1000px"></div>
            </el-scrollbar>
          </div>
        </div>
      </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 tools from "@/utils/scan/tools";
import { getDataDictionary, 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
      pointData: [], //信息点数据
      exampleData: {}, //实例数据
      criterias: [], //动态参数
      iframeSrc: '', //空间详情iframe
    }
  },
  computed: {
    ...mapGetters("layout", ["projectId", "userId", "secret"])
  },
  components: {
    eqToSpaceTable,
    syInSpaceTable
  },
  created() {
    this.params = this.$route.query;
    this.getData();
    this.setFrame();
  },
  mounted() { },
  watch: {
    projectId() { }
  },
  methods: {
    // 返回
    goBack() {
      this.$router.push({
        name: "spacelist",
        params: this.params
      })
    },
    // 查询空间详情
    getData() {
      let params1 = {
        data: {
          Orders: "sort asc",
          PageNumber: 1,
          PageSize: 1000
        },
        type: this.params.zone
      }, params2 = {
        data: {
          Filters: `RoomID='${this.params.RoomID}'`
        },
        zone: this.params.zone
      };
      let promise1 = new Promise((resolve, reject) => {
        getDataDictionary(params1, res => {
          resolve(res)
        })
      })
      let promise2 = new Promise((resolve, reject) => {
        queryZone(params2, res => {
          resolve(res)
        })
      })
      Promise.all([promise1, promise2]).then(values => {
        this.pointData = values[0].Content;
        this.exampleData = values[1].Content[0];
        this.pointData.forEach(item => {
          if (item.InputMode == "L" || item.InputMode == "L1" || item.InputMode == "L2" || item.InputMode == "M") {
            let cur = tools.dataForKey(this.exampleData, item.Path);
            if (cur) {
              this.criterias.push({
                id: exampleData.EquipID,
                code: item.InfoPointCode
              })
            }
          }
        })
      })
    },
    // 设置iframe
    setFrame() {
      this.iframeSrc = `${process.env.BASE_URL}:8889/#/changeMess?perjectId=${this.projectId}&secret=${this.secret}&id=${this.params.RoomID}&type=${this.params.zone}`;
      // 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 = {
          data: [{
            RoomID: this.exampleData.RoomID
          }],
          zone: this.params.zone
        }
        deleteZone(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;
    box-sizing: border-box;
    background: #fff;
    .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;
      }
    }

    .content {
      display: flex;
      flex-direction: row;
      box-sizing: border-box;
      height: calc(100% - 99px);
      .content-left {
        display: flex;
        flex-direction: column;
        flex: 1;
        .content-showType {
          height: 50px;
          border: 1px solid #ccc;
          border-bottom: none;
          box-sizing: border-box;
        }
        .content-point {
          display: flex;
          flex-direction: row;
          height: calc(100% - 50px);
          border: 1px solid #ccc;
          box-sizing: border-box;
          .content-point-left {
            flex: 1;
          }
          .content-point-right {
            width: 400px;
            border-left: 1px solid #ccc;
          }
        }
      }
      .content-right {
        width: 400px;
        margin-left: 10px;
        .content-repair {
          height: 50px;
          margin-bottom: 10px;
          border: 1px solid #ccc;
          box-sizing: border-box;
        }
        .content-media {
          height: calc(100% - 60px);
          border: 1px solid #ccc;
          box-sizing: border-box;
        }
      }
    }

    .main {
      margin-top: 10px;
      height: calc(100% - 96px);
    }
    .footer {
      margin-bottom: 10px;
    }

    /deep/ .el-scrollbar__wrap {
      overflow-x: hidden;
    }
  }
}
</style>

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