<template>
  <div class="head-box">
    <div class="flex head-box-content">
      <div class="head-box-title">
        <span class="avt"></span>
        <span class="title">佛山交科4A统一身份安全管理平台</span>
      </div>
      <div class="head-box-menu flex-wrap">
        <div class="user">
          <img class="head-icon-img" src="../../assets/status/ic_user.png" alt="">
          <span class="name">{{ name }}</span>
        </div>
        <!-- <div class="seting">
          <span @click="toSystem" class="img-icon"></span>
        </div> -->
        <div class="lock">
          <span @click="dialogPwd" class="img-icon"></span>
        </div>
        <div class="exit">
          <span @click="exitDialog" class="img-icon"></span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { loginUp } from '@/api/login'
import { mapGetters } from 'vuex'
export default {
  name: 'Hamburger',
  computed: {
    ...mapGetters(['firstLogin']),
    name () {
      return this.$store.state.user.name
    }
  },
  watch: {
    '$store.state.app.outcheck': {
      handler (val) {
        if (val) {
          this.logout()
        }
      },
      deep: true
    }
  },
  mounted () {
    // 首次登录
    if (this.firstLogin) {
      this.$message.warning('初次登录本系统,请修改密码')
      this.dialogPwd()
    }
  },
  methods: {
    //退出系统-弹框
    exitDialog () {
      this.$store.dispatch('app/toggleOutflag', true)
    },
    // 退出系统
    async logout () {
      let params = {
        UserId: this.$store.state.user.UserId,
        UserType: this.$store.state.user.UserType
      }
      // let loginUper = await loginUp(params)
      // if (loginUper) {}
      // await this.$store.dispatch('user/logout')
      // this.$router.push(`/login?redirect=${this.$route.fullPath}`)
      // if (loginUper.code == 0) {
      await this.$store.dispatch('user/logout')
      this.$router.push(`/login?redirect=${this.$route.fullPath}`)
      // }
    },
    //修改密码
    dialogPwd () {
      this.$store.dispatch('app/togglePwdflag', true)
    },
    //跳转
    toSystem () {
      this.$router.push(`/systemManagement`)
    }
  }
}
</script>

<style lang="scss" scoped>
.head-box {
  .head-box-title {
    font-size: 20px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    color: #303133;
    .avt {
      display: inline-block;
      width: 32px;
      height: 32px;
      background: #303133;
      border-radius: 50%;
      vertical-align: middle;
      margin-right: 16px;
      position: relative;
      top: -3px;
      img {
        max-width: 100%;
      }
    }
  }
  .head-box-menu {
    > div {
      margin-right: 20px;
      &:last-child {
        margin-right: 0;
      }
    }
    .head-icon-img {
      position: relative;
      top: 6px;
    }
    .img-icon {
      display: inline-block;
      width: 24px;
      height: 24px;
      vertical-align: middle;
      background-repeat: no-repeat;
      background-size: cover;
      cursor: pointer;
      transition: all 0.3s;
    }
    .user {
      font-size: 16px;
      font-family: Microsoft YaHei;
      font-weight: bold;
      color: #303133;
      .name {
        margin-left: 10px;
      }
    }
    .seting {
      .img-icon {
        background-image: url("../../assets/status/ic_setting.png");
        &:hover {
          background-image: url("../../assets/status/ic_setting_hovar.png");
        }
      }
    }
    .lock {
      .img-icon {
        background-image: url("../../assets/status/ic_password.png");
        &:hover {
          background-image: url("../../assets/status/ic_password_hovar.png");
        }
      }
    }
    .exit {
      .img-icon {
        background-image: url("../../assets/status/ic_exit.png");
        &:hover {
          background-image: url("../../assets/status/ic_exit_hovar.png");
        }
      }
    }
  }
}
</style>

