<template>
  <el-container style="height: 100%">
    <el-header class="header" v-show="flag">
      <div class="logInfo">
        <img :src="'api' + logo" alt="" />
        <h3>{{ header }}</h3>
      </div>
      <!-- 用户 -->
      <div class="userinfo">
        <img :src="userphoto" class="userheadImg" alt="" />{{ username }}
      </div>
      <!-- 标题 -->
      <div class="sysName">
        <h2 v-if="userinfo.user_header">{{ userinfo.user_header }}</h2>
        <h2 v-else>苗情监测应用系统 实时监测作物生长状态</h2>
        <p>
          The application system of seedling condition monitoring monitors the
          crop growth status in real time
        </p>
      </div>
      <span class="header_btn" @click="hCheckFun">[隐藏]</span>
    </el-header>
    <el-header class="header2" v-show="!flag">
      <h3 v-if="userinfo.user_header">{{ userinfo.user_header }}</h3>
      <h3 v-else>苗情监测应用系统</h3>
      <span class="header_btn" @click="hCheckFun">[展开]</span>
    </el-header>
    <el-container style="overflow: auto">
      <el-aside width="200px">
        <el-menu
          :default-active="$route.path"
          :collapse-transition="false"
          class="el-menu-vertical-demo"
          :router="isRouter"
          active-text-color="rgb(0, 0, 0)"
        >
          <el-menu-item index="/index/monitor">
            <i :class="iconObj[20]"></i>
            <span slot="title">苗情应用系统</span>
          </el-menu-item>
          <el-menu-item index="/index/list">
            <i :class="iconObj[22]"></i>
            <span slot="title">设备列表</span>
          </el-menu-item>
          <el-menu-item index="/index/userManger">
            <i :class="iconObj[23]"></i>
            <span slot="title">用户管理</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  data() {
    return {
      isRouter: true,
      iconObj: {
        20: "iconfont icon-jiankong",
        22: "iconfont icon-shebei",
        23: "iconfont icon-xitong",
      },
      flag: true,
      header: "",
      logo: "",
      active: 1,
      userinfo: {},
      username: "",
      userphoto: "",
    };
  },
  created: function () {
    this.getUserInfo();
    this.getuserinfo();
  },
  methods: {
    getUserInfo() {
      this.$axios({
        method: "POST",
        url: "/api/logoheader",
      }).then((res) => {
        this.header = res.data.header;
        this.logo = res.data.logo;
      });
    },
    hCheckFun() {
      this.flag = !this.flag;
    },
    getuserinfo() {
      this.$axios({
        method: "post",
        url: "/api/userinfo_",
      }).then((res) => {
        this.username = res.data.username;
        this.userphoto = res.data.userphoto;
        localStorage.setItem("username", res.data.username); // 0管理员  1用户
      });
      this.$axios({
        method: "get",
        url: "/api/user_detail",
      }).then((res) => {
        this.userinfo = res.data;
        localStorage.setItem("have_type", this.userinfo.have_type); // 0管理员  1用户
        localStorage.setItem("staff", this.userinfo.staff); // 1是admin
      });
    },
  },
};
</script>

<style scoped lang="less">
.header {
  position: relative;
  width: 100%;
  height: 177px !important;
  border-bottom: 2px solid #272b3a;
  background: #397b0c no-repeat center / 100% 100%
    url(../assets/images/monitor/h_bg.jpg);
  .userinfo {
    color: #fff;
    position: absolute;
    top: 10px;
    right: 10px;
    .userheadImg {
      width: 35px;
      height: 35px;
      border-radius: 50%;
      vertical-align: middle;
      margin-right: 6px;
    }
  }
  .sysName {
    color: #295206;
    text-align: center;
    h2 {
      color: #295206;
      font-weight: 800;
      text-shadow: #fff 1px 0 0, #fff 0 1px 0, #fff -1px 0 0, #fff 0 -1px 0;
      font-size: 20px;
    }
    p {
      color: #295206;
      font-weight: 600;
      text-shadow: #fff 1px 0 0, #fff 0 1px 0, #fff -1px 0 0, #fff 0 -1px 0;
      font-size: 14px;
    }
    margin-top: 50px;
  }
  .logInfo {
    color: #fff;
    position: absolute;
    top: 10px;
    left: 20px;
    display: flex;
    flex-direction: row;
    align-items: center;
    img {
      width: auto;
      height: 40px;
    }
    h3 {
      margin: 0;
      margin-left: 20px;
    }
  }
}
.header2 {
  border-bottom: 2px solid #397b0c;
  position: relative;
  background-color: #397b0c;
  color: #fff;
}
.header_btn {
  position: absolute;
  color: #999;
  font-size: 14px;
  right: 20px;
  bottom: 10px;
  cursor: pointer;
}
.header_btn:hover {
  color: #fff;
}

.el-aside {
  background: #f0f0f0;
  i {
    color: #000;
  }
  .is-active {
    span {
      color: #fff;
    }
    background: #5aae22;
    i {
      color: #fff;
    }
  }
  .el-menu-item:focus,
  .el-menu-item:hover {
    i {
      color: #fff;
    }
    color: #fff;
    background: #5aae22;
  }
}
.el-main {
  padding: 0;
}
</style>
