<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'" class="content">
        <div 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>
      <!-- 系统内设备 -->
      <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 { getDataDictionary, 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';
import exhibitionBaseInformation from "@/components/ledger/details/detail/exhibitionBaseInformation";
import exhibitionFile from "@/components/ledger/details/detail/exhibitionFile";
import exhibitionImage from "@/components/ledger/details/detail/exhibitionImage";
import selectRadio from "@/components/ledger/details/detail/selectRadio";
export default {
  data() {
    return {
      params: {}, //参数-包含系统id 分区类型
      tabsList: [
        { Code: 'detail', Name: '系统详情' },
        { Code: 'Equipment', Name: '系统内设备' },
        { Code: 'cenote', Name: '系统所在竖井' },
        { Code: 'space', Name: '系统所在业务空间' },
      ], //tab页
      activeTab: 'detail', //当前选中的tab
      pointData: [], //信息点数据
      exampleData: {}, //实例数据
      spaceType: {},//空间种类
      floorType: {}
    }
  },
  computed: {
    ...mapGetters("layout", ["projectId", "userId", "secret"])
  },
  components: {
    cenoteTable,
    deviceTable,
    spaceTable,
    exhibitionBaseInformation,
    exhibitionFile,
    exhibitionImage,
    selectRadio
  },
  created() {
    this.params = this.$route.query;
    this.getData();

    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
      })
    },
    // 获取表头和实例数据
    getData () {
      let params1 = {
          data: {
            Orders: "sort asc",
            PageNumber: 1,
            PageSize: 1000
          },
          type: this.params.SysType
        }, params2 = {
          Filters: `SysID='${this.params.SysID}'`,
        };
        let promise1 = new Promise((resolve, reject) => {
          getDataDictionary(params1, res => {
            resolve(res)
          })
        })
        let promise2 = new Promise((resolve, reject) => {
          queryLinkSys(params2, res => {
            resolve(res)
          })
        })
        Promise.all([promise1, promise2]).then(values => {
          this.pointData = values[0].Content;
          this.exampleData = values[1].Content[0];
        })
    },
    // 删除系统
    deleteSystem() {
      this.$confirm("此操作将删除系统，是否继续？", "提示", {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let pa = [{
          SysID: this.exampleData.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;
    box-sizing: border-box;
    .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-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>

