<template>
  <header>
    <div class="container">
      <div class="w-logo pull-left">
        <a href="#"><img src="/uas.png"></a>
        <div class="w-nav">
          <ul class="list-inline">
            <li><a href="http://uas.ubtob.com/#/index">B2B商务</a></li>
            <li><a href="https://www.usoftmall.com/">优软商城</a></li>
            <li><a href="https://www.ubtob.com/saas/about">优企云服</a></li>
            <li><a href="http://www.yitoa-fintech.com">金融服务</a></li>
            <li><a href="https://www.ubtob.com/#/uuzcJob">人才招聘</a></li>
            <li><a href="http://www.uuzcc.com/">英唐众创</a></li>
            <li><a href="http://diymall.ubtob.com/">定制商城</a></li>
            <li><a href="https://www.ubtob.com/#/help">供应链服务</a></li>
          </ul>
        </div>
      </div>
      <div class="w-login pull-right">
        <template v-if="logged">
          <a href="javascript:void(0)"><span v-text="user.vipName"/> <span>：&nbsp;</span> <span v-text="user.spaceName"/></a>
          <a href="javascript:void(0)" @click="logoutClick">退出</a>
        </template>
        <template v-else>
          <a href="javascript:void(0)" @click="loginClick">登录</a>
          <a href="javascript:void(0)" @click="registerClick">注册</a>
        </template>
      </div>
    </div>
  </header>
</template>

<script>
    export default {
      name: 'MainHeader',
      computed: {
        user () {
          return this.$store.state.option.user.data.content
        },
        logged () {
          return this.$store.state.option.user.logged
        }
      },
      methods: {
        loginClick () {
         this.$http.get('/login')
           .then(response => {
             if (response.data.success) {
               let localhost = window.location.href
               let url = response.data.content.replace('{returnURL}', localhost).replace('{baseUrl}', localhost)
               window.location.href = url
             }
           }).catch(err => {
              console.log(err)
            })
        },
        logoutClick () {
          this.$http.get('/logout')
            .then(response => {
              if (response.data.success) {
                this.$store.state.option.cookies = ''
                window.location.href = response.data.redirectUrl
              }
            }).catch(err => {
              console.log(err)
            })
        },
        registerClick () {}
      }
    }
</script>
