<template>
  <div class="login-box-parent">
    <div class="all" style="">
      <div class="data-all" style="text-align:center;margin-top:50px;">
        <transition name="fade">
          <!-- <img
            src="/static/images/login300.png"
            v-if="logImage"
            style="margin:48px auto;width:104px;height:104px;"
            alt=""
          /> -->
          <img
            src="/static/images/init.gif"
            style="margin:0 auto;"
            alt=""
          />
        </transition>
        <div>管理执行难，就用功道云</div>
        <!-- <transition name="fade">
          <van-button
            class="refresh"
            type="info"
            @click="LoginBut"
            v-show="loginButton"
            style="border-radius:5px;margin-top:10px;"
            >{{ logButText }}</van-button
          >
        </transition> -->
      </div>
    </div>
  </div>
</template>

<script>
import Vue from "vue";
import { Divider } from "vant";
import Cookies from 'js-cookie'

import request from '@/utils/request'
import { getToken, setToken } from "@/utils/auth";

import { wxAuth } from "@/utils/wx-auth-two.js";
import axios from "axios";
Vue.use(Divider);
export default {
  name: "login1",
  data() {
    return {
      logImage: true,
      logButText: "登录",
      loginButton: true
    };
  },
  activated() {//activated()每次进入页面都会执行,代替created
    if(Cookies.get('Admin-Token')){
      console.log('Admin-Token')
      const user_info = this.$store.getters.user_info || JSON.parse(localStorage.getItem('user_info')).data || JSON.parse(plus.storage.getItem('user_info')).data
      console.log(user_info)
      if(user_info){
        wxAuth(true);
      }else{
        this.detailAxiox()
      }
    }else{
      console.log('222222')
      var url = window.location.href; //获取url中"?"符后的字串
      let tokenif = false
      var token = ''
      if(url){
        if (url.split("?")[1]) {//判断有无？参数
          let str = url.split("?")[1]
          console.log(str)
          if(str.split("=")[0] == 'token'){
            token = str.split("=")[1].split("#")[0]
            console.log(str.split("=")[1])
            tokenif = true
          }
        }
      }
      if(tokenif){
        setToken(token);
        this.detailAxiox(token)
      }else{
        window.location.href = 'http://test.qywx.g107.net/wechat/authorize?platform='+ this.isPcOrApp() +'#wechat_redirect'
      }
    }
  },
  mounted() {
  },
  watch: {},
  methods: {
    detailAxiox(){
      request('get',process.env.BASE_API+'/api/employee/detail')
      .then(res => {
        if(res.data.code == 1){
          this.$store.commit("SET_USERINFO", res.data.data.user); // 设置员工信息
          window.sessionStorage.setItem('__VCKEEPALIVE__', JSON.stringify(['/']))
          window.sessionStorage.setItem('routers', '/')
          console.log(getToken());
          wxAuth(true);
        }
      })
    },
    // LoginBut() {
    //   // if(this.logButText == "重新登录"){
    //   //   window.location.href = 'http://wechatdimgs.vaiwan.com'
    //   // }else{
    //     console.log(process.env.APPID);
    //     console.log(process.env.REDIRECT_URI);
    //     var appid, redirect_uri, response_type, scope, state, wechat, agentid;
    //     appid = 'ww4065f0d4bb232a6a';
    //     redirect_uri = 'http%3A%2F%2Fwechatdings.vaiwan.com';
    //     response_type = "code";
    //     scope = "snsapi_privateinfo";
    //     state = "a";
    //     wechat = "#wechat_redirect";
    //     let link =
    //       "appid=" +
    //       appid +
    //       "&redirect_uri=" +
    //       redirect_uri +
    //       "&response_type=" +
    //       response_type +
    //       "&scope=" +
    //       scope +
    //       "&state=" +
    //       state +
    //       wechat;
    //     window.location.href =
    //       "https://open.weixin.qq.com/connect/oauth2/authorize?" + link;
    //   // }
    // },
    isPcOrApp(){
      if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
        return 'app'
      } else {
        return 'pc'
      }
    },

    clone() {
      if (window.plus) {
        plus.storage.clear()
	      Cookies.remove('Admin-Token')
      } else {
        window.localStorage.clear()
	      Cookies.remove('Admin-Token')
      }
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.all {
  margin: 0 auto;
  position: relative;
  top: 50%;
  margin-top: -325px;
}
.login-box-parent{
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: auto;
  cursor: default;
  /* background-color: #f5f6f9; */
  background-color: #FFF;
}
</style>
