<template>
  <div class="header">
    <div class="header-line ">
      <div class="flex-between content bg">
        <div class="flex-item">
          <div class="flex-item">
            <img src="~/assets/head/home-fill.png" class="home-fill" alt="logo"></img>
            <nuxt-link to="/" class="head-title t1">首页</nuxt-link>
          </div>
          <div class="welcome t1">
            <span>你好,{{userName}}</span>
            <nuxt-link to="/login/user" class="login" v-show="showDefault">登录</nuxt-link>
            <span>商家免费入住</span>
            <button @click="jump" v-show="!showDefault" class="right-pos">跳转后台</button>
          </div>
        </div>
        <div class="flex-item t1 collection">
          <div @click="addFavo" class="t5">收藏网站</div>
          <img @click="addFavo" src="~/assets/head/collection.png" alt="收藏" class="t5">
          <div @click="admin" class="t5">管理员入口</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    created(){

    },
    mounted(){
      let tokenStr = window.sessionStorage.getItem("token")
      if(tokenStr){
        this.showDefault = false
        this.userName = window.sessionStorage.getItem("companyName")
      }
    },
    data() {
      return {
        input: '',
        userName:'来到捷安采',
        showDefault: true
      }
    },
    methods: {
      //收藏按钮
      addFavo() {
        this.$message.success('同时按住ctrl+D收藏本站')
      },
      admin() {
        this.$router.push("/login/admin")
      },
      jump(){
        let token=window.sessionStorage.getItem("token")
        if(token){
          /* window.location.href="http://192.168.200.201:8082/#/purchaser/Home" */
          window.location.href=`http://192.168.200.201:8082/#/purchaser/Home?token=${token}`
        }
         /* window.location.href=`http://192.168.200.201:8082/#/purchaser/Home?token=${token}` */
      },
      getUserName(){
        return window.sessionStorage.getItem("companyName");
      }
    },

  }
</script>

<style scoped>
.right-pos{
  position: absolute;
  left:980px;
  cursor:pointer;
  font-size: 10px;
  background: #bfa;
}
  .bg {}

  .header-line {
    /* margin-top: .9rem; */
    width: 100%;
    height: .50rem;
    background: rgba(245, 245, 245, 1);
    border: 1px solid rgba(225, 225, 225, 1);
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .home-fill {
    width: .18rem;
    height: .18rem;
    margin-right: .1rem
  }

  .welcome {
    color: rgba(150, 151, 153, 1);
  }

  .welcome>span:last-child {
    color: #0486FE
  }

  .collection>img {
    width: .16rem;
    height: .16rem;
    margin: 0 .62rem 0 .2rem;
  }

  .head-title {
    margin-right: 0.5rem;
  }

  .welcome>.login {
    color: #FF0000;
  }
  .t5{
    cursor:pointer
  }
</style>
