<template>
  <div class="nav">
    <div class="container">
      <div class="logo-container  wow animate__animated animate__fadeInLeft">
        <img src="@/assets/imgs/home/logo.png" />
      </div>
      <div class="right ">
        <div class="tabs wow animate__animated animate__fadeInUp">
          <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 wow animate__animated animate__fadeInRight">
          <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>
.tab-item {
  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;
    overflow: hidden;
    .logo-container {
      width: 380px;
      height: 74px;
      // transform: translateX(-1000px);
      // animation: fadeUp 0.5s ease;
    }
    .right {
      display: flex;
      height: 100%;
      align-items: center;

      .tabs {
        display: flex;
        margin-right: 100px;
        min-width: 512px;
        // transform: translateY(200px);
        // animation: fadeUp ease 1s forwards;
        .tab-item {
          margin-right: 70px;
          color: #fff;
          display: flex;
          align-items: center;
          font-family: "Alibaba-PuHuiTi";
          position: relative;
          .svg-icon {
            position: absolute;
            bottom: -16px;
            left: 24%;
            transform: scale(1.5);
          }
        }
      }
    }
  }
}
@keyframes fadeUp {
  from {
    transform: translateY(200);
  }
  to {
    transform: translateY(0);
  }
}

@keyframes fadeLeft {
  from {
    transform: translateX(-1000);
  }
  to {
    transform: translateX(0);
  }
}
::v-deep .tools {
  .el-button {
    background: transparent;
    border-color: #fff;
    color: #fff;
    i {
      font-size: 16px;
    }
  }
}

.el-dropdown-menu {
  background-color: #fff;
  // border: 1px solid #8a919f;
}
.el-dropdown-menu__item {
  background-color: transparent;
  // color: #fff;
  color: #8a919f;
  a {
    text-decoration: none;
    color: #8a919f;
  }
}

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