<template>
    <div>
		<div id="navigation" class="navbar-inverse navbar-fixed-top animated-header">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <h1 class="navbar-brand">
                    <a href="#">
                        <img class="logo-img" src="/static/img/assets/dalogo3x.png" alt="">
                    </a>
                </h1>
            </div>
            <div class="collapse navbar-collapse navbar-right" role="navigation">
          <ul id="nav" class="nav navbar-nav menu">
            <li><a href="#"><span>首页</span></a></li>
            <li @click="home">
              <a href="#feature"><span>特色</span></a>
              <!-- <router-link to="/enterprise"><a href="#"><span>特色</span></a></router-link> -->
            </li>
            <li><a href="#service"><span>功能</span></a></li>
            <li><a href="#prototype"><span>帮助中心</span></a></li>
            <li><a href="https://uas.usoftchina.com/about" target="_blank"><span>关于我们</span></a></li>
            <li class="login" v-if="!account" style="margin-left: 20px;">
              <span @click="login"><img src="/static/img/assets/denglu3x.png" alt="">登录  &nbsp;</span>
              <span @click="register"><img src="/static/img/assets/zhuce3x.png" alt="">注册</span>
            </li>
            <li class="profile" v-if="account">
							<span class="user-info">
								<img src="/static/img/assets/denglu3x.png" alt="">
								<span id="user-info">{{account.realname || account.username}}</span>
							</span>
              <span @click="loginout">【退出】</span>    |
              <router-link to="/enterprise"><a href="#"><span style="color: white">账户管理</span></a></router-link>
            </li>
          </ul>
        </div>
        </div>
        
    </div>

    <iframe hidden :src="setTokenPage"></iframe>
    <main class="site-content" role="main">
      <!-- 遮罩 -->
      <div class="zhezhao" v-if="isLogin || isRegister || isexperience"></div>
      <div class="box" v-if="isLogin || isRegister">
        <div>
          <img @click="closeModal" class="tc-on shut"
               src="/static/img/qiye/chahao.png" alt="">
        </div>
        <iframe width="430" height="440" :src="ssoPage"></iframe>
        <iframe hidden :src="setTokenPage"></iframe>
      </div>
      <div class="tiyan" v-if="isexperience">
        <div><span>欢迎你访问u企云服</span></div>
        <div>
          <p>1.</p>
        </div>
        我是体验
        <img @click="Closeexperience" class="tc-on shut"
               src="/static/img/qiye/chahao.png" alt="">
      </div>

      <!--Home Slider==================================== -->
      <section id="home-slider">
        <div id="slider" class="sl-slider-wrapper">
          <div class="sl-slider">

            <div class="sl-slide" data-orientation="horizontal" data-slice1-rotation="-25" data-slice2-rotation="-25"
                 data-slice1-scale="2" data-slice2-scale="2">
              <div class="mask-overly"></div>
              <div class="bg-img slider-1">
                <img src="/static/img/assets/beijing2x.png" alt="">
              </div>
              <!-- 首页内容 -->
              <div class="my-text">
                <button class='my-tiyan' @click="experience">立即体验</button>

              </div>
              <div class="slide-caption">
                <div class="caption-content"></div>
              </div>
            </div>
          </div>
        </div>
      </section>

      <!-- End Home SliderEnd==================================== -->

      <!-- 特色 -->
      <section id="feature">
        <div class="container ts-worp">
          <div class="section-title text-center">
            <p class="ts-title">我们的特色</p>
            <p class="ts-text">云端部署 &nbsp;&nbsp; 轻量应用</p>
          </div>
          <div class="ts-box">
            <div style="margin:50px 0;">
              <img class="ts-img" src="/static/img/features.jpg" alt="">
            </div>
            <div class="right right-text">
              <img class="ts-minimg" src="/static/img/assets/1.png" alt="">
              <div class="ts-mintext">
                <p style="font-size: 32px !important;margin-bottom: 36px;"><img class="ts-textimg"
                                                                                src="/static/img/assets/xunzhao@2x.png"
                                                                                alt="">迅速找到您想要的</p>
                <p>寻找供应商资源</p>
                <p>寻找产品货源  寻找产品资料</p>
              </div>
            </div>
          </div>
          <div class="ts-box">
            <div class="left left-text">
              <img class="ts-minimg" style="left:0;" src="/static/img/assets/2.png" alt="">
              <div class="ts-mintext ts-lefttext">
                <p style="font-size: 32px !important;margin-bottom: 36px;">直观看到您想看的<img class="ts-textleftimg"
                                                                                        src="/static/img/assets/fen xi@2x.png"
                                                                                        alt=""></p>
                <p>每日订单量、收付款、月度销售分析、采购分析</p>
                <p>让你成为企业经营老司机</p>
              </div>
            </div>
            <div style="margin:50px 0;">
              <img class="ts-img" src="/static/img/features.jpg" alt="">
            </div>
          </div>
          <div class="ts-box">
            <div style="margin:50px 0;">
              <img class="ts-img" src="/static/img/features.jpg" alt="">
            </div>
            <div class="right right-text">
              <img class="ts-minimg" src="/static/img/assets/1.png" alt="">
              <div class="ts-mintext" style="right: 145px;">
                <p style="font-size: 32px !important;margin-bottom: 36px;"><img class="ts-textimg"
                                                                                src="/static/img/assets/kuaisu@2x.png"
                                                                                alt="">快速上手 生意简单做</p>
                <p>移动端的交互体验</p>
                <p>简短清晰的业务流程 让你三分钟上手</p>
              </div>
            </div>
          </div>
        </div>
      </section>

      <!-- Service section 功能-->
      <section id="service">
        <div class="container" style="position: relative;">
          <img class="gn-beijing" src="/static/img/gongneng/xu xian@3x.png" alt="">
          <div class="row">
            <div class="section-title text-center">
              <p class="ts-title">我们的功能</p>
            </div>
            <div class="gn-hei">
              <div class="col-md-3 col-sm-6 col-xs-12">
                <div class="service-item">
                  <p class="gn-text gn-color">任务管理</p>
                  <p>任务分配，高效工作</p>
                  <p>管好每一件事</p>
                  <div class="gn-img">
                    <img src="/static/img/gongneng/ren wu 1@3x.png" alt="">
                  </div>
                </div>
              </div>
              <div class="col-md-3 col-sm-6 col-xs-12">
                <div class="service-item">
                  <p class="gn-text">资源管理</p>
                  <p>一键查询，海量供应商产品信息</p>
                  <p>节约时间</p>
                  <div class="gn-img gn-huise">
                    <img src="/static/img/gongneng/zi yuan 2@3x.png" alt="">
                  </div>
                </div>
              </div>
              <div class="col-md-3 col-sm-6 col-xs-12">
                <div class="service-item">
                  <p class="gn-text">销售管理</p>
                  <p>快速制单</p>
                  <p>利润实时算</p>
                  <div class="gn-img">
                    <img src="/static/img/gongneng/ xiao shou 3@3x.png" alt="">
                    <div class="gn-xiaoqiu"></div>
                  </div>
                </div>
              </div>
              <div class="col-md-3 col-sm-6 col-xs-12">
                <div class="service-item">
                  <p class="gn-text">采购管理</p>
                  <p>寻源.定价.采购</p>
                  <p>一条流程</p>
                  <div class="gn-img gn-huise">
                    <img src="/static/img/gongneng/cai gou 4@3x.png" alt="">
                  </div>
                </div>
              </div>
              <div class="col-md-3 col-sm-6 col-xs-12">
                <div class="service-item">
                  <div class="gn-img gn-huise">
                    <img src="/static/img/gongneng/cang ku 5@3x.png" alt="">
                    <div class="gn-xiaoqiu"></div>
                  </div>
                  <p class="gn-text">仓库管理</p>
                  <p>库存盘点，库存账龄</p>
                  <p>呆滞分析</p>
                </div>
              </div>
              <div class="col-md-3 col-sm-6 col-xs-12">
                <div class="service-item">
                  <div class="gn-img">
                    <img src="/static/img/gongneng/jia gong 6@3x.png" alt="">
                  </div>
                  <p class="gn-text">加工管理</p>
                  <p>BOM成本及时看</p>
                  <p>加工单自动出入库作业</p>
                </div>
              </div>
              <div class="col-md-3 col-sm-6 col-xs-12">
                <div class="service-item">
                  <div class="gn-img gn-huise">
                    <img src="/static/img/gongneng/QIAN BAO 7@3x.png" alt="">
                  </div>
                  <p class="gn-text">资金管理</p>
                  <p>清晰核算</p>
                  <p>实时查看供应商和客户账款情况</p>
                </div>
              </div>
              <div class="col-md-3 col-sm-6 col-xs-12">
                <div class="service-item">
                  <div class="gn-img">
                    <img src="/static/img/gongneng/FEN XI 8@3x.png" alt="">
                    <div class="gn-xiaoqiu gn-left"></div>
                  </div>
                  <p class="gn-text gn-color">智能分析</p>
                  <p>直观数据看板，看库存分析</p>
                  <p>收款分析，付款分析</p>
                </div>
              </div>
            </div>
          </div>
        </div>
      </section>
      <!-- end Service section -->

      <!-- 帮助中心 -->
      <section id="prototype">
        <div class="container">
          <div class="row">
            <div class="section-title text-center">
              <p class="ts-title">帮助中心</p>
            </div>
            <div class="bz-worp">
              <div class="bz-box">
                <div class="bz-sskuang">
                  <span><img class="bz-sousuoimg" src="/static/img/assets/sou.png" alt=""></span>
                  <input class="bz-sousuo" type="text" placeholder="输入标题搜索"/>
                </div>
                <button class="bz-btn">搜索</button>
              </div>
              <div class="bz-content">
                <div class="bz-left">
                  <ul class="bz-ul">
                    <li class='active'>操作文档</li>
                    <li>常见问题</li>
                  </ul>
                </div>
                <div class="bz-right">
                  <div class="bz-right-conent">
                    <div>
                      <ul>
                        <li>
                          <span class="left bz-yuandian"></span>
                          <span class="left">方式不同吧好像是差不多哇来访黑哇哦发检测句ID回复开展了好xxxxx操作文档 </span>
                          <span class="right">2018年10月31日  12:00</span>
                        </li>
                        <li>
                          <span class="left bz-yuandian"></span>
                          <span class="left">XXXXXXXXXXXXXXX操作文档</span>
                          <span class="right">2018年10月31日  12:00</span>
                        </li>
                        <li>
                          <span class="left bz-yuandian"></span>
                          <span class="left">XXXXXXXXXXXXXXX操作文档</span>
                          <span class="right">2018年10月31日  12:00</span>
                        </li>
                      </ul>
                    </div>
                    <div>
                      <ul>
                        <li>
                          <span class="left bz-yuandian"></span>
                          <span class="left">方式不同吧好像是差不多哇来访黑哇哦发检测句ID回复开展了好xxxxx常见问题 </span>
                          <span class="right">2018年10月31日  12:00</span>
                        </li>
                        <li>
                          <span class="left bz-yuandian"></span>
                          <span class="left">方式不同吧好像是差不多哇来访黑哇哦发检测句ID回复开展了好xxxxx常见问题</span>
                          <span class="right">2018年10月31日  12:00</span>
                        </li>
                        <li>
                          <span class="left bz-yuandian"></span>
                          <span class="left">XXXXXXXXXXXXXXX常见问题</span>
                          <span class="right">2018年10月31日  12:00</span>
                        </li>
                      </ul>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </section>
    </main>
  </div>
