<template>
  <div class="header_top">
    <!-- <svg-icon icon-class="Head" :class-name="['headItem']"></svg-icon> -->
    <img style="width:100%;" :src="require('@/assets/images/81/' + skinInfo + '/head.png')" alt="" />
    <div class="dateTime">
      <span>{{ date.ymd }}</span>
      <span>{{ $t("headerTitles.week")[date.week] }}</span>
      <span>{{ batteryInfo }}</span>
      <div @click="openWeather">
        <svg-icon style="width: 20px;height: 20px;cursor: pointer;"  icon-class="weather" ></svg-icon>
      </div>
    </div>
    <setTool ref="setTool"></setTool>
    <systemPopup ref="systemPopup" v-if="showSystem"></systemPopup>
    <weather ref="weather"></weather>
    <!-- <headButton class="headButton"></headButton> -->
  </div>
</template>

<script>
// 右侧按钮弹框
import setTool from "./setTool/setTool.vue";
// 系统设置弹框
import systemPopup from "./systemPopup/systemPopup.vue";
// btn
// import headButton from "./headButton/buttonMenu.vue";
import weather from "./weather/index.vue";

export default {
  name: "index",
  components: {
    setTool,
    systemPopup,
    weather
    // headButton
  },

  data() {
    return {
      xxx: "pause",
      date: {
        ymd: "2023/11/20",
        week: "1",
      },
      showSystem: false, //设置框
      head: "",
      skinInfo: JSON.parse(localStorage.getItem("systemSetting")).skinInfo,
      appVersion: localStorage.getItem("appVersion"),
      batteryInfo: "",
    };
  },
  beforeMount() {
    // this.$sendElectronChanel("getHead");
    // this.$recvElectronChanel("headRes", (e, res) => {
    //
    //   this.head = res;
    // });
  },
  mounted() {
    // this.setTime()
    this.setTime();
    // console.log("dsfdsad", process.env.Head)
    setInterval(() => {
      this.setTime();
    }, 1000);
    const that = this;
    window.addEventListener("setItemEvent", (e) => {
      if (e.key == "systemSetting") {
        let obj = JSON.parse(e.newValue);
        that.skinInfo = obj.skinInfo;
      }
    });
    this.$recvChanel("batteryInfo", (data) => {
      if (data.isShow) {
        this.batteryInfo = data.title;
      } else {
        this.batteryInfo = "";
      }
    });
  },
  methods: {
    openWeather(){
      this.$changeComponentShow(".my_weather", true);
    },
    setTime() {
      let date = new Date();
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      let day = date.getDate();
      let hours = date.getHours();
      if (hours < 10) {
        hours = "0" + hours;
      }
      let minutes = date.getMinutes();
      if (minutes < 10) {
        minutes = "0" + minutes;
      }
      let seconds = date.getSeconds();
      if (seconds < 10) {
        seconds = "0" + seconds;
      }
      this.date.ymd =
        year +
        "/" +
        month +
        "/" +
        day +
        "  " +
        hours +
        ":" +
        minutes +
        ":" +
        seconds;
      this.date.week = date.getDay();
    },
  },
};
</script>

<style scoped lang="scss">
.header_top {
  width: 100%;
  //height: 120px;
  height: 6.25vw;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 19;

  .dateTime {
    position: absolute;
    left: 20px;
    //top: 15px;
    top: 0.35vw;
    height: 36px;
    //border: 1px solid red;
    //width: 200px;
    color: var(--svg-headColor3);
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 18px;

    >span {
      margin: 0 5px;
    }

    &>span:first-child {
      letter-spacing: 1px;
    }
  }

  .headButton {
    position: absolute;
    top: 80px;
    left: 50%;
    transform: translate(-50%, 0);
  }
}
</style>
