<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>{{params.Name}}</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="deleteSystem">删除系统</el-button>
        </div>
      </el-row>
      <div v-if="activeTab=='detail'" style="height:calc(100% - 110px)">
        <div>开发中...</div>
      </div>
      <!-- 系统内设备 -->
      <deviceTable v-if="activeTab=='Equipment'" :params="params" :type="activeTab"></deviceTable>
      <!-- 系统所在竖井 -->
      <cenoteTable v-else-if="activeTab=='cenote'" :params="params" :type="activeTab"></cenoteTable>
      <!-- 系统所在业务空间 -->
      <spaceTable v-else-if="activeTab=='space'" :params="params" :type="activeTab" :spaceType="spaceType" :floorType="floorType"></spaceTable>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex"
import { queryLinkSys, deleteGeneralSys, queryDictionaryHead, buildingQuery } from '@/api/scan/request'
import cenoteTable from '@/components/ledger/system/table/cenoteTable'
import deviceTable from '@/components/ledger/system/table/deviceTable'
import spaceTable from '@/components/ledger/system/table/spaceTable'
export default {
  data() {
    return {
      params: {}, //参数-包含系统id 分区类型
      tabsList: [
        { Code: 'detail', Name: '系统详情' },
        { Code: 'Equipment', Name: '系统内设备' },
        { Code: 'cenote', Name: '系统所在竖井' },
        { Code: 'space', Name: '系统所在业务空间' },
      ], //tab页
      activeTab: 'detail', //当前选中的tab
      systemDetails: {}, //系统信息,
      spaceType: {},//空间种类
      floorType: {}
    }
  },
  computed: {
    ...mapGetters("layout", ["projectId", "userId", "secret"])
  },
  components: {
    cenoteTable,
    deviceTable,
    spaceTable
  },
  created() {
    this.params = this.$route.query;
    this.getSystemDetails();

    let pa = {
      Filters: `parentId='Space'`
    }
    queryDictionaryHead(pa, res => {
      res.Content.map(t => {
        if (t.Name != "元空间") {
          this.spaceType[t.Code] = t.Name;
        }
      })
    });

    let param = {
      Cascade: [
        { Name: "floor" }
      ]
    };
    buildingQuery(param, res => {
      res.Content.map(item => {
        if (item.BuildID && item.BuildLocalName) {
          this.floorType[item.BuildID] = item.BuildLocalName;
          if (item.Floor instanceof Array) {
            item.Floor.map(f => {
              if (f.FloorID && f.FloorLocalName) {
                this.floorType[f.FloorID] = f.FloorLocalName;
              }
            })
          }
        }
      });
    });
  },
  mounted() { },
  watch: {
    projectId() { }
  },
  methods: {
    // 返回
    goBack() {
      this.$router.push({
        name: "systemlist",
        params: this.params
      })
    },
    // 查询系统详情
    getSystemDetails() {
      let pa = {
        Filters: `SysID="${this.params.SysID}"`
      }
      queryLinkSys(pa, res => {
        this.systemDetails = res.Content[0];
      })
    },
    // 删除系统
    deleteSystem() {
      this.$confirm("此操作将删除系统，是否继续？", "提示", {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let pa = [{
          SysID: this.systemDetails.SysID
        }]
        this.removeSys(pa)
      }).catch(() => {
        this.$message("取消删除")
      })
    },
    async removeSys(param) {
      await deleteGeneralSys(param, res => {
        this.$message.success("删除成功")
        this.goBack()
      })
    },
  }
};
</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>