</template>

<script>
  import {subscribe, disconnect} from '@/api/socket'
  import Session from '@/utils/session'

  export default {
    data() {
      return {
        isLogin: false,
        isRegister: false,
        clientId: null,
        account: null,
        isexperience: false
      }
    },
    mounted() {
      this.clientId = Math.random().toString(36).substr(2)
      // 从本地加载已经登录的信息
      this.account = Session.getAccount()
      console.log(this.$store.state.isAutoLogin)
    },
    computed: {
      setTokenPage() {
        return this.$url.web + '/set-token.html'
      },
      ssoPage() {
        if (this.isLogin) {
          return this.$url.sso + '/sassLogin?appId=sp&baseUrl=' +
            encodeURIComponent(this.$url.api + '/api/auth/sso/callback/' + this.clientId)
        }
        if (this.isRegister) {
          return this.$url.sso + '/sassLogin/register?appId=sp&baseUrl=' +
            encodeURIComponent(this.$url.api + '/api/auth/sso/callback/' + this.clientId)
        }
      }
    },
    methods: {
      home() {
        document.documentElement.scrollTop = 0;
      },
      listenOnCallback() {
        const me = this
        subscribe(this.clientId, '/sso/callback').then(data => {
          const session = data.token, account = data.account
          account.companies = account.companies || []
          session.account = account
          Session.set(session)
          const frame = window.frames[window.frames.length - 1]
          window.addEventListener('message', () => {
           if(me.isLogin){
            me.isLogin = false
            if (!account.companyId) {
              // 添加企业
              me.$router.push({path: '/enterprise', query: {mydata: account}})
              me.$store.state.isAutoLogin = true;
            } else {
              // 跳转应用页面
              window.location.href = me.$url.web
            }
           } 
          }, false)
          frame.postMessage(JSON.stringify(session), '*')
        })
      },
      login() {
        // 显示账户中心登录窗口
        this.isLogin = true
        // 监听账户中心回调消息
        this.listenOnCallback()
      },
      register() {
        this.isRegister = true
        this.listenOnCallback()
      },
      //退出
      loginout(){
        const frame = window.frames[window.frames.length - 1]
        frame.postMessage('', '*')
        Session.remove()
        this.$router.go(0); 
      },
      // 关闭窗口
      closeModal() {
        const me = this
        disconnect( () => {
          me.isLogin = false
          me.isRegister = false
        })
      },
      //体验
      experience(){
        this.isexperience = true;
      },
      //关闭体验
      Closeexperience(){
        this.isexperience = false;
      }
    }
  }
</script>

<style scoped>
.shut {
  cursor: pointer;
  position: absolute;
  top: 10px;
  right: 10px;
}
.tiyan {
  position: absolute;
  top: 50%;
  left: 50%;
	width: 400px;
	height: 200px;
	margin-left: -200px;
  margin-top: -100px;
  z-index: 10001;
  background: white;
}
.navbar-inverse {
  /* padding: 3px; */
  padding: 0px;
  /* height: 70px;
  line-height: 70px; */
}
</style>
