<template>
  <div class="login-container">
    <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" v-if="!logImage" style="margin:0 auto;" alt="">
        </transition>
        <div>管理执行难，就用功道云</div>
        <!-- <transition name="fade">
          <el-button class="refresh" type="primary" style="margin-top:10px" @click="LoginBut" v-show="loginButton">{{logButText}}</el-button>
        </transition>
        
        <el-button class="refresh" type="primary" style="margin-top:10px" @click="LoginBut1">123</el-button> -->
      </div>
    </div>
    <pastDue></pastDue>
  </div>
</template>

<script>
  import Cookies from 'js-cookie'
  import axios from 'axios'
  import pastDue from "@/views/common/pastDue.vue"
  import QRCode  from "qrcodejs2"
  import {getToken, setToken, getUser, getPasw, setUser, setPasw,} from '@/utils/auth' // getToken from cookie
  import { wxAuth } from '@/utils/wx-auth-two.js'; 
  import {withoutCodeLoad} from '@/utils/wxconfiguration.js'

  export default {
    data() {
      return {
        logImage:true,
        logButText: '登录',
        loginButton: true,
      }
    },
    components:{QRCode,pastDue},
    watch:{
    },
    created() {
      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){
        console.log(token)
        setToken(token)
        this.$store.commit('SET_TOKEN', token)
        localStorage.setItem('Experience_data',JSON.stringify({if:false,name:''}))
        console.log(getToken())
        
        this.$http('get',process.env.BASE_API+'/api/employee/detail')
        .then(res => {
          if(res.data.code == 1){
            console.log(res)
          }
        })
        wxAuth(true)
      }else{
        if(this.isPcOrApp() == 'pc'){
          window.location.href = process.env.BASE_API+'/wechat/authorize?platform='+ this.isPcOrApp() +'#wechat_redirect'
        }else if(this.isPcOrApp() == 'app'){
          window.location.href = 'http://wechatgdym.vaiwan.com';
        }
      }
      // Cookies.get('Admin-Token')
      // // if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
      // //   this.appPC = "手机"
      // //   window.alert("手机")
      // //   window.location.href = process.env.BASE_API+'/m'
      // // } else {
      // //   this.appPC = "PC端"
      // //   // window.alert("PC端")
      // // }
      // this.$store.dispatch('setLanguage', 'zh')
      // localStorage.setItem('login_code','0')

      
      // var url = window.location.href; //获取url中"?"符后的字串
      // let codesif = false
      // let codes = ''
      // if(url){
      //   if (url.split("?")[1]) {//判断有无？参数
      //     var strs = url.split("?")[1].split("&");
      //     for (var i = 0; i < strs.length; i++) {
      //       if(strs[i].split("=")[0] == 'code'){
      //         this.loginButton = false
      //         this.logImage = false
      //         codesif = true
      //         codes = strs[i].split("=")[1]
      //       }
      //     }
      //   }else{//没有就清空缓存并放出登录按钮
      //     this.clone()
      //     this.loginButton = true
      //     this.logImage = true
      //   }
      // }

      // if(!codesif){
      //   this.logImage = true
      //   this.loginButton = true
      // }else{
      //   if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
      //     window.location.href = 'http://wechatgdym.vaiwan.com?code='+codes+'&';
      //   } else {
      //     let params = { code: codes }
      //     axios.get(process.env.BASE_API+'/api/wechat/minAuth', { params: params })
      //     .then(res => {
      //       if(res.data.code == 1){
      //         if(res.data.data.user.is_official == 1){
      //           setToken(res.data.data.token)
      //           this.$store.commit('SET_TOKEN', res.data.data.token)
      //           localStorage.setItem('Experience_data',JSON.stringify({if:false,name:''}))
      //           console.log(getToken())
      //           wxAuth(true)
      //         }else if(res.data.data.user.is_official == 0){
      //           this.$router.push({path: '/noAccess'})
      //         }
      //       }else if(res.data.code == 4444){
      //         this.$store.state.user.pastDue = true
      //         this.logButText = '重新登录'
      //         this.loginButton = true
      //         this.logImage = true
      //       }else{
      //         this.logButText = '重新登录'
      //         this.loginButton = true
      //         this.logImage = true
      //       }
      //     })
      //   }
        
      // }
    },
    mounted(){
    },
    methods: {
      isPcOrApp(){
        if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
          return 'app'
        } else {
          return 'pc'
        }
      },
      LoginBut1(){
        window.location.href = 'http://test.qywx.g107.net/wechat/authorize?platform=pc#wechat_redirect'
      },
      // LoginBut(){
      //   withoutCodeLoad()
      // },
      // withoutCodeLoad(){
      //   console.log(process.env.APPID)
      //   let appid,redirect_uri,response_type,scope,state,wechat,agentid
      //   appid = process.env.APPID
      //   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
      // },

      clone(){
        localStorage.clear()
        sessionStorage.clear()
	      Cookies.remove('Admin-Token')
        if(!this.$store.state.user.pastDue){
          //进入登录界面判断 VueX里是否遗留数据，有就刷新一次页面，清空vuex
          if (this.$store.getters.addRouters.length > 0) { // 判断是否已经刷新
            return window.location.reload()
          }
        }
      },
    },
    destroyed() {
      localStorage.setItem('login_code','0')
    }
  }
