<template>
  <div class="head-com">
    <div class="head-com-content">
      <div class="hcc-search __hover">
        <img src="@/assets/images/layout/head-com-search.png"/>
      </div>
      <el-divider direction="vertical" style="border-color: #0276e9;"/>
      <div class="hcc-info-center __hover">
        <el-badge :value="newInfoCenterNum" :max="99" class="item" :hidden="newInfoCenterNum === 0">
          <img src="@/assets/images/layout/head-com-info-center.png"/>
        </el-badge>
      </div>
      <div class="hcc-user">
        <img class="avatar" src="@/assets/images/layout/head-com-avatar.png"/>
        <el-dropdown @command="onCommand">
          <div class="hcc-user-info __hover">
            <div class="label">
              <span class="name">{{$store.state.app.userInfo.nickName}}</span>
              <span class="dept">{{$store.state.app.userInfo.deptName}}</span>
            </div>
            <img src="@/assets/images/layout/head-com-dropdown.png"/>
          </div>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item command="info">个人信息</el-dropdown-item>
              <el-dropdown-item command="password">修改密码</el-dropdown-item>
              <el-dropdown-item command="logout">退出</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>
    <InfoCom v-model:show="showInfo"/>
    <PasswordCom v-model:show="showPassword"/>
  </div>
</template>

<script lang="ts">
import {
  defineComponent,
  computed,
  onMounted,
  ref,
  reactive,
  watch,
  getCurrentInstance,
  ComponentInternalInstance,
  toRefs,
  nextTick
} from 'vue'
import {useStore} from 'vuex'
import {useRouter, useRoute} from 'vue-router'
import InfoCom from '@/views/global/head/info.vue'
import PasswordCom from '@/views/global/head/password.vue'
import {ElMessageBox} from "element-plus";
import {toLogin} from "@/utils/permissions";

export default defineComponent({
  name: '',
  components: {
    InfoCom,
    PasswordCom
  },
  setup() {
    const store = useStore();
    const router = useRouter();
    const route = useRoute();
    const that = (getCurrentInstance() as ComponentInternalInstance).appContext.config.globalProperties
    const state = reactive({
      newInfoCenterNum: 88,
      showInfo: false,
      showPassword: false,
    })
    const onCommand = (c) => {
      if (c === 'info') {
        state.showInfo = true
      } else if (c === 'password') {
        state.showPassword = true
      } else if (c === 'logout') {
        ElMessageBox.confirm("请确认是否退出登录?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          that.$api.logout()
          toLogin()
        }).catch(() => {})
      }
    }
    return {
      ...toRefs(state),
      onCommand
    }
  },
})
</script>

<style scoped lang="scss">
  .head-com {
    background-image: url("@/assets/images/layout/head-com-bg.png");
    background-position-x: left;
    background-position-y: bottom;
    background-repeat: no-repeat;
    width: 331px;
    height: 48px;
    display: flex;
    align-items: flex-end;
    position: absolute;
    top: 0;
    right: 0;
    .head-com-content {
      width: 100%;
      height: 40px;
      display: flex;
      align-items: center;
      .el-divider {
        margin: 0;
      }
      .hcc-search {
        width: 20px;
        height: 20px;
        margin-left: 30px;
        margin-right: 18px;
        >img {
          width: 100%;
          height: 100%;
        }
      }
      .hcc-info-center {
        margin-left: 14px;
        width: 18px;
        height: 20px;
        :deep(.el-badge__content) {
          height: 16px;
          top: 7px;
          right: 8px;
          border: none;
        }
      }
      .hcc-user {
        display: flex;
        align-items: center;
        margin-left: auto;
        margin-right: 7px;
        .avatar {
          width: 25px;
          height: 25px;
          margin-right: 30px;
        }
        .hcc-user-info {
          display: flex;
          align-items: center;
          .label {
            display: flex;
            flex-direction: column;
            font-family: Microsoft YaHei;
            font-weight: 400;
            color: #FFFFFF;
            text-shadow: 0px 1px 2px rgba(41,111,208,0.2);
            margin-right: 13px;
            .name {
              font-size: 14px;
            }
            .dept {
              font-size: 12px;
            }
          }
        }
      }
    }
  }
</style>
