<template>
  <div class="menu">
    <div class="nav-left">
      <img class="logo" src="https://zws-imgs-pub.ezijing.com/pc/base/logo.svg" alt="logo" />
      <div class="text-title" @click="setStatus">{{ $t('components.learnSysLayout.navigation.title') }}</div>
    </div>
    <div class="nav-right">
      <div class="notify" @click="goNotify()">
        {{ $t('components.learnSysLayout.navigation.tip') }}
        <div class="num" v-if="this.$store.getters.myMsg != 0">{{ this.$store.getters.myMsg }}</div>
      </div>
      <language-switch />
    </div>
  </div>
</template>

<script>
import LanguageSwitch from '@/components/languageSwitch/index.vue'
import cAction from '../../action'

export default {
  components: { LanguageSwitch },
  data() {
    return {
      num: this.$store.getters.myMsg
    }
  },
  mounted() {
    cAction.Other.getNavMsg()
      .then(data => {
        this.$store.commit('myMsg', data.num)
      })
      .catch(e => {
        this.$message.error(e.message)
      })
      .finally(() => {})
  },
  methods: {
    goNotify() {
      this.$router.push({ path: '/app/other/message' })
    },
    setStatus() {
      if (this.status) {
        this.status = false
      } else {
        this.status = true
      }
      this.$root.$emit('updateStatus', this.status)
    }
  }
}
</script>

<style scoped lang="scss">
.menu {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #b80037;
  .nav-left {
    float: left;
    position: relative;
    height: 100%;
    img.logo {
      position: absolute;
      left: 0;
      top: 50%;
      height: 80%;
      width: auto;
      transform: translateY(-50%);
    }
    .text-title {
      float: left;
      margin-left: 190px;
      line-height: 60px;
      font-size: 16px;
    }
  }
  .nav-right {
    display: flex;
    align-items: center;
  }
  .notify {
    position: relative;
    float: right;
    padding: 0 20px;
    line-height: 60px;
    font-size: 16px;
    cursor: pointer;
    .num {
      position: absolute;
      top: 9px;
      left: 50px;
      padding: 1px 5px 2px 4px;
      font-size: 12px;
      line-height: 14px;
      color: #ffffff;
      background: #fb2121;
      border-radius: 50%;
    }
    &:hover {
      color: #b49441;
    }
  }
}

@media (max-width: 767px) {
  .menu {
    .nav-left {
      img.logo {
        display: none;
      }
      .text-title {
        margin-left: 0;
      }
    }
  }
}
</style>
