<template>
  <div class="app-container">
  </div>
</template>

<script>
import {Dialog} from "vant";
import Cookies from "js-cookie";
const TEST = 0;

export default {
  name: "ChungengFarmerSSOLogin",
  data() {
    return {
    };
  },
  created() {
    this.Login();
  },
  methods: {
    GetToken() {
      if(TEST)
      {
        if(!this.$route.query.s)
          return this.$route.query.s;
        let name = '6a4634036f90c1985122c4919d8ecb99';
        let idcard = 'e49446695d1e82935bbc0cc7e440a8f739f2c015dc029dccb15380b896e7f71b';
        // idcard = '8feee543fdf8c9cdca7928c9b501908b0b353515cbd0da854519651dafea96c8';
        // name = '6e067f6d57682232cc32096e86487c5e';
        let ts = '1234567890123';
        return name + '#' + idcard + '#' + ts;
      }
      else
        return this.$route.query.s;
    },
    ShowToast(content, title) {
      return Dialog.alert({
        title: title,
        message: content,
        theme: 'round-button',
      });
    },
    Login() {
      let code = this.GetToken();
      if(!code)
      {
        this.ShowToast('请从春耕App进入登录').then(() => {
          history.back();
        });
        return false;
      }
      Cookies.set('bookId', '', { expires: 1 });
      this.$store.dispatch("ChungengFarmerLogin", {code})
        .then((data) => {
          Cookies.set('deptId', data.deptId, { expires: 30 });
          this.$router.push({path:'/sunVillage_info/index_code_rights'});
        })
        .catch((error) => {
          this.ShowToast(error || '春耕App农户登录失败').then(() => {
            history.back();
          });
        });
    },
  },
};
</script>

<style scoped lang="scss">
</style>
