<template>
  <div class="Header">
    <div class="H_content com-container">
      <div class="image" @click="toRecruit">
        <img :src="system_logo" alt="" />
      </div>
      <div class="right">
        <el-dropdown @command="handleCommand" trigger="click">
          <div class="el-dropdown-link">
            <img src="@/assets/img/default.svg" class="img_user" />
            <span class="phone">{{ phone }}</span>
            <i class="el-icon-arrow-down el-icon--right"></i>
          </div>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="1">
              <i class="el-icon-switch-button"></i>退出
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </div>
  </div>
</template>
<script>
/* eslint-disable */
import Cookie from "js-cookie";
import { logout } from "r/index/login";

export default {
  name: "Header",
  data() {
    return {
      phone: window.localStorage.getItem(
        "phone" + this.$store.state.indexIdentity
      ),
      system_logo: window.localStorage.getItem(
        "system_logo" + this.$store.state.indexIdentity
      ),
    };
  },
  methods: {
    handleCommand(command) {
      if (command == 1) {
        this.logout();
      }
    },
    //  退出
    async logout() {
      const confirmResult = await this.$confirm(`确认退出登录？`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        closeOnClickModal: false,
        type: "warning",
      }).catch((err) => err);
      if (confirmResult !== "confirm")
        return this.$message.info("您取消了退出");

      // 清除本地缓存除了大学logo
      window.localStorage.clear();
      let code = this.$store.state.indexIdentity;
      await this.$router.replace("/" + code);
      this.$message.success("退出成功");
      await logout({});
    },
    // 点击图片跳转到招生简章页面
    toRecruit() {
      // 清除本地缓存除了大学logo
      let code = this.$store.state.indexIdentity;
      this.$router.replace("/" + code);
    },
  },
};
</script>
<style lang="scss" scoped>
@import "a/scss/common";

.Header {
  font-family: PingFang SC;
  height: 80px;
  box-shadow: 0px 0px 12px 0px rgba(0, 0, 0, 0.12);

  .H_content {
    height: 100%;
    display: flex;
    flex-flow: row;
    align-items: center;
    justify-content: space-between;

    .image img {
      // width: 318px;
      height: 62px;
    }

    .right {
      height: 80px;

      ::v-deep .el-dropdown {
        height: 80px;

        .el-dropdown-link {
          height: 80px;
          display: flex;
          flex-flow: row;
          align-items: center;

          .img_user {
            width: 34px;
            height: 34px;
            background-color: #d8d8d8;
            border-radius: 50%;
          }

          .phone {
            margin: 0 10px 0 12px;
          }
        }

        &:hover {
          cursor: pointer;
        }
      }
    }
  }
}
</style>
