<template>
  <div class="nav">
    <div class="container">
      <div class="logo-container">
        <img src="@/assets/imgs/home/logo.png" />
      </div>
      <div class="right">
        <div class="tabs">
          <div
            class="tab-item"
            v-for="(item, index) in pages"
            :key="index"
            @click="handleClickTab(item)"
          >
            <router-link :to="item.path">{{ item.name }} </router-link>
            <svg-icon
              icon-class="subscript"
              v-show="currentTab.name == item.name"
            ></svg-icon>
          </div>
        </div>
        <div class="tools">
          <div class="wrapper">
            <el-dropdown trigger="click">
              <el-button round>
                <i class="el-icon-user"></i>
                <i class="el-icon-arrow-down el-icon--right"></i>
              </el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item
                  ><span
                    v-if="!hasToken"
                    @click="handleToLogin"
                    class="operation-item"
                    >登陆</span
                  ></el-dropdown-item
                >
                <el-dropdown-item
                  ><router-link
                    v-if="hasToken"
                    to="/personal"
                    class="operation-item"
                    >个人中心</router-link
                  ></el-dropdown-item
                >
                <el-dropdown-item>
                  <span v-if="hasToken" @click="handleLogOut">退出</span>
                  <!-- <span class="logout" v-if="hasToken">
                    <el-popover
                      placement="bottom"
                      width="200"
                      trigger="click"
                      v-model="logoutDialogVisible"
                    >
                     
                      <p>确定退出吗？</p>
                      <div style="text-align: right; margin: 0">
                        <el-button
                          size="mini"
                          type="text"
                          @click="logoutDialogVisible = false"
                          >取消</el-button
                        >
                        <el-button
                          type="primary"
                          size="mini"
                         
                          >确定</el-button
                        >
                      </div>
                    </el-popover> -->
                  <!-- </span> -->
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
          <!-- 
          
           -->
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  name: "NavBar",
  computed: {
    ...mapGetters(["token", "userInfo"]),
    hasToken() {
      return this.token;
    },
  },
  data() {
    return {
      pages: [
        {
          name: "首页",
          path: "/",
        },
        {
          name: "精品展",
          path: "/boutique",
        },
        {
          name: "虚拟展厅",
          path: "/virtual",
        },
        {
          name: "布展",
          path: "/display",
        },
        {
          name: "文物展",
          path: "/culturalRelic",
        },
        {
          name: "博物馆",
          path: "/museum",
        },
      ],
      userName: "",
      logoutDialogVisible: false,
      currentTab: {
        name: "首页",
        path: "/",
      },
    };
  },
  methods: {
    handleToLogin() {
      this.$router.push("/login?redirect=" + this.$route.fullPath);
    },
    async handleLogOut() {
      await this.$store.dispatch("user/logout");
      this.logoutDialogVisible = false;
      // 如果当前的path为/personal，需跳转到首页
      let path = this.$route.fullPath;
      if (path.indexOf("/personal") != -1) {
        this.$router.push("/");
      }
      // this.$router.push(`/login?redirect=${this.$route.fullPath}`);
    },
    handleClickTab(tab) {
      this.currentTab = tab;
    },
  },
};
</script>

<style lang="scss" scoped>
a {
  color: #fff;
  text-decoration: none;
}
.nav {
  height: 100px;
  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 9;
  .container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 70px 0 100px;
    .title {
    }
    .right {
      display: flex;
      height: 100%;
      align-items: center;
      .tabs {
        display: flex;
        margin-right: 100px;
        min-width: 512px;
        // height: 100%;

        .tab-item {
          margin-right: 90px;
          color: #fff;
          // height: 100%;
          display: flex;
          align-items: center;
          font-family: "Alibaba-PuHuiTi";
          position: relative;
          .svg-icon {
            position: absolute;
            bottom: -16px;
            left: 24%;
            transform: scale(1.5);
          }
        }
      }
    }
  }
}

::v-deep .tools {
  .el-button {
    background: transparent;
    border-color: #fff;
    color: #fff;
    i {
      font-size: 16px;
    }
  }
}

.el-dropdown-menu {
  background-color: transparent;
}
.el-dropdown-menu__item {
  background-color: transparent;
  color: #fff;
}

.el-dropdown-menu__item:focus,
.el-dropdown-menu__item:not(.is-disabled):hover {
  background-color: rgba(255, 255, 255, 0.2);
  color: #fff;
}
</style>