<template>
  <div :class="classObj" class="app-wrapper">
    <div class="top-head-bar">
      <div class="top-head-bar__logo">
        环境监测中心
      </div>

      <ul>
        <li class="li-active">工作台</li>
        <li>1</li>
        <li>2</li>
        <li>3</li>
      </ul>

      <div class="top-head-bar__user">
        <el-dropdown class="avatar-container" trigger="click">
          <div class="avatar-wrapper">
            <img src="../assets/face.jpg" class="user-avatar">
            <i class="el-icon-caret-bottom" />
          </div>
          <el-dropdown-menu slot="dropdown" class="user-dropdown">
            <router-link to="/">
              <el-dropdown-item>
                系统首页
              </el-dropdown-item>
            </router-link>
            <el-dropdown-item divided>
              <span style="display:block;">退出</span>
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </div>
    <div v-if="device==='mobile'&&sidebar.opened" class="drawer-bg" @click="handleClickOutside" />

    <template v-if="$route.path === '/worker'">
      <el-scrollbar style="margin-top: 50px;">
        <div class="worker-container">
          <div class="card" v-for="i in 10">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>卡片名称</span>
                <el-button style="float: right; padding: 3px 0" type="text">操作按钮</el-button>
              </div>
              <div v-for="o in 4" :key="o" class="text item">
                {{'列表内容 ' + o }}
              </div>
            </el-card>
          </div>
        </div>
      </el-scrollbar>
    </template>
    <template v-else>
      <sidebar class="sidebar-container" />
      <div class="main-container">
        <div :class="{'fixed-header':fixedHeader}" v-if="false">
          <navbar />
        </div>
        <el-scrollbar style="height: 100%">
          <app-main />
        </el-scrollbar>
      </div>
    </template>
  </div>
</template>

<script>
  import {
    Navbar,
    Sidebar,
    AppMain
  } from './components'
  import ResizeMixin from './mixin/ResizeHandler'

  export default {
    name: 'Layout',
    components: {
      Navbar,
      Sidebar,
      AppMain
    },
    mixins: [ResizeMixin],
    data(){
      return {
        active:'1'
      }
    },
    computed: {
      sidebar() {
        return this.$store.state.app.sidebar
      },
      device() {
        return this.$store.state.app.device
      },
      fixedHeader() {
        return this.$store.state.settings.fixedHeader
      },
      classObj() {
        return {
          hideSidebar: !this.sidebar.opened,
          openSidebar: this.sidebar.opened,
          withoutAnimation: this.sidebar.withoutAnimation,
          mobile: this.device === 'mobile'
        }
      }
    },
    methods: {
      handleClickOutside() {
        this.$store.dispatch('app/closeSideBar', {
          withoutAnimation: false
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  @import "~@/styles/mixin.scss";
  @import "~@/styles/variables.scss";

  .app-wrapper {
    @include clearfix;
    position: relative;
    height: 100%;
    width: 100%;

    &.mobile.openSidebar {
      position: fixed;
      top: 0;
    }
  }

  .top-head-bar{
    background: #338DE3FF;
    height: 50px;
    filter: drop-shadow(0 1px 1px #49a0f3);
    display: grid;
    grid-template-columns: auto 2fr 6fr .5fr 1fr;
    grid-template-rows: auto;
    grid-template-areas:
      "logo . menu . user";

    z-index: 9999;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;

    &__logo{
      color: #fff;
      font-size: 20px;
      line-height: 50px;
      font-weight: 600;
      grid-area:logo;

      padding:0 20px;
    }

    &__user{
      grid-area: user;
    }

    ul{
      grid-area:menu;
      height: 100%;
      display: flex;
      justify-self: flex-end;
      align-items: flex-end;

      li{
        color:#fff;
        height: 40px;
        line-height: 40px;
        list-style: none;
        transition: all 300ms ease-out;
        border-top-right-radius: 6px;
        border-top-left-radius: 6px;

        padding: 0 20px;
        position: relative;

        &::after{
          content:"";
          background: #338DE3FF;
          height: 3px;
          width: 0;
          border-radius: 1px;
          transition: all 300ms ease-out;

          position: absolute;
          left: 6px;
          bottom: 2px;
        }
        &+li{
          margin-left: 20px;
        }
        &:hover{
          background: #fff;
          color:rgb(100,100,100);

          &::after{
            width: calc(100% - 12px);
          }
        }
      }
      .li-active{
        background: #fff;
        color:rgb(100,100,100);

        &::after{
          width: calc(100% - 12px);
        }
      }
    }
  }
  .drawer-bg {
    background: #000;
    opacity: 0.3;
    width: 100%;
    top: 0;
    height: 100%;
    position: absolute;
    z-index: 999;
  }

  .fixed-header {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 9;
    width: calc(100% - #{$sideBarWidth});
    transition: width 0.28s;
  }

  .hideSidebar .fixed-header {
    width: calc(100% - 54px)
  }

  .mobile .fixed-header {
    width: 100%;
  }

  .avatar-container {
    margin-right: 30px;

    .avatar-wrapper {
      margin-top: 5px;
      position: relative;

      .user-avatar {
        cursor: pointer;
        width: 40px;
        height: 40px;
        border-radius: 10px;
      }

      .el-icon-caret-bottom {
        cursor: pointer;
        position: absolute;
        right: -20px;
        top: 25px;
        font-size: 12px;
      }
    }
  }

  .worker-container{
    display: flex;
    align-content: flex-start;
    flex-wrap: wrap;
  }
</style>
