<template>
  <div class="g-app">
    <div class="m-loading">
      <p v-if="status == 'success'">登录成功</p>
      <p v-else-if="status == 'failed'">登录失败</p>
    </div>
  </div>
</template>

<script>
import { requestPost } from "@/js/dai/request";
import { toLoginPage } from "@/utils/yantai-transit";
import getQueryPara from "dai-js/modules/getQueryPara";

export default {
  data() {
    return {
      status: "ing",
    };
  },

  components: {},
  computed: {},

  async mounted() {
    let code = getQueryPara("code");
    console.log("--------------code" + code);
    const loading = this.$loading({
      lock: true,
      text: "登录中……",
      spinner: "el-icon-loading",
      customClass: "u-loading-yantai-login-transit",
      background: "rgba(255, 255, 255, 0.7)",
    });
    if (code) {
      await this.login(code);
      loading.close();
    } else {
      toLoginPage();
    }
  },

  methods: {
    //根据社区id获取小区列表
    async login(client_code) {
      const url = "/auth/thirdlogin/sso-govlogin-yantai/" + client_code;

      let params = {};

      const { data, code, msg } = await requestPost(url, params);

      if (code === 0) {
        this.status = "success";
        localStorage.setItem("customerId", data.customerId);
        localStorage.setItem("userType", "work");
        //localStorage.setItem("showHeader", "1");
        localStorage.setItem("token", data.token);
        this.$router.replace({ name: "index" });
      } else {
        this.status = "failed";
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.m-loading {
  text-align: center;
  margin-top: 10vh;
  line-height: 100px;
  font-size: 50px;
  color: rgb(62, 142, 247);
}
</style>

<style lang="scss">
.u-loading-yantai-login-transit {
  margin-top: -140px;
  //   transform: translateY(-100px);
  .el-loading-spinner {
    .el-loading-text,
    .el-icon-loading {
      line-height: 60px;
      font-size: 30px;
      color: rgb(62, 142, 247);
    }
    .el-icon-loading {
      font-size: 40px;
    }
  }
}
</style>
