<template>
  <div class="mianBox" >
    <van-row class="headerBox">
      运营中心
    </van-row>
    <van-row class="contentBox" v-if="loadingErp">
      <weather alt="天气" />
      <record alt="记录" />
    </van-row>
    <van-row class="mask" v-if="!loadingErp">
      <loadingSZ />
    </van-row>
  </div>
</template>

<script>
import axios from "axios";
import { Toast } from "vant";
import Cookies from "js-cookie";
import { encrypt, encrypt2, decrypt } from "../../utils/jsencrypt";
import weather from "@/components/weather";
import record from "@/components/record";
import loadingSZ from "@/components/loadingSZ";
export default {
  components: {
    weather,
    record,
    loadingSZ
  },
  data() {
    return {
      loadingErp:false
    };
  },
  created() {
    var url = window.location.href;
    if (url.indexOf("token") > 1) {
      //("app进入")
      if (this.getQueryVariable("token")) {
        this.userQuery();
      } else {
        //console.log("app进入")
        Toast(this.getQueryVariable("无token传入！"));
      }
    }else if(Cookies.get("tokenMT")){
      this.userQuery()
    }else{
      this.$router.push({ path: "/login"})
    }
  },
  mounted() {},
  methods: {
    getQueryVariable(variable){//参数获取
      //window.location.search.substring(1);
      var query = window.location.hash.substring(3);
      var vars = query.split("&");
      for (var i=0;i<vars.length;i++) {
        let pair = vars[i].split("=");
        return pair[1];
      }
      return(false);
    },
    //用户查询
    userQuery(){
      let token = undefined
      if(this.getQueryVariable("token")){
        token = this.getQueryVariable("token")
      }else{
        token = Cookies.get("tokenMT")
      }
      axios({//查询信息
        method: 'get',
        url: 'https://smartpark.caih.com/zkxt/api/thirdparty/v1/user/getZkUserByCipher?cipher=' + token,
        timeout: 10000,
      }).then(res =>{
        if(res.data?.data?.id){
          this.loadingErp = true
        }
      }).catch(err =>{
        Cookies.remove("usernameMT");
        Cookies.remove("rememberMeMT");
        Cookies.remove("passwordMT");
        Cookies.remove("userIdMT");
        Cookies.remove("tokenMT");
        Cookies.remove("nonceMT");
        Cookies.remove("timestampMT");
        this.loadingErp = false
        this.userNoAlert(err.response.data.message)
        this.$router.push({ path: "/login"})
      });
    },
    userNoAlert(msg){
      Toast(msg)
    },
  },
};
</script>

<style lang="scss" scoped>
html,
body {
  color: #fff;
}
.mask{
  width:100%;
  height:100%;
  position: fixed;
  z-index: 1;
}
.mianBox {
  height: 100%;
  width: 100%;
  background-color: rgba(0, 0, 0, 0.01);
  padding-top: 40px;
  // box-sizing: border-box;
  position: fixed;
  overflow-y: scroll;
  padding-bottom: 40px;

  .contentBox {
    width: 100%;
    height: auto;
    .record {
      .recordList {
        margin-top: 10px;
        padding: 10px;
        box-sizing: border-box;
        background-color: #fff;
        .listTitle {
          font-size: 14px;
          color: #000;
          span {
            width: 4px;
            height: 14px;
            display: inline-block;
            background-color: #f22e3c;
            margin-right: 4px;
          }
        }
      }
    }
  }
}
.el-table th > .cell {
  font-size: 11px;
}
</style>
<style>
.el-table td,
.el-table th {
  padding: 4px 0 !important;
}
.el-loading-mask {
  background-color: transparent !important;
}

.el-table .cell {
  padding-right: 0;
}
.tableScroll {
  overflow-x: scroll;
}
</style>
