

<script>
import { getCodeImg } from "@/api/login";
import Cookies from "js-cookie";
import { encrypt, decrypt } from '@/utils/jsencrypt'

export default {
  name: "Login",
  data() {
    return {
      codeUrl: "",
      cookiePassword: "",
      gwToken:"",
      loginForm: {
        username: "demo",
        password: "123456",
        rememberMe: false,
        code: "",
        uuid: ""
      },
      loginRules: {

      },
      loading: false,
      redirect: undefined
    };
  },
  watch: {
    $route: {
      handler: function(route) {
        this.redirect = route.query && route.query.redirect;
      },
      immediate: true
    }
  },
  created() {
     this.getssourl();
    // this.getCookie();
    // this.getCode();
  },
  methods: {
     getssourl(){
      debugger
      var ssa = window.location.host
      // var ssa = 'scm.jxhh.com'
      let data = {
        type: 2,
        site_type: 7,
        domain:ssa
      }
       this.$store.dispatch('getssourl', data)
            .then((res) => {
             if(res.code==1){
               this.ssourl = res.data.channel_site[0].domain
               this.tiaozuan()
             }
            })
            .catch(() => {
             
            })
    },
    tiaozuan(){
      console.log(this.gwToken)
      if(this.gwToken == "" || this.gwToken ==null){

        var ssa = window.location.host
        var ht = document.location.protocol 
        var that = this
        setTimeout(function (){
         if(ssa =='localhost:1024'){
           window.location.href=ht+'//'+that.ssourl+'/login.html?redirect='+ht+'//'+ssa+'/platformlogin'
         }else{
          window.location.href=ht+'//'+that.ssourl+'/login.html?redirect='+ht+'//'+ssa+'/platformlogin'
         }
        }, 1000)
       }
    },
    // getCode() {
    //   getCodeImg().then(res => {
    //     this.codeUrl = res.data.base64stringC;
    //     this.loginForm.uuid = res.data.idKeyC;
    //   });
    // },
    // getCookie() {
    //   this.gwToken=this.$store.state.token
    //   if(this.gwToken == null){
    //     this.tiaozuan();
    //   }
    //   console.log("this.gwToken",this.gwToken)
    // },
    // handleLogin() {
    //   this.$refs.loginForm.validate(valid => {
    //     if (valid) {

    //       this.loading = true;
    //       if (this.loginForm.rememberMe) {
    //         Cookies.set("username", this.loginForm.username, { expires: 30 });
    //         Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
    //         Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
    //       } else {
    //         Cookies.remove("username");
    //         Cookies.remove("password");
    //         Cookies.remove('rememberMe');
    //       }
    //       this.$store
    //         .dispatch("Login", this.loginForm)
    //         .then(() => {
    //           this.$router.push({ path: this.redirect || "/" });
    //         })
    //         .catch(() => {
    //           this.loading = false;
    //           this.getCode();
    //         });
    //     }
    //   });
    // }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss">
.login {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  background-image: url("../assets/image/login-background.jpg");
  background-size: cover;
}
.title {
  margin: 0px auto 30px auto;
  text-align: center;
  color: #707070;
}

.login-form {
  border-radius: 6px;
  background: #ffffff;
  width: 400px;
  padding: 25px 25px 5px 25px;
  .el-input {
    height: 38px;
    input {
      height: 38px;
    }
  }
  .input-icon {
    height: 39px;
    width: 14px;
    margin-left: 2px;
  }
}
.login-tip {
  font-size: 13px;
  text-align: center;
  color: #bfbfbf;
}
.login-code {
  width: 33%;
  height: 38px;
  float: right;
  img {
    cursor: pointer;
    vertical-align: middle;
    width:120px;
  }
}
.el-login-footer {
  height: 40px;
  line-height: 40px;
  position: fixed;
  bottom: 0;
  width: 100%;
  text-align: center;
  color: #fff;
  font-family: Arial;
  font-size: 12px;
  letter-spacing: 1px;
}
</style>
