<template>
  <div class="nav-header">
    <div class="left-nav">
      <span>{{ date }} {{ weekDay }} {{ time }}</span>
    </div>
    <div class="mid-title">
      <span>{{ userInfo.customer_shortname }}检测数字化生产可视平台</span>
    </div>
    <div class="right-nav"></div>
  </div>
</template>
<script>
import { mapState } from "vuex";
export default {
  data() {
    return {
      date: "",
      weekDay: "",
      time: "",
    };
  },
  methods: {
    getTime() {
      let date = new Date();
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      let day = date.getDate();
      month = month > 9 ? month : "0" + month;
      day = day < 10 ? "0" + day : day;
      let today = year + "-" + month + "-" + day;
      this.date = today;
      let hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
      let min =
        date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
      let sec =
        date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
      this.time = `${hour}:${min}:${sec}`;

      let str = "星期";
      let weekDay = new Date().getDay();
      switch (weekDay) {
        case 0:
          str += "日";
          break;
        case 1:
          str += "一";
          break;
        case 2:
          str += "二";
          break;
        case 3:
          str += "三";
          break;
        case 4:
          str += "四";
          break;
        case 5:
          str += "五";
          break;
        case 6:
          str += "六";
          break;
      }
      this.weekDay = str;
    },
  },
  mounted() {
    setInterval(() => {
      this.getTime();
    }, 1000);
  },
  computed: {
    ...mapState(["userInfo"]),
  },
};
</script>
<style lang="less" scoped>
.nav-header {
  width: calc(100% - 40px);
  display: flex;
  align-content: center;
  padding: 0 20px;
  height: 110px;
  margin: 0px;
  background: url("@/assets/images/User/header.png") no-repeat;
  background-size: 100% 100%;
  .left-nav {
    width: calc(100% / 3);
    display: flex;
    justify-content: flex-start;
    line-height: 50px;
    span {
      color: #fff;
      font-size: 18px;
    }
    .weather-img {
      vertical-align: top;
      width: 30px;
      height: 30px;
      margin: 15px 0;
      margin-right: 30px;
    }
  }
  .mid-title {
    width: calc(100% / 3);
    font-size: 32px;
    color: #fff;
    text-align: center;
    letter-spacing: 3px;
    line-height: 65px;

    span {
      white-space: nowrap;
    }
  }
  .right-nav {
    width: calc(100% / 3);
    text-align: right;
  }
}
</style>