<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"/>
            <nuxt-link to="/" class="head-title t1 textr">首页</nuxt-link>
          </div>
          <div class="welcome t1">
            <el-dropdown size="mini">
              <span class="text textr" style=" color:#969799">{{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 textr" v-show="showDefault">登录</nuxt-link>
            <span style="color:#0486FE;margin-left:.15rem" class="other textr" @click="loginOther" v-show="showDefault">商家免费入驻</span>
          </div>
        </div>
        <div class="flex-item t1 collection">
          <button @click="jump" v-show="!showDefault" class="right-pos textr">商家管理后台</button>
          <div @click="addFavo" class="t5 textr">收藏网站</div>
          <img @click="addFavo" src="~/assets/head/collection.png" alt="收藏" class="t5 textr">
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {getSecond} from '@/common/list.js'
import Cookies from 'js-cookie'
import url from "@/assets/js/url.js"
  export default {
    mounted(){
      let tokenStr = Cookies.get("token")
      console.log(1234567890)
      console.log(1234567890)
      console.log(tokenStr+"-------------")
      if(tokenStr){
        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=Cookies.get("token")
        if(token){
          /* window.location.href="http://192.168.200.201:8082/#/purchaser/Home" */
          window.location.href=url+`/#/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(){
        Cookies.remove("token")
        this.$router.push("/login/user")
      }
    },

  }
</script>

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

  .header-line {
    /* margin-top: .9rem; */
    width: 100%;
    height: .30rem;
    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-left:.15rem;
  }

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

  .welcome>.login {
    color: #FF0000;
  }
  .t5{
    cursor:pointer
  }
  .other{
    cursor: pointer;
    margin-left:50px
  }
  /* .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: 12px;
  }
  .textr{
      font-size:12px;
      line-height:.50rem;
     
  }
</style>
