<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">
            <el-dropdown size="mini">
              <span class="text">{{userName}}<i class="el-icon-arrow-down el-icon--right" v-if="isicon"></i> </span>
                <el-dropdown-menu slot="dropdown">
                  <div v-if="isicon" size="mini" class="checkButton" @click="out">退出</div>
                </el-dropdown-menu>
            </el-dropdown>
            <!-- <div class="checkout" v-show = "showButton" @mouseover="hover()">退出</div> -->
            <nuxt-link to="/login/user" class="login" v-show="showDefault">请登录</nuxt-link>
            <span style="color:blue;margin-left:30px" class="other" @click="loginOther" v-show="showDefault">商家免费入住</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>
      </div>
    </div>
  </div>
</template>

<script>
import {getSecond} from '@/common/list.js'
  export default {
    created(){

    },
    mounted(){
      
      let tokenStr = sessionStorage.getItem("token")
      console.log(tokenStr+"-------------")
      if(tokenStr){
        /* let a = sessionStorage.getItem("companyNameType")
        if(a=="1"){
          setTimeout(()=>{
          location.reload()
          sessionStorage.removeItem("companyNameType")
          },10)
        } */
        this.getSecond()
        this.showDefault = false
        this.isicon = true
      }
    },
    data() {
      return {
        isicon:false,
        input: '',
        userName:'欢迎来到捷安采,',
        showDefault: true,
        /* showButton:false */
      }
    },
    methods: {
      async getSecond(){
        const {data} = await getSecond()
        console.log(data+'------------------------')
        this.userName = data.companyName
      },
      //商家管理后台
      loginOther(){
        this.$router.push("/login/examine")
      },
      //收藏按钮
      addFavo() {
        this.$message.success('同时按住ctrl+D收藏本站')
      },
      jump(){
        let token=window.sessionStorage.getItem("token")
        if(token){
          /* window.location.href="http://192.168.200.201:8082/#/purchaser/Home" */
          window.location.href=`http://60.205.251.80:8082/#/purchaser/Home?token=${token}`
        }
         /* window.location.href=`http://192.168.200.201:8082/#/purchaser/Home?token=${token}` */
      },
      /* hover(){
        this.showButton = true
      },
      out(){
        this.showButton = false
      } */
      out(){
        sessionStorage.clear()
        this.$router.push("/login/user")
      }
    },

  }
</script>

<style scoped>
.right-pos{
  position: absolute;
  top:12px;
  left:1000px;
  cursor:pointer;
  font-size: 10px;
  color:blue;
  background: none;
}

  .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
  }
  .other{
    cursor: pointer;
  }
  /* .checkout{
    position: absolute;
    left:365px;
    top:40px;
    font-size: 16px;
    border: 1px solid black;
    padding-left:15px;
    padding-right: 15px;
    border-top:none
  } */
  .checkButton{
    /* padding-left:-50px;
    padding-right: 50px; */
    width:100px;
    text-align: center;
    cursor:pointer
  }
  .text{
    font-size: 10px;
  }
</style>
