<template>
  <div class="navbar">
    <!-- <hamburger :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" /> -->
    <!-- <breadcrumb class="breadcrumb-container" /> -->
    <div class="navbar_top">
      <div class="nav_left">
        <div class="log_name">{{ pageTitle }}</div>
      </div>
      <div class="right-menu">
        <el-dropdown>
          <div class="user">
            <img class="head-icon-img" src="../../assets/status/ic_user.png" alt="" />
            <span class="name">{{ name }}</span>
            <i class="el-icon-arrow-down el-icon--right"></i>
          </div>
          <el-dropdown-menu class="handleMsgMneu" slot="dropdown">
            <el-dropdown-item v-if="name != '匿名用户'">
              <span class="editPwd" @click="dialogPwd">修改密码</span>
            </el-dropdown-item>
            <el-dropdown-item>
              <span @click="exitDialog" class="layoutSys">退出登录</span>
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
        <!-- <el-button class="btn-help" plain @click="downFile">帮助</el-button> -->
        <!-- <div class="seting">
          <span @click="toSystem" class="img-icon"></span>
        </div> -->
        <!-- <div class="lock">
          <span @click="dialogPwd" class="img-icon"></span>
        </div>
        <div class="exit">
          <span @click="exitDialog" class="img-icon"></span>
        </div> -->
      </div>
    </div>
    <div class="navbar_lower" id="navbar_lowers">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item v-for="(item, index) in breadList" :key="index" :to="index < breadList.length -1 ? item.path : undefined">
          <span>{{ item.meta.title }}</span>
        </el-breadcrumb-item>
      </el-breadcrumb>
      <!-- <tags-view /> -->
      <div class="newdata">{{ newData }}</div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import Breadcrumb from '@/components/Breadcrumb'
import Hamburger from '@/components/Hamburger'
// import { Format } from "../../config/util";
import { timeInZone } from '@/utils/table'
import { userHealth } from "@/api/login";
// import TagsView from "./TagsView";

export default {
  props: ['logstart'],
  data () {
    return {
      newData: '',
      breadList: this.getBreadcrumb(),
      getTimeInterval: null,
      usertHeart: null,
      imgSrc: window.location.origin + sessionStorage.getItem('appLog'),
      pageTitle: sessionStorage.getItem('appName') ?? '行李全流程跟踪系统',
      name: sessionStorage.getItem('userName')
    }
  },
  components: {
    Breadcrumb,
    Hamburger
    // TagsView,
  },
  watch: {
    $route (val) {
      this.breadList = this.getBreadcrumb()
    }
  },
  computed: {
    ...mapGetters(['sidebar', 'avatar', 'timeZone'])
  },
  mounted () {
    this.getTimeInterval = setInterval(() => {
      // this.newData = Format("yyyy/MM/dd hh:mm:ss", new Date());
      this.newData = timeInZone(new Date(), this.timeZone).replaceAll('-', '/')
    })
    // this.usertHeart = setInterval(() => {
    //   this.setUserHeart()
    // }, 1000 * 10);
  },
  beforeDestroy () {
    this.getTimeInterval && clearInterval(this.getTimeInterval)
    this.getTimeInterval = null
    this.usertHeart && clearInterval(this.usertHeart)
    this.usertHeart = null
  },
  methods: {
    errorHandler () {
      return true
    },
    //心跳连接
    async setUserHeart () {
      const { code, message } = await userHealth();
      if (code != 0) {
        this.$message.error(message);
      }
    },
    toggleSideBar () {
      this.$store.dispatch('app/toggleSideBar')
    },
    async logout () {
      await this.$store.dispatch('user/logout')
      this.$router.push(`/login?redirect=${this.$route.fullPath}`)
    },
    getBreadcrumb () {
      return this.$route.matched.filter(item => item.name && item.meta.title)
    },
    //修改密码
    dialogPwd () {
      this.$store.dispatch('app/togglePwdflag', true)
    },
    //退出系统-弹框
    exitDialog () {
      this.$store.dispatch('app/toggleOutflag', true)
    },
    //下载
    downFile () {
      const a = document.createElement('a')
      // 给a标签的href属性值加上地址,注意:这里是绝对路径,不用加 点.
      a.href = './行李全流程跟踪数据系统-用户使用手册V2.1.pdf'
      // 设置下载文件文件名,这里加上.xlsx指定文件类型,pdf文件就指定.fpd即可
      a.download = '行李全流程跟踪数据系统-用户使用手册V2.1.pdf'
      // 障眼法藏起来a标签
      a.style.display = 'none'
      // 将a标签追加到文档对象中
      document.body.appendChild(a)
      // 模拟点击了<a>标签,会触发<a>标签的href的读取,浏览器就会自动下载了
      a.click()
      // 一次性的,用完就删除a标签
      a.remove()
      // window.location.href = './行李全流程跟踪数据系统-用户使用手册V2.1.pdf'
    },
    goBackHandler (item) {
      return item.parent?.path
    }
  }
}
</script>