</script>

<style rel="stylesheet/css" type="text/css" scoped>
  .left-box {
    position: relative;
    top: 50%;
    margin-top: -25%;
  }

  .all {
    /* width: 1000px; */
    /* height: 675px; */
    margin: 0 auto;
    position: relative;
    top: 50%;
    margin-top: -325px;
  }

  .login-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: auto;
    cursor: default;
    /* background-color: #f5f6f9; */
    background-color: #FFF;
  }

  .login-container .login_logo {
    position: relative;
    width: 100%;
    max-width: 1000px;
    overflow: hidden;
  }
  .login-container .login_logo a{
    display: inline-block;
  }
  .login-container .login_logo img {
    width: 100%;
    vertical-align: middle;
  }

  .login-container .login_box {
    position: relative;
    display: block;
    top: 0;
    width: 100%;
    /* height: 530px; */
    max-width: 1000px;
    box-shadow: 0px 4px 22px #efefef;
    background: #fff;
  }

  .login-container .login_box .login_ad {
    width: 482px;
    height: 552px;
    background: url(/images/login_bg_20200603.png) no-repeat;
    background-size: cover;
  }

  .login-container .login_box .login_ad img {
    width: 360px;
    margin: auto;
    height: 200px;
  }

  .login-container .login_box .login_ad span {
    font-family: "Microsoft YaHei";
    display: block;
    text-align: center;
    font-size: 28px;
    letter-spacing: 2px;
    font-weight: bold;
    color: #fff;
  }

  .login-container .login_box .login_type_icon {
    position: absolute;
    top: 0;
    right: 0;
    width: 94px;
    height: 94px;
    overflow: hidden;
    z-index: 10;
  }

  .login-container .login_box .login_type_icon .login_default {
    width: 96px;
    height: 96px;
    background: url(/images/login_default.jpg) no-repeat;
    background-size: cover;
  }

  .login-container .login_box .login_type_icon .login_code {
    width: 96px;
    height: 96px;
    background: url(/images/login_code.jpg) no-repeat;
    background-size: cover;
  }

  .login-container .login_box .login_input {
    position: relative;
    display: inline-block;
    text-align: center;
    width: 508px;
    height: 552px;
    background: #FFF;
    overflow: hidden;
  }

  .login-container .login_box .login-form {
    width: 320px;
    margin: 0 auto;
    margin-top: 75px;
  }

  .login-container .login_box .login-form /deep/ input:-webkit-autofill{
    -webkit-box-shadow:0 0 0 1000px white inset !important;
  }

  .title-container {
    font-size: 22px;
    font-weight: bold;
    padding: 30px 0;
    text-align: left;
  }

  .title-container img {
    margin-top: 38px;
    width: 100%;
    height: auto;
  }

  .login-container .login_box .login-form .login_tel {
    display: block;
    margin-bottom: 24px;
    border: none;
    border-bottom: 1px solid #C0C4CC;
  }

  .login-container .login_box .login-form .login_tel .label {
    display: inline-block;
    text-align: left;
    width: 12%;
    font-size: 18px;
    color: #303133;
    line-height: 26px;
    padding: 0;
    margin: 12px 0;
    float: left;
  }

  .login-container .login_box .login-form .login_tel .input_tel {
    display: inline-block;
    width: 88%;
    margin: 12px auto;
    height: 24px;
    line-height: 24px;
    border-left: 1px #efefef solid;
    float: right;
  }

  .login-container .login_box .login-form .login_tel .input_tel /deep/ input {
    padding: 0 0% 0 4%;
    margin: 0;
    font-size: 18px;
    height: 24px;
    line-height: 24px;
    border: none !important;
  }

  .login-container .login_box .login-form .login_tel /deep/ .el-input__suffix {
    top: -6px;
    right: 0px;
  }

  .login-container .login_box .login-form .login_pwd {
    border: none;
    border-bottom: 1px solid #C0C4CC;
  }

  .login-container .login_box .login-form .login_pwd .el-input /deep/ input {
    padding: 0;
    margin: 0;
    font-size: 18px;
    height: 24px;
    line-height: 24px;
    border: none;
  }

  .login-container .login_box .login-form .login_pwd .show-pwd {
    position: absolute;
    right: 0;
    top: 0;
  }

  .login-container .login_box .login-form .login_pwd /deep/ .el-input__suffix {
    right: 20px;
  }

  /*.login-container .login_box .login-form:hover .login_tel{*/
  /*border-bottom: 1px solid #409EFF;*/
  /*}*/
  /*.login-container .login_box .login-form:active .login_tel{*/
  /*border-bottom: 1px solid #409EFF;*/
  /*}*/
  .login-container .login_box .login-form /deep/ input::-webkit-input-placeholder {
    color: #909399;
    letter-spacing: 1px;
  }

  .login-container .login_box .login-form /deep/ input:focus::-webkit-input-placeholder {
    color: #409EFF;
  }

  .login-container .login_box .login-form .el-form-item__error {
    margin: 2px auto;
  }

  .login-container .login_box .login_keeppwd {
    float: left;
  }

  .login-container .login_box .login_keeppwd .el-checkbox__inner {
    width: 20px;
    height: 20px;
    background: #fff;
  }

  .login-container .login_box .login_keeppwd .el-checkbox__inner::after {
    height: 12px;
    left: 6px;
    border: 2px solid #409EFF;
    border-top: none;
    border-left: none;
  }

  .login-container .login_box .login_keeppwd .el-checkbox__label {
    padding-left: 8px;
    font-size: 16px;
    color: #909399;
  }

  .login-container .login_box .login_forgepwd {
    float: right;
  }

  .login-container .login_box .login_forgepwd span {
    font-size: 16px;
    color: #909399;
  }

  .login-container .login_box .login_code_box {
    position: relative;
    display: inline-block;
    text-align: center;
    width: 582px;
    height: 614px;
    float: right;
    overflow: hidden;
  }

  .login-container .login_box .login_code_box .title {
    display: block;
    font-size: 24px;
    color: #1a1a1a;
    line-height: 33px;
    margin: 100px auto 30px;
  }

  .login-container .login_box .login_code_box span {
    display: block;
    font-size: 16px;
    line-height: 32px;
  }

  .login-container .login_box .login_code_box .code {
    display: inline-block;
    width: 200px;
    height: 200px;
    margin-bottom: 20px;
    overflow: hidden;
    position: relative;
  }

  .login-container .login_box .login_code_box .code .mack {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    background-color: #98989891;
    padding-top: 60px;
  }

  .mack i.el-icon-refresh {
    font-size: 26px
  }

  .login-container .login_box .login_code_box .code .mack span {
    line-height: 100%;
    color: #fff;
    background: #000;
    display: inline-block;
  }

  .login-container .login_box .login_code_box .code img {
    width: 100%;
    height: auto;
  }

  .login-container .login_box .login_code_box .social_soft {
    display: inline-block;
    width: 260px;
    margin: 30px auto;
    padding: 16px 0;
    border-top: 1px #efefef dashed;
  }

  .login-container .login_box .login_code_box .social_soft .title {
    display: inline-block;
    vertical-align: top;
    text-align: left;
    width: 80%;
    margin: 0 auto;
    font-size: 16px;
  }

  .login-container .login_box .login_code_box .social_soft .svg-icon {
    display: inline-block;
    vertical-align: top;
    width: 18%;
    font-size: 36px;
  }

  .login-container .login_box .login_code_box .social_soft .download_app {
    width: 260px;
    margin: 30px auto;
    padding: 16px 0;
    border: 1px red solid;
    background: red;
    border-radius: 8px;
  }

  .login-container .login_box .login_code_box .social_soft .download_app img {
    width: 40px;
  }

  .login-container .login_box button {
    margin: 0 auto 32px;
    padding: 0;
  }

  .login-container .login_box .login_reg {
    display: inline-block;
    overflow: hidden;
  }

  .login-container .login_box .login_reg span {
    font-size: 16px;
    letter-spacing: 1px;
  }

  .footer_copyright {
    text-align: center;
    margin: 20px 0;
  }

  .footer_copyright span {
    display: block;
    text-align: center;
    font-size: 14px;
    line-height: 18px;
    color: #606266;
  }

  .footer_copyright span img {
    display: inline-block;
    vertical-align: top;
    margin-top: 8px;
    padding: 0 20px;
  }

  .login-container::-webkit-scrollbar {
    width: 4px;
    height: 1px;
  }

  .login-container::-webkit-scrollbar-thumb {
    border-radius: 10px;
    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
    background: #535353;
  }

  .login-container::-webkit-scrollbar-track {
    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    background: transparent;
  }

  
.fade-enter {
  opacity: 0;
}
.fade-enter-active {
  transition: opacity 1.2s;
}
.fade-leave-to {
  opacity: 0;
}
.fade-leave-active {
  transition: opacity 1s;
}
</style>
