<template>
</template>
<script>
  import { Notification } from 'element-ui';
  import { getShopInf } from '@/api/module/entry';
  import request from '@/utils/request'
  export default {
    name: "Platformlogin",
    created() {
      this.gotosso();
    },
    methods: {
      gotosso() {
        var ticket = this.$route.query.ticket;
        this.$store.dispatch('Login', {"ticket": ticket}).then((res) => {
          debugger
          if (res.token != "") {
            // 获取客户是否有审核信息
            getShopInf().then(res => {
              if(res.code === 1) {
                //debugger
                switch(res.data.state) {
                  case 0:
                    switch(res.data.status){
                      case(0):
                        this.$router.push({path: '/process'});
                        break;
                      case(1):
                        this.$router.push({path: '/fillBrandInf'});
                        break;
                      case(2):
                        this.$router.push({path: '/fillShopInf',});
                        break;
                    }
                    break;
                  case 1: // 审核成功，要跳转到首页
                    this.$router.push({path: '/home/index'});
                    break;
                  case 2: // 审核中
                    this.$router.push({path: '/reviewing'});
                    break;
                  case 3: // 审核失败
                    let msg = res.data.Apply.content;
                    this.$router.push({
                      name: 'reviewFail',
                      params: { msg: msg }
                    });
                    break;
                }
              }else {
                if(res && res.msg) {
                  Notification.error({
                    title: '提示：',
                    message: res.msg
                  })
                }else {
                  Notification.error({
                    title: '提示：',
                    message: '刷新浏览器后，再次登录，若仍不行，请联系我们！'
                  })
                }
              }
            });

          } else {
            this.$store.dispatch('Statistic')
            this.$store.dispatch('FedLogOut')
            var ssa = window.location.host;
            setTimeout(function () {
              if (ssa == 'localhost:1024') {
                window.location.href = 'http://sso.jxhh.com/logout?redirect=http://' + ssa + '/login'
              } else {
                window.location.href = 'http://sso.jxhh.com/logout?redirect=http://' + ssa + '/login'
              }
            }, 1000)
          }
          this.loading = false
        })
          .catch(() => {
            this.$store.dispatch('FedLogOut')
            var ssa = window.location.host
            setTimeout(function () {
              if (ssa == 'localhost:1024') {
                window.location.href = 'http://sso.jxhh.com/logout?redirect=http://' + ssa + '/login'
              } else {
                window.location.href = 'http://sso.jxhh.com/logout?redirect=http://' + ssa + '/login'
              }
            }, 1000)
            this.loading = false
          })
      },
    }
  };

</script>
