<template>
  <div class="logout">
    <loading/>
    <p>跳转中，请稍后...</p>
  </div>
</template>

<script>
  import Loading from '~components/common/loading/Loading.vue'
  export default {
    name: 'agency',
    layout: 'mobile',
    components: {
      Loading
    },
    mounted () {
      this.$nextTick(() => {
        this.agency()
      })
    },
    methods: {
      agency () {
        let param = new FormData()
        param.append('returnURL', this.$route.query.returnURL || '')
        param.append('appId', this.$route.query.appId || '')
        param.append('token', this.$route.query.token || '')
        param.append('baseURL', this.$route.query.baseURL || '')
        param.append('spaceUU', this.$route.query.spaceUU || '')
        param.append('isLoginAll', this.$route.query.isLoginAll || '')
        let config = {
          headers: {'Content-Type': 'multipart/form-data'}
        }
        let url = this.$store.state.option.isMobile ? '/sso/login/mobile/proxy' : '/sso/login/proxy'
        this.$http.post(url, param, config)
          .then(response => {
            if (response.data.success) {
              if (response.data.content.loginUrls) {
                // 遍历登录url循环让各应用登录(需要跨域)
                let param = response.data.content.data
                let a = ''
                for (let n in param) {
                  a += (n + '=' + param[n] + '&')
                }
                for (let i in response.data.content.loginUrls) {
                  this.$jsonp(`${response.data.content.loginUrls[i]}?` + a.substr(0, a.length - 1), function (err, data) {
                    if (err) throw err
                    console.log(data)
                  })
                }
              }
              setTimeout(function () {
                window.location.href = response.data.content.returnUrl || 'http://www.ubtob.com'
              }, 3000)
            }
          })
      }
    }
  }
</script>
<style type="text/scss" lang="scss" scoped>
  .logout{
    p{
      position: fixed;
      left: 0;
      right:0;
      top: 54%;
      z-index: 1000;
      text-align: center;
      font-size: 14px;
      color:#333;
    }
  }
</style>