<style lang="scss" scoped>
.navbar {
  width: 100%;
  height: 80px;
  overflow: hidden;
  position: relative;
  background: #fff;
  position: fixed;
  top: 0;
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
  z-index: 999;
  ::v-deep .el-breadcrumb__separator {
    display: none;
  }
  ::v-deep .el-breadcrumb__inner {
    padding: 8px 31px 9px 31px;
    color: #afb4bf;
  }
  ::v-deep .el-breadcrumb__item:last-child {
    .el-breadcrumb__inner {
      padding: 8px 31px 9px 31px;
      background: #dfe3ea;
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #101116;
    }
  }
  > .navbar_top {
    width: 100%;
    height: 48px;
    background: #2d67e3;
    display: flex;
    align-items: center;
    justify-content: space-between;
    // border-bottom: 1px solid #f2f6fc;
    padding-left: 14px;
    > .nav_left {
      height: 100%;
      display: flex;
      align-items: center;

      > .dividing {
        width: 1px;
        height: 16px;
        margin-left: 8px;
        margin-right: 12px;
        background: #ffffff;
      }
      > .log_name {
        font-size: 14px;
        font-family: Microsoft YaHei;
        font-weight: bold;
        color: #ffffff;
      }
    }
    .hamburger-container {
      line-height: 46px;
      height: 100%;
      float: left;
      cursor: pointer;
      transition: background 0.3s;
      -webkit-tap-highlight-color: transparent;
      &:hover {
        background: rgba(0, 0, 0, 0.025);
      }
    }

    .breadcrumb-container {
      float: left;
    }

    .right-menu {
      float: right;
      height: 100%;
      line-height: 48px;
      margin-right: 44px;
      display: flex;
      &:focus {
        outline: none;
      }
      > div {
        margin-right: 20px;
      }
      .img-icon {
        display: inline-block;
        width: 24px;
        height: 24px;
        vertical-align: middle;
        background-repeat: no-repeat;
        background-size: cover;
        cursor: pointer;
        transition: all 0.3s;
      }
      .lock {
        .img-icon {
          background-image: url("../../assets/status/ic_password.png");
          &:hover {
            background-image: url("../../assets/status/ic_password_hovar.png");
          }
        }
      }
      .exit {
        .img-icon {
          background-image: url("../../assets/status/ic_exit.png");
          &:hover {
            background-image: url("../../assets/status/ic_exit_hovar.png");
          }
        }
      }
      .btn-help {
        height: 20px;
        line-height: 20px;
        padding: 0;
        width: 38px;
        margin-top: 14px;
        border: 1px solid #fff;
        background: none;
        color: #fff;
        transition: all 0.3s;
        &:hover {
          background: #fff;
          color: #2d67e3;
        }
      }
      .user {
        img {
          position: relative;
          top: 6px;
          margin-right: 10px;
        }
        color: #fff;
        font-weight: 600;
        font-size: 16px;
        cursor: pointer;
      }
      > .right {
        width: 100%;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        padding-right: 80px;
        > .log {
          width: 40px;
          height: 40px;
          background: #e1e5eb;
          border-radius: 50%;
          margin-right: 16px;
        }
        > p {
          font-size: 16px;
          font-family: Microsoft YaHei;
          font-weight: 300;
          color: #303133;
        }
      }
      .right-menu-item {
        display: inline-block;
        padding: 0 8px;
        height: 100%;
        font-size: 18px;
        color: #5a5e66;
        vertical-align: text-bottom;

        &.hover-effect {
          cursor: pointer;
          transition: background 0.3s;
          &:hover {
            background: rgba(0, 0, 0, 0.025);
          }
        }
      }

      .avatar-container {
        margin-right: 30px;
        height: 100%;
        .avatar-wrapper {
          height: 100%;
          // margin-top: 5px;
          display: flex;
          align-items: center;
          position: relative;
          .search {
            width: 21px;
            height: 21px;
            background: url("../../assets/header/ic_search_top.png") no-repeat;
            background-size: 100% 100%;
            margin-top: 10px;
            margin-right: 41px;
          }
          .fullscreen {
            width: 21px;
            height: 21px;
            background: url("../../assets/header/ic_fullscreen_top.png")
              no-repeat;
            background-size: 100% 100%;
            margin-top: 10px;
            margin-right: 20px;
          }
          .journaler {
            width: 21px;
            height: 21px;
            background: url("../../assets/header/ic_data_top.png") no-repeat;
            background-size: 100% 100%;
            margin-top: 10px;
            margin-right: 41px;
          }
          .information {
            width: 21px;
            height: 21px;
            background: url("../../assets/header/ic_message_top.png") no-repeat;
            background-size: 100% 100%;
            margin-top: 10px;
            margin-right: 41px;
            position: relative;
            > .information_number {
              position: absolute;
              width: 15px;
              height: 15px;
              background: #ed5050;
              color: #ffffff;
              border-radius: 50%;
              top: -35%;
              right: -30%;
              display: flex;
              align-items: center;
              justify-content: center;
              font-size: 12px;
              font-family: Microsoft YaHei;
              font-weight: 400;
            }
          }
          .user-avatar {
            cursor: pointer;
            width: 24px;
            height: 24px;
            border-radius: 50%;
            margin-right: 16px;
          }
          .username {
            // width: 200px;
            height: 40px;
            // margin-left: 5%;
            color: #ffffff;
            font-size: 16px;
            font-family: Microsoft YaHei;
            font-weight: bold;
            line-height: 40px;
            display: inline;
          }
          .el-icon-caret-bottom {
            cursor: pointer;
            position: absolute;
            right: -20px;
            top: 20px;
            font-size: 12px;
          }
        }
      }
    }
  }
  > .navbar_lower {
    width: 100%;
    height: 32px;
    display: flex;
    background: #ffffff;
    justify-content: space-between;
    align-items: center;
    padding-left: 130px;
    padding-right: 24px;
    ::v-deep .el-breadcrumb {
      font-size: 18px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      // color: #ffffff;
      .is-link {
        font-size: 14px !important;
        // color: #ffffff !important;
      }
      .el-breadcrumb__item {
        .el-breadcrumb__inner {
          font-size: 14px;
        }
      }
      // .is-link {
      //   font-size: 14px;
      //   color: #ffffff !important;
      // }
      .btn-back {
        margin-left: -18px;
        margin-right: 10px;
        font-size: 14px;
        color: #2d67e3;
        cursor: pointer;
      }
    }
    > .newdata {
      font-size: 14px;
      font-family: DIN;
      font-weight: bold;
      min-width: 200px;
      text-align: right;
      // color: #ffffff;
    }
  }
}
</style>
