<!--
 * @Author: your name
 * @Date: 2022-01-11 13:44:17
 * @LastEditTime: 2022-02-22 15:09:22
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /test/hello-world/src/views/Home.vue
-->
<template>
  <div class="home bigwindow">
    <div class="goSystem" @click="$router.push('/index')">进入管理系统</div>
    <div id="map"></div>
    <Center :show="show" :centerData="centerData" />
    <PipeColor />
    <!-- 底部按钮 -->
    <div class="home-div">
      <img
        src="@/assets/mapinages/bottombanner.png"
        alt=""
        style="width: 100%; height: 100%; z-index: 999"
      />
      <div class="listingsSty fangy">
        <div
          @click="allCompany"
          :class="selarr.length == 3 ? 'active' : ''"
          class="firsty"
        >
          全部
        </div>
        <div
          class="firsty"
          :class="selarr.indexOf(item.val) >= 0 ? 'active' : ''"
          v-for="(item, index) in typeList"
          :key="item.val"
          @click="sel(index, item)"
        >
          {{ item.name }}
        </div>
      </div>
    </div>

    <!-- 设备按钮 -->
      <div class="typelist-div">
        <div class="list" v-for="(item,index) in arr" :key="index" :class="item.ischeck==true?'active':''" @click="sel1(index,item)">
          {{item.name}}
        </div>
      </div>
 

    <!-- 弹框 -->
    <div
      id=""
      style="position: fixed; top: 0; right: 0; width: 100px; height: 100px"
    >
      <!-- <markerInfoWindow></markerInfoWindow> -->
    </div>

    <!-- 头部 -->
    <div class="banner-test">
      <!-- <dv-decoration-5 style="width:100%;height:100%;" /> -->
      <img src="@/assets/mapinages/topbanner.png" alt="" />
    </div>

    <!-- 左边 -->
    <div class="leftbar">
      <leftBar ref="mychild2"></leftBar>
    </div>
    <!-- 右边 -->
    <div class="rightbar">
      <rightBar ref="mychild"></rightBar>
    </div>

    <!-- 左上角天气 -->
    <div
      class="weather"
      style="
        position: fixed;
        top: 0;
        margin-top: 10px;
        margin-left: 15px;
        left: 0;
        z-index: 999;
        width: 300px;
        height: 50px;
      "
    >
      <!-- <iframe src="../../static/weather.html" frameborder="0"></iframe> -->
      <iframe
        scrolling="no"
        src="https://tianqiapi.com/api.php?style=tz&skin=pitaya&color=339CC9"
        frameborder="0"
        width="400"
        height="30"
        allowtransparency="true"
      ></iframe>
      <!-- <iframe scrolling="no" src="https://yiketianqi.com/api.php?style=ty&skin=pitaya" frameborder="0" width="300" height="75" allowtransparency="true"></iframe> -->
    </div>

    <!-- 右上角时间 -->
    <div
      class="right-time"
      style="
        position: fixed;
        top: 0;
        margin-top: 10px;
        margin-right: 15px;
        right: 0;
        z-index: 999;
        width: 200px;
        height: 50px;
        color: #339CC9;
      "
    >
      <div style="height: 20px; width: 100%; float: right; font-size: 14px;">
        {{ nowDate }}&nbsp;{{ nowtime }}&nbsp;{{ nowweek }}
      </div>
    </div>
  </div>
</template>

<script>
// @ is an alias to /src
import { EditorMap } from "@/utils/mapClass/map";
import {
  pipeData,
  tiaoyaxiang,
  famen,
  changzhan,
  jiankong,
  user,
} from "@/utils/mapClass/config.js";
import Line from "@/components/bigWindow/Line.vue";
import VideoView from "@/components/bigWindow/VideoView.vue";
import DeviceA from "@/components/bigWindow/DeviceA.vue";
import User from "@/components/bigWindow/User.vue";
import Center from "@/components/bigWindow/Center.vue";
import PipeColor from "@/components/bigWindow/PipeColor.vue";

