<template>
  <div>
    <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
      <div class="nav">
        <div v-for="(item, index) in navtopData" :key="index" :class="{ 'nav-item-active': activeNav == index }"
          @click="clickNav(item, index)" class="nav-item" style="font-size: 12px">
          {{ item.name }}
        </div>
      </div>
      <div class="mostHead" v-if="activeName == 'first' && activeNav == 0">
        <h2 style="display: inline-block; margin-right: 2px; font-size: 20px">
          CID文件一次性检测
        </h2>
        <el-button type="primary" plain @click="portExcel">结果导出Excel</el-button>
        <span class="closeX" @click="closeX">×</span>
      </div>
      <el-tab-pane label="网络结构图" name="first">
        <net-work v-if="activeName == 'first' && activeNav == null"></net-work>
        <div class="disappear" v-if="activeName == 'first' && activeNav == 0">
          <!-- 左侧树形数据 -->
          <div style="width: 15%">
            <CidTree :nowScdId="nowScdId" @treeBack="treeBack"></CidTree>
          </div>
          <!-- 右侧展示图 -->
          <div style="width: 85%; height: calc(100vh - 280px); position: relative">
            <div class="abBox">
              <div>
                <span style="
                    border-right: 1px solid black;
                    padding-right: 300px;
                    font-size: 12px;
                  ">
                  基准文件:{{ arrName }}
                </span>
              </div>
              <div>
                <span style="font-size: 12px"> 对比文件:{{ upName }} </span>
              </div>
              <div class="uploadBox">
                <el-upload ref="upload" class="upload-demo" :http-request="nowUpload" :limit="2"
                  element-loading-text="上传中..." element-loading-background="rgba(255, 255, 255, 0.8)"
                  :on-remove="handleRemove" :on-change="fileSuccess" :show-file-list="false">
                  <template #trigger>
                    <el-button style="border-bottom: 1px solid #7bbafd" type="text" plain>上传CID</el-button>
                  </template>
                </el-upload>
              </div>
            </div>
            <Gsix :activeName="activeName" :activeNav="activeNav" :backName="backName" :mustVal="mustVal"
              :arrName="arrName" :upName="upName"></Gsix>
          </div>
        </div>
        <div class="scdCheck" v-if="activeName == 'first' && activeNav == 1">
          <div class="mostHead" v-if="activeName == 'first' && activeNav == 1">
            <div class="scd-title">SCD文件一次性检测</div>
            <span class="closeX" @click="closeX">×</span>
          </div>
          <!-- 右侧内容 -->
          <div
            style="
              width: 97%;
              display: flex;
              justify-content: space-between;
              align-items: center;
              margin-top: 5px;
            ">
            <div class="treeBtn">
              <scdTree :nowStation="nowStation" @scdTreeBack="scdTreeBack"></scdTree>
            </div>
            <div class="scdMap">
              <scdMap :antherBack="antherBack" :activeNav="activeNav"></scdMap>
            </div>
          </div>
        </div>
        <CrcCheck v-if="activeName == 'first' && activeNav == 3" :nowScdId="nowScdId"></CrcCheck>
        <SlcCheck v-if="activeName == 'first' && activeNav == 2" :nowScdId="nowScdId"></SlcCheck>
        <!-- 虚端子关系图 -->
        <div v-if="clickNavCode == 'virtual'">
          <!-- <virtual-relation 
            :checkData="checkData"
            :isOpen="isOpen"
            :iedRelation="iedRelation"
            @result="result">
          </virtual-relation> -->
        </div>
      </el-tab-pane>
      <el-tab-pane label="SCD可视化" name="second">
        <scd-visual v-if="!clickNavCode"></scd-visual>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>
  

