<template>
  <div class="header">
    <div class="con">
      <div class="logo">
        <img :src="require('@/assets/images/icons/img_logo.png')" alt="" />
      </div>
      <ul class="tab">
        <li @click="handleItem(item)" :class="{active:active.id==item.id}" v-for="(item, i) in tab" :key="i">
          {{ item.name }}
        </li>
      </ul>
      <div class="user">
        <!-- <div>
          <img :src="require('@/assets/images/icons/img_logo.png')" alt="" />
          <span>简体中文</span>
        </div> -->
        <img title="回到个人中心" @click="backtoInfo" :src="userInfo.head||$thumb" alt="" />
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      active:{},
      tab: [
        {
          name: "我的作品",
          id: "works",
          path:{
            path:'/works'
          }
        },
        {
          name: "我的素材",
          id: "material",
          path:{
            path:'/'
          }
        }
      ],
    };
  },
  computed:{
    userInfo(){
      let info = {}
      try {
       info = JSON.parse(localStorage.getItem('info')) || {}
      } catch (e) {
        info= {}
      }
      return info
    }
  },
  watch:{
    '$route.meta':{
      deep:true,
      handler:function (newVal) {
        this.active  = this.tab.find(item=>{
          return item.id == newVal.belong 
        })
      }
    }
  },
  methods:{
    backtoInfo(){
      window.location.href = '/#/information'
    },
    handleItem(item){
      this.$router.push(item.path)
    }
  }
};
</script>

<style lang="less" scoped>
.header {
  width: 100%;
  background: #fff;
  box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.1);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 999;
  .con {
    color: #000;
    max-width: 1280px;
    height: 70px;
    display: flex;
    align-items: center;
    margin: 0 auto;
    position: relative;
    padding: 0;
    .logo {
      font-size: 24px;
      font-weight: bold;
      width: 188px;
      >img{
        width: 100%;
        vertical-align: middle;
      }
    }
    .tab {
      display: flex;
      align-items: center;
      margin-left: 116px;
      > li {
        cursor: pointer;
        margin-right: 50px;
        text-align: left;
        font-size: 16px;
        color: #909090;
        &.active{
          font-size: 16px;
          font-weight: bold;
          color: #0076F6;
          position: relative;
          &::before{
            content: '';
            width: 20px;
            height: 2px;
            background: #0076F6;
            display: inline-block;
            position: absolute;
            left: 50%;
            transform: translateX(-50%);
            bottom: -10px;
          }
        }
      }
    }
    .user {
      position: absolute;
      right: 0;
      top: 50%;
      transform: translateY(-50%);
      border-radius: 50%;
      width: 32px;
      height: 32px;
      overflow: hidden;
      > img {
        cursor: pointer;
        height: 100%;
        position: absolute;
        top: 50%;
        transform: translate(-50%, -50%);
        left: 50%;
      }
    }
  }
}
</style>