// import markerInfoWindow from './components/markerInfoWindow.vue'
import leftBar from "@/components/bigWindow/leftBar.vue";
import rightBar from "@/components/bigWindow/rightBar.vue";
export default {
  name: "Home",
  components: {
    leftBar,
    rightBar,
    Center,
    PipeColor,
  },
  data() {
    return {
      map: null,
      show: false,
      centerData: null,
      selarr: [1, 2, 3],
      weather: "",
      lower: "",
      higher: "",
      nowDate: "",
      nowweek: "",
      nowtime: "", // 当前日期

      typeList: [
        {
          val: 1,
          name: "中燃翔科",
        },
        {
          val: 2,
          name: "中诚然气",
        },
        {
          val: 3,
          name: "中燃韵科",
        },
      ],
      arr:[
        {
          val:1,
          ischeck:false,
          name: "调压箱"
        },
        {
          val:2,
          ischeck:false,
          name: "阀门井"
        },
        {
          val:3,
          ischeck:false,
          name: "场站"
        },
        {
          val:4,
          ischeck:false,
          name: "用户"
        },
        {
          val:5,
          ischeck:false,
          name: "监控"
        }
      ],
        selarr1:[],
        };
      },
  watch: {
    selarr(newValue) {
      if (newValue.length == 3) {
        this.$refs.mychild.choice(0);
        this.$refs.mychild2.choice(0);
      }
    },
  },
  mounted() {
    const path = eval(this.$store.state.user.systemSetting.map_center);
    this.map = new EditorMap(
      "map",
      {
        center:path,
        mapStyle: "amap://styles/f71d3a3d73e14f5b2bf5508bf1411758",
        zoom: 14.5,
      },
      this
    );
    this.addPipeLine();
    this.addDevice(tiaoyaxiang, DeviceA);
    this.addDevice(famen, DeviceA);
    this.addDevice(changzhan, DeviceA);
    this.addDevice(user, User);
    this.addDevice(jiankong, VideoView);

    this.currentTime();
    this.$refs.mychild.choice(0);
    this.$refs.mychild2.choice(0);
  },
  methods: {
    addPipeLine() {
      for (let comp in pipeData) {
        pipeData[comp].forEach((pipe) => {
          this.map.addPipeLine(pipe, Line);
        });
      }
    },
    // 设备上图
    addDevice(data, component) {
      for (let comp in data) {
        data[comp].forEach((pipe) => {
          this.map.addDevice(pipe, component);
        });
      }
    },
    centerShow(boolean) {
      this.show = boolean;
    },
    centerDataFunc(centerData) {
      this.centerData = centerData;
      console.log(centerData);
      this.show = true;
    },

    allCompany() {
      if (this.selarr.length == 3) {
        this.selarr = [];
      } else {
        this.selarr = [1, 2, 3];
      }

      this.map.companyFilter(this.selarr);
      this.map.infowindowClose();
      this.show = false;
    },
    sel(index, item) {
      this.map.infowindowClose();
      this.show = false;
      const ind = this.selarr.indexOf(item.val);
      if (ind >= 0) {
        this.selarr.splice(ind, 1);
        if (item.val == 3) {
          this.$refs.mychild.choice(1);
          this.$refs.mychild2.choice(1);
        } else {
          this.$refs.mychild.choice(item.val + 1);
          this.$refs.mychild2.choice(item.val + 1);
        }
      } else {
        this.selarr.push(item.val);
        this.$refs.mychild.choice(item.val);
        this.$refs.mychild2.choice(item.val);
      }
      this.map.companyFilter(this.selarr);
    },

    sel1(index,item){
      let arr=[...this.arr];
      let selarr1=[...this.selarr1];
      if(arr[index].ischeck==false){
      arr[index].ischeck=true;
      selarr1.push(item)
      }else{
      arr[index].ischeck=false;
      var index11=selarr1.indexOf(index)
      selarr1.splice(index11,1)
      
      }
      
      this.arr=arr;
      this.selarr1=selarr1;
      
    },

    currentTime() {
      setInterval(() => {
        this.formatDate();
      }, 1000);
    },
    formatDate() {
      let date = new Date();
      let year = date.getFullYear(); // 年
      let month = date.getMonth() + 1; // 月
      let day = date.getDate(); // 日
      let week = date.getDay(); // 星期
      let weekArr = [
        "星期日",
        "星期一",
        "星期二",
        "星期三",
        "星期四",
        "星期五",
        "星期六",
      ];
      let hour = date.getHours(); // 时
      hour = hour < 10 ? "0" + hour : hour; // 如果只有一位，则前面补零
      let minute = date.getMinutes(); // 分
      minute = minute < 10 ? "0" + minute : minute; // 如果只有一位，则前面补零
      let second = date.getSeconds(); // 秒
      second = second < 10 ? "0" + second : second; // 如果只有一位，则前面补零
      this.nowtime = `${hour}:${minute}:${second}`;
      this.nowweek = `${weekArr[week]}`;
      this.nowDate = `${year}年${month}月${day}`;
    },
  },
  // 销毁定时器
  beforeDestroy() {
    if (this.formatDate) {
      clearInterval(this.formatDate); // 在Vue实例销毁前，清除时间定时器
    }
  },
};
</script>
<style lang="scss" scoped>
.home {
  position: relative;
  height: 100vh;
}
.goSystem {
  position: fixed;
  z-index: 9999;
  top: 50px;
  right: 20px;
  font-size: 14px;
  color: #18baff;
  cursor: pointer;
  padding: 3px 5px;
  border: 1px solid #339CC9;
  color: #339CC9;
  &:hover {
    background-color: #053B6A ;
    color: #2CD5DB;
  }
}
#map {
  position: absolute;
  top: 0px;
  bottom: 0;
  width: 100%;
}
.banner-test {
  width: 100%;
  height: 85px;
  position: relative;
  top: 0;
  z-index: 999;
}
.banner-test img {
  width: 100%;
  height: 100%;
}

