<template>
  <div class="home" >
      <div class="top">
        <div @click="logout()" style="float: left;">
        <img src="../assets/bargound/logout1.png" style="height: 20px; width: 20px; margin-left: 20px;" alt="" ><span style="color: rgb(174, 201, 222);">退出</span>
        </div>
        <div class="time"><span class="iconfont icon-riqi"></span>&nbsp;&nbsp;{{ currentTime }}</div>
      </div>
    <div class="content">
      <div class="left">
        <div class="klfx modulbox leftbox1">
          <KLFX />
        </div>
        <div class="xsfx modulbox leftbox2">
          <XSFX />
        </div>
        <div class="fqyw modulbox leftbox3">
          <FQYW />
        </div>
      </div>
      <div class="middle">
        <div class="cztj modulbox middlebox1">
          <CZTJ />
        </div>
        <div class="kyfx modulbox middlebox2">
          <KYFX />
        </div>
        <div class="jcpm modulbox middlebox3">
          <JCPM />
        </div>
      </div>
      <div class="right">
        <div class="bxcb modulbox rightbox1">
          <BXCBHB />
        </div>
        <div class="kcfx modulbox rightbox2">
          <KCFX />
        </div>
        <div class="bkfx modulbox rightbox3">
          <BKFX />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import KLFX from "../components/HomeChart/KLFX.vue";
import XSFX from "../components/HomeChart/XSFX.vue";
import FQYW from "../components/HomeChart/FQYW.vue";
import CZTJ from "../components/HomeChart/CZTJ.vue";
import KYFX from "../components/HomeChart/KYFX.vue";
import JCPM from "../components/HomeChart/JCPM.vue";
import BXCBHB from "../components/HomeChart/BXCBHB.vue";
import KCFX from "../components/HomeChart/KCFX.vue";
import BKFX from "../components/HomeChart/BKFX.vue"
import {  kcfxcompanInfo, userlogoutInfo } from "../servuces/prove";
import { settoken } from "../servuces/token";
import { mapMutations } from "vuex";
export default {
  name: 'HomeView',
  data () {
    return {
      currentTime: '',//当前时间
    }
  },
  mounted () {
    this.updateTime(); //时间
    this.kcfxcompanapi()//时间
  },
  beforeDestroy () {
    // 在组件销毁前清除定时器，避免内存泄漏
    clearInterval(this.timer);
  },
  methods: {
    ...mapMutations(['setData']),
    kcfxcompanapi () {
      kcfxcompanInfo().then(res => {
        const storefront = res.data;
        sessionStorage.setItem('company_data', JSON.stringify(storefront))
      })
    },
    //更新时间
    updateTime() {
      // 在组件挂载结束时启动定时器，每秒更新一次时间
      this.currentTime = this.getCurrentTime();
      //每秒更新一次
      this.timer = setInterval(() => {
        this.currentTime = this.getCurrentTime();
      }, 1000);
    },
    getCurrentTime() {
      const now = new Date();
      const year = now.getFullYear();
      const month = String(now.getMonth() + 1).padStart(2, "0");
      const day = String(now.getDate()).padStart(2, "0");
      const hours = String(now.getHours()).padStart(2, "0");
      const minutes = String(now.getMinutes()).padStart(2, "0");
      const seconds = String(now.getSeconds()).padStart(2, "0");
      return `${year}.${month}.${day} ${hours}:${minutes}:${seconds}`;
    },
    logout(){
      userlogoutInfo().then(res => {

        if (res.success) {
          this.$router.replace('/login');
          settoken('');
        } else {
          this.$vux.toast.show({
            type: 'cancel',
            text: res.errors
          })
        }
      })
    },
  },
  components: {
    KLFX, XSFX, FQYW, CZTJ, KYFX, JCPM, BXCBHB, KCFX, BKFX
  }
}
</script>
<style scoped lang="scss">
.home {
  width: 100%;
  height: 100vh;
  color: white;
  padding: 1% 0 0 0;

  .top {
    height: 7%;
    justify-content: flex-end;
    background-image: url(../assets/bargound/title.png);
    background-repeat: no-repeat;
    background-size: 100% 100%;
    box-sizing: border-box;

    .time {
      float: right;
      color: rgb(174, 201, 222);
      margin-right: 2%;
      font-size: 16px;
      overflow: hidden;
      max-width: 15%;
      white-space: nowrap;
    }
  }

  .content {
    width: 100%;
    height: 91%;
    display: flex;
    justify-content: space-evenly;

    .left {
      height: 100%;
      width: 32%;
      display: flex;
      flex-direction: column;
      justify-content: space-between;

      .leftbox1 {
        width: 100%;
        height: 32%;

      }

      .leftbox2 {
        width: 100%;
        height: 32%;
        min-height: 250px;
      }

      .leftbox3 {
        width: 100%;
        height: 32%;
        min-height: 150px;
      }
    }

    .middle {
      height: 100%;
      width: 32%;
      display: flex;
      flex-direction: column;
      justify-content: space-between;


      .middlebox1 {
        height: 48%;
        min-height: 320px;
      }

      .middlebox2 {
        height: 26%;
        min-height: 130px;
      }

      .middlebox3 {
        height: 22%;
        min-height: 150px;
      }
    }

    .right {
      height: 90vh;
      width: 32%;
      display: flex;
      flex-direction: column;
      justify-content: space-between;

      .rightbox1 {
        height: 25%;
        min-height: 170px;
      }

      .rightbox2 {
        height: 29%;
        min-height: 150px;
      }

      .rightbox3 {
        height: 42%;
        min-height: 280px;
      }
    }
  }
}
</style>
