<template>
  <div class="Header">
    <div class="H_content com-container">
      <div class="image">
        <img :src="system_logo" alt="" />
      </div>
      <div class="right" v-if="!isLogin">
        <span
          @mouseenter="onMouserEnter(false)"
          :class="isHover ? '' : 'is-hover'"
          @click="toLogin"
          >登录</span
        >
        <span
          @mouseenter="onMouserEnter(true)"
          :class="isHover ? 'is-hover' : ''"
          @click="toRegister"
          >注册</span
        >
      </div>
      <div class="right alreadyLogin" v-else>
        <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" @click="toCenter">
              <i class="el-icon-user"></i>个人中心
            </el-dropdown-item
            > -->
            <el-dropdown-item command="2" @click="logout">
              <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 {
      isHover: true,
      system_logo: window.localStorage.getItem(
        "system_logo" + this.$store.state.indexIdentity
      ),
      isLogin: false,
      phone: window.localStorage.getItem(
        "phone" + this.$store.state.indexIdentity
      ),
    };
  },
  created() {
    let code = this.$store.state.indexIdentity;
    this.isLogin = !!localStorage.getItem("index-token" + code);
  },
  methods: {
    toLogin() {
      let code = this.$store.state.indexIdentity;
      this.$router.push("/login?code=" + code);
    },
    handleCommand(command) {
      if (command == 2) {
        this.logout();
      }
      if (command == 1) {
        this.toCenter();
      }
    },
    toCenter() {
      let code = this.$store.state.indexIdentity;
      this.$router.replace("/signUp/examInfo?code=" + code);
    },
    toRegister() {
      let code = this.$store.state.indexIdentity;
      this.$router.push("/register?code=" + code);
    },
    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;
      window.localStorage.removeItem("doubt_code" + code);
      window.localStorage.removeItem("doubt_info" + code);
      window.localStorage.removeItem("doubt_check" + code);
      window.localStorage.removeItem("index-token" + code);
      window.localStorage.removeItem("phone" + code);
      window.localStorage.removeItem("camp_name" + code);
      window.localStorage.removeItem("system_color" + code);
      window.localStorage.removeItem("system_logo" + code);
      window.localStorage.removeItem("has_amount" + code);
      window.localStorage.removeItem("campsite_id" + code);
      window.localStorage.removeItem("order_no" + code);
      window.localStorage.removeItem("campindex_type" + code);
      window.localStorage.removeItem("bk_pic" + code);
      window.localStorage.removeItem("examine_status" + code);
      window.localStorage.removeItem("examine_reason" + code);
      window.localStorage.removeItem(
        "sign_up_file_18355151517" +
          window.localStorage.getItem("phone" + code) +
          code
      );
      window.localStorage.removeItem("schoolName" + code);
      window.localStorage.removeItem("camp_statement" + code);
      //  window.localStorage.removeItem("restet_code_time" + code, )
      window.localStorage.removeItem("transfer_account" + code);
      window.localStorage.removeItem("payee" + code);
      window.localStorage.removeItem("bank_first" + code);
      window.localStorage.removeItem("bank_idcard" + code);
      window.localStorage.removeItem(
        "bank_info" + window.localStorage.getItem("phone" + code) + code
      );
      this.isLogin = false;
      if (this.$store.state.human == 1) {
        this.$router.replace({
          path: "/login",
          query: {
            code: code,
          },
        });
      } else {
        this.$router.replace("/" + code);
      }
      this.$message.success("退出成功");

      await logout({});
    },
    onMouserEnter(val) {
      this.isHover = val;
    },
  },
};
</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 {
      span {
        font-size: 15px;
        font-weight: 500;
        color: #666666;
        line-height: 21px;
        padding: 10px 36px;
        border-radius: 4px;
        border: 2px solid transparent;

        &:last-child {
          margin-left: 10px;
        }

        &.is-hover {
          cursor: pointer;
          color: var(--color);
          border-color: var(--color);
        }
      }

      &.alreadyLogin span {
        padding: 0 !important;
      }

      ::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>