.leftbar {
  width: 450px;
  height: 90%;
  position: fixed;
  top: 10%;
  left: 0;
  background: #112238;
}
.rightbar {
  width: 450px;
  height: 90%;
  position: fixed;
  top: 10%;
  right: 0;
  background: #112238;
}
.home-div {
  width: 50%;
  height: 70px;
  position: fixed;
  bottom: 0;
  margin-left: 25%;
  z-index: 1000;
}
.listingsSty {
  /* height: 25px; */
  position: fixed;
  /* border: 1px solid #fff; */
  bottom: 0;
  margin-bottom: 10px;
  width: 30%;
  margin-left: 10%;
    // font-family: 'arialbd';
}
.firsty {
  width: 15%;
  height: 35px;
  text-align: center;
  line-height: 35px;
  /* border: 1px solid #fff; */
  color: #fff;
  font-size: 16px;
  float: left;
  margin-left: 8%;
  cursor: pointer;
  // font-family: 'arialbd';
}
.active {
  color: #2ee7e7;
  background: url(../../assets/mapinages/background.png);
  background-repeat: no-repeat;
  background-size: 100% 100%;
  font-size: 18px;

  /*position:relative;*/
  /*&::after{
    width: 80px;
    height: 50px;
    z-index: -1;
    content: " ";
    position: absolute;
    top: -7px;
    left: 50%;
    margin-left:-40px;
    background: url(/img/bac1.0ec28f27.png);
    background-repeat: no-repeat;
    background-size: 100% 100%;
    background-position: center;
    color: aquamarine;
  }*/
}
.weather-icon {
  float: left;
  width: 30px !important;
  height: 30px !important;
  margin-top: 10px !important;
  margin-left: 10px !important;
  padding-right: 5px;
}
.tttt {
  background-image: -webkit-linear-gradient(
    bottom,
    rgb(134, 185, 233),
    #ffffff
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.typelist-div{
  width: 450px;
  height: 50px;
  z-index: 9999;
  position: fixed;
  bottom: 20%;
  left: 40%;
}
.list{
  z-index: 9999;
  float: left;
  margin-left: 10px;
  color: #fff;
  width: 80px;
  height: 30px;
  line-height: 30px;
  text-align: center;
  background: linear-gradient(86deg, #112238 0%, #086187 62%, #112238 100%);
  box-shadow: inset 0px 1px 2px 1px #125C9B;
}
 
.list.active{
  background: linear-gradient(86deg, #112238 0%, #32A3D3 62%, #112238 100%);
  box-shadow: inset 0px 1px 2px 1px #125C9B;
  color: #2ee7e7;
}
</style>
