<template>
  <div>
    <!-- {{ 'code:' + code + ' ,params:' + params + ' ,redirect_uri:' + redirect_uri + 'response:' + JSON.stringify(response2)  }} -->
  </div>
</template>

<script>
import req from "@/request.js";
import utils from "@/utils.js";
import { Notify } from "vant";
export default {
  components: {},
  data() {
    return {
      layout: {},
      gridList: [],
      code: '',
      id:'',
      response2: '',
      redirect_uri: '',
      params: ''
    };
  },
  created() {
    if (sessionStorage.getItem("currentUser")) {
      var redirect_uri = decodeURIComponent(utils.getParameters("redirect"));
      if (redirect_uri) {
        location.href = redirect_uri;
      } else {
        this.$router.push({ path: '/unfinished' })
      }
    }
    const loading = this.$loading({
      lock: true,
      text: "加载中",
      spinner: "el-icon-loading",
      background: "rgba(0, 0, 0, 0.7)"
    });
    let Base64 = require("js-base64").Base64;
    var params = utils.getParameters("params")
    params = decodeURIComponent(params);
    if (params) {
      try {
        params = Base64.decode(params);
      } catch (error) {
        loading.close();
        Notify({ type: "danger", message: "传入的参数params解码错误了：" + error });
        return;
      }
    }

    var code = utils.getParameters("code");
    this.code = code

    var id = utils.getParameters("code");
    this.id = id
    this.params = params


    var redirect = 'laptop-kkottu8t.com:8080/fvue/qywxOauth'
    this.redirect_uri = redirect

    let url = `http://183.230.176.125:8896/sso/weixin?code=${code}`;

    req.get(url).then((response) => {
      this.response2 = response.data
      loading.close();

      if (this.response2) {

        sessionStorage.setItem("currentUser", JSON.stringify(response.data));
        sessionStorage.setItem("token", response.data.token); // 存入一个值
        sessionStorage.setItem("username", response.data.username);
        sessionStorage.setItem("account", response.data.account);
        sessionStorage.setItem("userId", response.data.userId);
        this.$store.dispatch('login/qywxJump', response.data)

        this.$router.push({
          path: '/meetingDetail2',
          query: {
            id:this.id,
          }
        })
      }

    });
    // this.$router.push({path:'/unfinished'})
    // this.proxyLogin(code, redirect, loading, params);
  },
  methods: {
    proxyLogin(code, redirect_uri, loading, params) {
      this.$router.push({ path: '/unfinished' })
      req.get(url).then((response) => {
        this.response2 = response.data
        loading.close();

        if (response) {

          sessionStorage.setItem("currentUser", JSON.stringify(response.data));
          sessionStorage.setItem("token", response.data.token); // 存入一个值
          sessionStorage.setItem("username", response.data.username);
          sessionStorage.setItem("account", response.data.account);
          sessionStorage.setItem("userId", response.data.userId);
          this.$router.push({ path: '/unfinished' })
        }

      });
    },
    // parseParams(params){
    //   let paramsJson = JSON.parse(params||"{}");
    //   //审批的消息
    //   if(paramsJson.templateType ==='bpmnapproval'){
    //     let url = `/task/${paramsJson.taskId}/0`;
    //     this.$router.push({path:url});
    //   }else{
    //     this.$router.push({path:'/home'})
    //   }
    // }
  },

};
</script>
