<template>
  <div class="layout-top_header">
    <!-- 折叠按钮 -->
    <!-- <div class="collapse-btn" @click="collapseChage">
      <i v-if="!collapse" class="iconfont">&#xe607;</i>
      <i v-else class="iconfont">&#xe606;</i>
    </div> -->
    <div class="layout-top_logo">
      <!-- <img :src="`${staticDomain}${logo}`" alt="" class="logo-img -->
      <!-- <span class="layout-top_t">智慧校园管理平台</span> -->
    </div>
    <div class="layout-top_nav">
      <ul class="nav-list" v-if="navData.length">
        <li :class="['nav-item',item.item_id === initNavId ? 'active' : '']" v-for="(item,index) in navData" :key="item.item_id" @click="handleNavTabClick(index)">
          <a href="javascript:;" class="nav-item_box">
            <i :class="['menu-icon',item.mvc_icon_css]"></i>
            <p class="text">{{ item.item_name }}</p>
          </a>
        </li>
      </ul>
    </div>
    <div class="layout-top_right">
      <div class="user-icon">
        <!-- 全屏显示 -->
        <div class="btn-full-screen" @click="handleFullScreenClick">
          <el-tooltip
            effect="dark"
            :content="fullscreen ? `取消全屏` : `全屏`"
            placement="bottom">
           <i class="el-icon-rank"></i>
          </el-tooltip>
        </div>
        <!-- <div class="btn-bell">
          <el-tooltip
            effect="dark"
            content="有5条未读消息`"
            placement="bottom">
            <i class="el-icon-bell"></i>
          </el-tooltip>
          <span class="btn-bell-badge"></span>
        </div> -->
      </div>
      <div class="user-avator"><img class="img" :src="require(`@/${headerImg}`)" /></div>
      <el-dropdown class="user-name" trigger="click" @command="handleCommandClick" >
        <span class="el-dropdown-link">
          {{ $store.state.userinfo.RealName }}
          <i class="el-icon-caret-bottom"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="loginout">退出登录</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>
<script>
import bus from '@/assets/bus'
import ossConfig from '@/assets/ossConfig'
export default {
    name: 'LayoutHeader',
    props: {
        initNavId: {
            type: String,
            default: ''
        },
        navData: {
            type: Array,
            default: () => {
                return []
            }
        }
    },
    data () {
        return {
            staticDomain: ossConfig.staticResourcesFileBucket.domain, // 静态图片域名
            logo: '/Assets/images/login/logo_white.png',
            cruentIndex: 1,
            collapse: false,
            fullscreen: false,
            headerImg: 'assets/images/avatar_a.png'
        }
    },

    methods: {
    // 用户名下拉菜单选择事件
        handleCommandClick (command) {
            if (command === 'loginout') {
                this.$store.commit('saveToken', '')
                this.$store.commit('saveExpireTime', 0)
                this.$router.replace('/login')
            }
        },
        // 侧边栏折叠
        collapseChage () {
            this.collapse = !this.collapse
            bus.$emit('collapse', this.collapse)
        },
        // 全屏事件
        handleFullScreenClick () {
            let element = document.documentElement
            if (this.fullscreen) {
                if (document.exitFullscreen) {
                    document.exitFullscreen()
                } else if (document.webkitCancelFullScreen) {
                    document.webkitCancelFullScreen()
                } else if (document.mozCancelFullScreen) {
                    document.mozCancelFullScreen()
                } else if (document.msExitFullscreen) {
                    document.msExitFullscreen()
                }
            } else {
                if (element.requestFullscreen) {
                    element.requestFullscreen()
                } else if (element.webkitRequestFullScreen) {
                    element.webkitRequestFullScreen()
                } else if (element.mozRequestFullScreen) {
                    element.mozRequestFullScreen()
                } else if (element.msRequestFullscreen) {
                    // IE11
                    element.msRequestFullscreen()
                }
            }
            this.fullscreen = !this.fullscreen
        },
        checkFull () {
            let isFull = document.fullscreenEnabled || window.fullScreen || document.webkitIsFullScreen || document.msFullscreenEnabled
            if (isFull === undefined) isFull = false
            return isFull
        },
        handleNavTabClick (index) {
            this.cruentIndex = index
            this.$emit('change', index)
        }
    },
    mounted () {
    // if (document.body.clientWidth < 1500) {
    //   this.collapseChage()
    // }
        this.$nextTick(() => {
            window.onresize = () => {
                if (!this.checkFull()) {
                    this.fullscreen = false
                }
            }
        })
    }
}
</script>
<style lang="less" scoped>
.layout-top_header {
  display: flex;
  align-items: center;
  height: 64px;
  white-space: nowrap;
  color: #fff;
  background-color: #458fd2;
  .layout-top_logo {
    padding: 0  30px;
    width: 250px;
    .logo-img {
      height: 50px;
      width: auto;
    }
    .layout-top_t {
      font-size: 20px;
    }
  }
  .layout-top_nav {
    flex: 1;
    height: 100%;
    .nav-list {
      display: flex;
      align-items: center;
      height: 100%;
      .nav-item:first-child {
        border-left: 1px solid #78B5F5;
      }
      .nav-item {
        height: 100%;
        text-align: center;
        border-right: 1px solid #78B5F5;
        .nav-item_box {
          display: block;
          padding: 0 20px;
          color: #fff;
          padding-top: 5px;
          .menu-icon {
            font-size: 24px
          }
          .text {
            font-size: 14px;
            margin-top: -3px;
          }
        }
      }
      .nav-item.active {
        background: #2269B4;
        border-bottom: 3px solid #FE9500;
      }
    }
    .icon-news:before  {
      content: "\e60b"
    }
  }
  .layout-top_right {
    display: flex;
    align-items: center;
    padding: 0 20px 0 0;
    .user-icon {
      display: flex;
      align-items: center;
       .btn-bell,.btn-full-screen {
        position: relative;
        width: 30px;
        height: 30px;
        font-size: 22px;
        text-align: center;
        border-radius: 15px;
        cursor: pointer;
      }
      .btn-full-screen {
        transform: rotate(45deg);
        margin-right: 5px;
      }
      .btn-bell {
        .btn-bell-badge {
          position: absolute;
          right: 0;
          top: -2px;
          width: 8px;
          height: 8px;
          border-radius: 4px;
          background: #f56c6c;
          color: #fff;
        }
        .el-icon-bell {
          color: #fff;
        }
      }
    }
    .user-avator {
      margin-left: 15px;
      .img {
        display: block;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        border: 1px solid #ddd;
      }
    }
    .user-name {
      margin-left: 10px;
      .el-dropdown-link {
        color: #fff;
        cursor: pointer;
      }
      .el-dropdown-menu__item {
        text-align: center;
      }
    }
  }
  // .collapse-btn {
  //   float: left;
  //   padding: 0 21px;
  //   cursor: pointer;
  //   line-height: 70px;
  // }

}
</style>
