<template>
  <div class="headBox">
    <div class="top">
      <div class="top-left">
        <div class="qwbg"></div>
        <div class="time">
          <div class="timer">{{ hour + ":" + minute + ":" + second }}</div>
          <div class="week">{{ weekenday }} {{ datatime }}</div>
        </div>
      </div>
      <div class="top-right">
        <div class="info">
          <img class="photo" src="@/assets/my/photo.png" />
          <div class="text">
            <div>姓名：{{ username }}</div>
            <div class="dept" :tabindex="deptName">
              单位：<el-tooltip :content="deptName">{{ deptName }}</el-tooltip>
            </div>
          </div>
          <el-dropdown :hide-on-click="false">
            <span class="el-dropdown-link">
              <el-icon :size="20" color="#fff">
                <CaretBottom />
              </el-icon>
            </span>
            <template #dropdown>
              <el-dropdown-menu class="loginOut" @click="logout">
                <el-dropdown-item command="logout">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
        <div class="meun" @click="modularShowFn" title="后台">
          <img src="@/assets/my/meun.png" />
        </div>
        <el-popover trigger="click" placement="bottom" v-model:visible="showVisible" :append-to-body="false">
          <template #reference>
            <span class="el-dropdown-tools" @click="showVisible = !showVisible">
              <span class="el-dropdown-tools-n">
                <el-icon :size="26" color="#28426a">
                  <Tools />
                </el-icon>
              </span>
            </span>
          </template>
          <div @click="handleRhtx" class="settingItem"><el-icon>
              <Notification />
            </el-icon>融合通信 </div>
          <div @click="handleJxkh" class="settingItem"><el-icon>
              <Notification />
            </el-icon>绩效考核</div>
        </el-popover>
      </div>
    </div>
    <Performance v-model="modelValue" />
  </div>
</template>

<script setup>
import { getRecentDay } from "@/utils/tools.js";
import { useRouter, useRoute, onBeforeRouteLeave } from "vue-router";
import { useStore } from "vuex";
import { ref, onMounted, defineEmits, onUnmounted } from "vue";
import Performance from './performance.vue'
const modelValue = ref(false)
const showVisible = ref(false)
const store = useStore();
const router = useRouter();
const route = useRoute();
const username = ref("");
const weekenday = ref('') //星期几
const datatime = ref(getRecentDay(0));
const minute = ref("00"); //分
const second = ref("00"); //秒
const hour = ref("00"); //时
const day = ref(0);
const deptName = ref(JSON.parse(localStorage.getItem("deptId"))[0].deptName);
const modularShow = ref(false);
const timersfm = ref(null);
onMounted(() => {
  getWeek()
  username.value = localStorage.getItem("USERNAME");
  timersfm.value = setInterval(() => {
    CurrentTime();
  }, 1000);
});

// 打开融合通信页面
function handleRhtx(params) {
  const DDZHhref = router.resolve({
    name: "rhtx", //这里是跳转页面的name
    path: "/rhtx"
  });
  window.open(DDZHhref.href, "_blank");
}

// 打开绩效考核
function handleJxkh() {
  modelValue.value = true;
  showVisible.value = false
}

function getWeek() {
  let week = new Date().getDay()
  switch (week) {
    case 0:
      return weekenday.value = '星期日'
      break;
    case 1:
      return weekenday.value = '星期一'
      break;
    case 2:
      return weekenday.value = '星期二'
      break;
    case 3:
      return weekenday.value = '星期三'
      break;
    case 4:
      return weekenday.value = '星期四'
      break;
    case 5:
      return weekenday.value = '星期五'
      break;
    case 6:
      return weekenday.value = '星期六'
      break;

  }
}


// 获取时分秒
function CurrentTime() {
  const date = new Date();
  hour.value = date.getHours();
  minute.value = date.getMinutes();
  second.value = date.getSeconds();
  day.value = day.value < 10 ? "0" + day.value : day.value;
  hour.value = hour.value < 10 ? "0" + hour.value : hour.value;
  minute.value = minute.value < 10 ? "0" + minute.value : minute.value;
  second.value = second.value < 10 ? "0" + second.value : second.value;
}
// 打开菜单弹窗
function modularShowFn(val) {
  router.replace('/editPassword');
}

// 退出
const logout = () => {
  store.dispatch("user/logout");
  store.commit("app/clearTag", null, { immediate: true });
  store.commit("permission/deleteRouter", { immediate: true });
  store.commit("user/deleteKeepLiiveRoute", "lz/home");
};

onUnmounted(() => {
  clearInterval(timersfm.value)
});
</script>

<style lang="scss" scoped>
@import "@/assets/css/homeScreen.scss";

::v-deep .el-dialog {
  --el-dialog-bg-color: #10295b;
}

::v-deep .el-dialog__title {
  color: #fff;
}

.settingItem {
  color: #fff;
  display: flex;
  align-items: center;
  height: 30px;
  border-bottom: 1px solid #143d91;
  padding-left: 10px;
  box-sizing: border-box;
  cursor: pointer;

  .el-icon {
    margin-right: 10px;
  }
}

.settingItem:hover {
  background: #143d91;
}
</style>
