<template>
  <nav class="aui-navbar" :class="`aui-navbar--${$store.state.navbarLayoutType}`">
    <div class="aui-navbar__header" style="height:100px;">
      <!-- logo -->
      <h1 class="aui-navbar__brand" @click="logoClick">
        <a class="aui-navbar__brand-lg" href="javascript:;" style="text-align:center;">
          <svg-icon icon-class="icon-yzk-login" style="font-size:36px" />
          <div style="margin-top:5px;">眼科电子病历系统</div>
        </a>
        <a class="aui-navbar__brand-mini" href="javascript:;"> <svg-icon icon-class="icon-yzk-login" style="font-size:36px" /></a>
      </h1>
    </div>
    <div class="aui-navbar__body">
      <el-menu class="aui-navbar__menu mr-auto" mode="horizontal">
        <!-- 收缩 -->
        <el-menu-item index="1" @click="$store.state.sidebarFold = !$store.state.sidebarFold">
          <svg class="icon-svg aui-navbar__icon-menu aui-navbar__icon-menu--switch" aria-hidden="true"><use xlink:href="#icon-outdent" /></svg>
        </el-menu-item>
        <!-- 刷新 -->
        <el-menu-item index="2" style="padding:0 6px;" @click="refresh()">
          <svg class="icon-svg aui-navbar__icon-menu aui-navbar__icon-menu--refresh" aria-hidden="true"><use xlink:href="#icon-sync" /></svg>
        </el-menu-item>
        <el-menu-item index="2" style="padding:0 6px;">
          <bread-crumb />
        </el-menu-item>
      </el-menu>
      <el-menu class="aui-navbar__menu" mode="horizontal">
        <!-- 全屏 -->
        <el-menu-item index="4" @click="fullscreenHandle()">
          <svg-icon icon-class="fullscreen" />
        </el-menu-item>
        <!-- 数据可视化 -->
        <el-menu-item index="5" @click="dataVisionHandle()">
          <svg-icon icon-class="pointmap" />
        </el-menu-item>
        <!-- 头像、按钮组 -->
        <el-menu-item index="6" class="aui-navbar__avatar">
          <el-dropdown placement="bottom" :show-timeout="0">
            <span class="el-dropdown-link">
              <img src="~@/assets/img/avatar.png">
              <span>{{ $store.state.user.name }}</span>
              <i class="el-icon-arrow-down" />
            </span>
            <el-dropdown-menu slot="dropdown">
              <!-- 修改密码 -->
              <!-- <el-dropdown-item v-if="isShowSwitchingSystem" @click.native="switchingSystemHandle()">切换系统</el-dropdown-item> -->
              <el-dropdown-item @click.native="updatePasswordHandle()">修改密码</el-dropdown-item>
              <!-- 退出 -->
              <el-dropdown-item style="color:#FF4D4F" @click.native="logoutHandle()">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-menu-item>
      </el-menu>
    </div>
    <!-- 弹窗, 修改密码 -->
    <update-password v-if="updatePasswordVisible" ref="updatePassword" />
    <!-- 数据可视化 -->
<!--    <data-vision v-if="dataVisionVisible" ref="dataVisionRef" @dataVisionVisible="dataVisionVisible = false" />-->
  </nav>
</template>
<script>
import { messages } from '@/i18n'
import screenfull from 'screenfull'
import UpdatePassword from './main-navbar-update-password.vue'
import { clearLoginInfo } from '@/page-subspecialty/utils/request.js'
import breadCrumb from '@/components/bread-crumb'
// import dataVision from '@/components/data-vision'
import { resetRouter } from '@/page-subspecialty/router/index.js'
// import Cookies from 'js-cookie'
// var socket = null
export default {
  inject: ['refresh'],
  components: {
    UpdatePassword,
    breadCrumb,
    // dataVision
  },
  data() {
    return {
      i18nMessages: messages,
      updatePasswordVisible: false,
      messageTip: false,
      logo: require('@/assets/img/logo.png'),
      // sysUserDTO: {},
      // isShowSwitchingSystem: false,
      dataVisionVisible: false
    }
  },
  created() {
    // this.sysUserDTO = JSON.parse(window.localStorage.getItem('yzk-sysUserDTO'))
    // this.isShowSwitchingSystem = this.sysUserDTO.drgsNames.length > 1
  },
  methods: {
    logoClick() {
      this.$store.commit('activeIndexFun', window.SITE_CONFIG.menuList[0].id)
      this.$router.push({ name: 'patientManagement' })
    },
    myNoticeRouter() {
      this.$router.replace('')
    },
    // 全屏
    fullscreenHandle() {
      if (!screenfull.enabled) {
        return this.$message({
          message: this.$t('fullscreen.prompt'),
          type: 'warning',
          duration: 500
        })
      }
      screenfull.toggle()
    },
    // 数据可视化
    dataVisionHandle() {
      this.dataVisionVisible = true
      this.$nextTick(() => {
        this.$refs.dataVisionRef.init()
      })
    },
    // 切换系统
    // switchingSystemHandle() {
    //   this.$router.replace({ name: 'identity' })
    // },
    // 修改密码
    updatePasswordHandle() {
      this.updatePasswordVisible = true
      this.$nextTick(() => {
        this.$refs.updatePassword.init()
      })
    },
    // 退出
    logoutHandle() {
      this.$confirm(this.$t('prompt.info', { handle: this.$t('logout') }), this.$t('prompt.title'), {
        confirmButtonText: this.$t('confirm'),
        cancelButtonText: this.$t('cancel'),
        type: 'warning'
      }).then(() => {
        this.$http.post('/logout').then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg)
          }
          clearLoginInfo()
          resetRouter()
          this.$router.push({ name: 'login' })
          // location.reload()
        }).catch(() => {})
      }).catch(() => {})
    }
  }
}
</script>
<style lang='scss' scoped>
.aui-navbar__brand{
  font-size: 17px;
  .sidebar-logo {
      width: 36px;
      height: 36px;
    }
}
</style>