<script setup>
import { ref, watch, onMounted } from "vue";
import netWork from "./components/netWork";
import scdVisual from "./components/scdVisual";
import CidTree from "./components/CidTree.vue";
import Gsix from "./components/Gsix.vue";
import scdTree from "./components/scdTree.vue";
import scdMap from "./components/scdMap.vue";
import CrcCheck from "./newTitle/CrcCheck";
import SlcCheck from "./newTitle/SlcCheck.vue";
import { useRoute } from "vue-router";
import cid from "@/api/cid/cid";
import { ElMessage } from "element-plus";
import systemRow from "@/api/systemRow";
import scdCheck from "@/api/scdCheck/scdCheck";
import virtualRelation from "./components/virtualRelation.vue"; //虚端
let route = useRoute();
const activeName = ref("first"); //默认展示网络结构图
const navtopData = ref([
  { name: "CID一致性校核", code: "CID" },
  { name: "SCD文件一致性校核", code: "SCD" },
  { name: "SCL文件校核", code: "SCL" },
  { name: "CRC校核", code: "CRC" },
  { name: "虚端子关系图", code: "virtual" },
]);
const activeNav = ref(null);
const backName = ref('')//树组件返回名称
let mustVal = ref(false)
let upName = ref('')//上传的文件名称
let arrName = ref('')//基准的文件名称
let upFile = ref({})//上传文件流
let backId = ref('')//返回id
let nowScdId = ref('')//路由传参的scdid
let antherBack = ref([])
let nowStation = ref("")//变电站id
watch(() => antherBack.value, (newVal) => {
  antherBack.value = newVal
}, {
  deep: true
})
const reload = () => {
  nowScdId.value = route.query.id
  nowStation.value = route.query.station
}
// const clickNav = (navIndex) => {  //点击导航栏事件
//   activeNav.value = navIndex;
// }
// const handleClick = (val) => {
//   if (val.props.name == 'first') {
//     activeNav.value = null
//     activeName.value = val.props.name
//   }
// }
// const reload = () => {
//   nowScdId.value = route.query.id;
// };
//虚端子关系====
const isOpen = ref(false);
//虚端子关系====
const clickNavCode = ref(""); //点击导航栏的头部
const clickNav = (item, navIndex) => {
  //点击导航栏事件
  clickNavCode.value = item.code;
  activeNav.value = navIndex;
  switch (item.code) {
    case "virtual":
      isOpen.value = true;
      break;
  }
};
const handleClick = (val) => {
  if (val.props.name == "first") {
    activeNav.value = null;
    activeName.value = val.props.name;
  }
  clickNavCode.value = "";
};
const treeBack = (data, ids) => {
  backName.value = data;
  arrName.value = data;
  backId.value = ids;
  console.log(ids, "ids");
};
const closeX = () => {
  activeName.value = "first";
  activeNav.value = null;
};
const nowUpload = (file, e) => {
  upFile.value = file.file
  upName.value = file.file.name
  cid.fileUpload({ station_id: nowStation.value - 0, file: upFile.value, data_type: "cid" }).then(res => {
    if (res.code == 0) {
      let idp = `${file.file.uid},${backId.value}`
      ElMessage({
        type: 'success',
        message: "上传成功!"
      })
      scdCheck.scdStart({ type: 'cid', station_id: nowStation.value - 0, ids: idp }).then(res => {
        console.log(res, 'show');
      })
    }
  })

};

const handleRemove = (file, e) => {
  console.log(file, e, "删除");
};
const fileSuccess = (file, e) => {
  mustVal.value = true;
};
function scdTreeBack(data) {
  antherBack.value = data;
}
const portExcel = () => {
  systemRow
    .portExcel({
      code: "scd-comp-result",
    })
    .then((res) => {
      if (res.data) {
        return;
      } else {
        ElMessage({
          message: res.msg,
          type: "info",
        });
      }
    });
};
onMounted(() => {
  reload();
});
</script>

<style scoped lang="scss">
$height: 40px;

@mixin mid-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

:deep(.el-tabs__item) {
  margin: 16px 0 0 32px;
  font-size: 18px;
}

:deep(.el-tabs__item:last-child) {
  margin-left: 0;
}

:deep(.el-tabs__nav-wrap::after) {
  --el-border-color-light: none;
}

:deep(.el-tabs__item.is-active),
:deep(.el-tabs__active-bar) {
  color: #255ce7;
}

:deep(.el-tabs__active-bar) {
  background-color: #255ce7;
}

//设置导航栏样式
.nav {
  @include mid-center;

  .nav-item {
    width: 144px;
    height: $height;
    @include mid-center;
    margin-right: 8px;
    cursor: pointer;
    background: #fff url("~@/assets/image/instruct/navtop.png") no-repeat center;
    background-size: 144px $height;
  }

  .nav-item-active {
    background: #fff url("~@/assets/image/instruct/navtop_active.png") no-repeat center;
    background-size: 144px $height;
    color: #fff;
  }
}

//最外层的滚动条不要
:deep(.el-main) {
  // overflow: hidden;
}

//ied的高度
:deep(.network-wrap) {
  height: 70vh;
  overflow: auto;
}

// 头部导出excel
.mostHead {
  width: 97%;
  height: auto;
  border-bottom: 1px solid #a3ade0;
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.closeX {
  font-size: 24px;
  color: #7484ab;
  cursor: pointer;
}

// CID显示
.disappear {
  width: 97%;
  height: calc(100vh - 260px);
  margin: 0 auto;
  display: flex;
  justify-content: flex-start;
  align-items: center;
}

.abBox {
  width: 90%;
  height: 5%;
  display: flex;
  justify-content: space-around;
  align-items: center;
  background-color: white;
  margin-left: 10px;
  position: relative;
}

.uploadBox {
  position: absolute;
  top: 0px;
  right: -100px;
}

.scdCheck {
  width: 97.5%;
  height: calc(100vh - 205px);
  margin: 0 33px;
  // border: 1px solid red;
}

.treeBtn {
  width: 32%;
  // margin-right: 16px;
  height: calc(100vh - 205px);
  // border: 1px solid rebeccapurple;
}

.scdMap {
  width: 67%;
  height: calc(100vh - 205px);
  // border: 1px solid teal;
  background-color: #f6f8fa;
}
//scd一致性校验
.scd-title {
  display: inline-block;
  margin-right: 2px;
  font-size: 16px;
  color: #1a2447;
  padding-bottom: 12px;
}
</style>