<template>
  <div class="nav">
    <div class="container">
      <div class="title">贵州省精品展览展示平台</div>
      <div class="right">
        <div class="tabs">
          <router-link
            :to="item.path"
            v-for="(item, index) in pages"
            :key="index"
            :class="['tab-item', currentTab == item ? 'active' : '']"
            @click="handleClickTab(item)"
            >{{ item.name }}</router-link
          >
        </div>
        <div class="operation">
          <span v-if="hasToken" class="operation-item">欢迎你，{{ userInfo.username }}</span>
          <!-- <router-link v-if="!hasToken" to="/login" class="operation-item"
            >登陆</router-link
          > -->
            <span v-if="!hasToken" @click="handleToLogin" class="operation-item"
            >登陆</span
          >
          <router-link v-if="hasToken" to="/personal" class="operation-item"
            >个人中心</router-link
          >
          <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" @click="handleLogOut"
                  >确定</el-button
                >
              </div>
              <span class="operation-item" slot="reference">退出</span>
            </el-popover>
          </span>
        </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: "",
    };
  },
  methods: {
    handleToLogin(){
      this.$router.push('/login?redirect='+this.$route.fullPath)
    },
    async handleLogOut() {
      await this.$store.dispatch("user/logout");
      this.logoutDialogVisible = false;
      // this.$router.push(`/login?redirect=${this.$route.fullPath}`);
    },
    handleClickTab(tab) {
      this.currentTab = tab;
    },
  },
};
</script>

<style lang="scss" scoped>
a {
  color: #000;
  text-decoration: none;
}
.nav {
  height: 120px;
  width: 100%;
  // background-color: #1e5fbb;
  //  box-shadow: 0 2px 10px 6px rgba(0, 0, 0, 0.12);
  .container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 100px;
    .title {
      font-size: 30px;
      // font-weight: bold;
      font-family: LiSu;
      min-width: 330px;
      // color: #c8945b;
    }
    .right {
      display: flex;

      .tabs {
        display: flex;
        margin-right: 100px;
        .tab-item {
          margin-right: 40px;
          min-width: 64px;
          // color: #fff;
        }
        .router-link-exact-active {
          position: relative;
          &::after {
            content: "";
            position: absolute;
            width: 100%;
            height: 2px;
            bottom: -4px;
            left: 0;
            background-color: #000;
          }
        }
        // .router-link-active{}
      }
      .operation {
        min-width: 270px;
        .operation-item {
          margin: 0 8px;
          cursor: pointer;
          // color: #fff;
        }
      }
    }
  }
}
</style>