<template>
  <div class="app-container home">
      <el-row>
      <el-col :sm="24" :lg="12" style="padding-left: 50px">
        <el-row>
          <el-col :span="10">
            <h2>XWTC-DCS</h2>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
        <h3>欢迎！ <strong>{{ user.userId }}</strong></h3>
          </el-col>
          <el-col :span="18">
        <h3>所在单元： <strong>{{deptName}}</strong></h3>
          </el-col>
          <!-- <el-col :span="6">
            <h4>后端技术</h4>
            <ul>
              <li>SpringBoot</li>
              <li>Spring Security</li>
              <li>JWT</li>
              <li>MyBatis</li>
              <li>Druid</li>
              <li>Fastjson</li>
              <li>...</li>
            </ul>
          </el-col>
          <el-col :span="6">
            <h4>前端技术</h4>
            <ul>
              <li>Vue</li>
              <li>Vuex</li>
              <li>Element-ui</li>
              <li>Axios</li>
              <li>Sass</li>
              <li>Quill</li>
              <li>...</li>
            </ul>
          </el-col> -->
        </el-row>
        <el-row>
          <el-col :span="25">
        <h3>当前地区：<strong>{{location}}</strong><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{weather}}</strong></h3>
        <h3 v-if="SideBarFlag" style="color:red"><strong>请先前往右上角个人中心修改初始密码，然后重新登陆！</strong></h3>
          </el-col>
        </el-row>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { getUserProfile } from "@/api/system/user";
import Cookies from "js-cookie";
import { encrypt, decrypt } from '@/utils/jsencrypt'
export default {
  name: "Index",
  data() {
    return {
      // 版本号
      version: "3.8.1",
      user: {},
      deptName:"",
      location:"",
      weather:"",
      SideBarFlag:false
    };
  },
  created() {
    this.getUser();
    this.isSideBar();
  },
  methods: {
    isSideBar(){
      if(decrypt(Cookies.get("password")) == "111111"){
        this.SideBarFlag = true;
      }
    },
    getUser() {
      getUserProfile().then(response => {
        this.user = response.data;
        this.deptName = this.user.dept.deptName;
        Cookies.set("username", this.user.userId, { expires: 30 });
        Cookies.set("unitid", this.user.deptId, { expires: 30 });
        this.location = locationInfo["result"]["ad_info"]["nation"]+""+locationInfo["result"]["ad_info"]["province"] + " " +locationInfo["result"]["ad_info"]["city"] +" "+ locationInfo["result"]["ad_info"]["district"];
        if(locationInfo["result"]["ad_info"]["city"] != undefined && locationInfo["result"]["ad_info"]["city"] != ""){
          this.weather = "天气加载中...";
        }else{
          this.weather = "天气加载失败";
        }
        this.$axios.get('https://www.mxnzp.com/api/weather/current/'+locationInfo["result"]["ad_info"]["city"]+'?app_id=8srpsmnqoiqfmqby&app_secret=b05VZEhCbUR3MERQandqcGdzcmZLdz09').then(res => {
                this.weather = "气温：" + res.data.data.temp + "       " + res.data.data.weather  + "       " + res.data.data.windDirection + "风  " + "   " + res.data.data.windPower;
                })
        // this.roleGroup = response.roleGroup;
        // this.postGroup = response.postGroup;
      });
    },
    goTarget(href) {
      window.open(href, "_blank");
    }
  }
};
</script>

<style scoped lang="scss">
.home {
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }
  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }
  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }
}
</style>

