<template>
  <div>
    <el-row>
      <el-col class="sub-system control-system">
        <div class="icon-subsystem">
          <img src="@/assets/dashboard_images/icon-control.png" @click="changeSubSystem('ctrl')">
          <div><a @click="changeSubSystem('ctrl')">综合控制室</a></div>
        </div>
      </el-col>
      <el-col class="sub-system door-system">
        <div class="icon-subsystem">
          <img src="@/assets/dashboard_images/icon-door.png" @click="changeSubSystem('door')">
          <div><a @click="changeSubSystem('door')">营门管理</a></div>
        </div>
      </el-col>
      <el-col class="sub-system defence-system">
        <div class="icon-subsystem">
          <img src="@/assets/dashboard_images/icon-defence.png" @click="changeSubSystem('fence')">
          <div><a @click="changeSubSystem('fence')">周界防卫</a></div>
        </div>
      </el-col>
      <el-col class="sub-system region-system">
        <div class="icon-subsystem">
          <img src="@/assets/dashboard_images/icon-region.png" @click="changeSubSystem('region')">
          <div><a @click="changeSubSystem('region')">全域监控</a></div>
        </div>
      </el-col>
      <el-col class="sub-system key-system">
        <div class="icon-subsystem">
          <img src="@/assets/dashboard_images/icon-key.png" @click="changeSubSystem('key')">
          <div><a @click="changeSubSystem('key')">重点区域管控</a></div>
        </div>
      </el-col>
    </el-row>

    <div class="logo-title">
      <img src="@/assets/dashboard_images/icon-title.png" height="120">
      <div>
        <div class="title">
          天津海图营区
        </div>
        <div class="sub-title">
          综合安防集成管理平台
        </div>
      </div>
    </div>

    <div class="welcome">
      <img src="@/assets/dashboard_images/setting-logo.png" height="20px" style="margin-right: 20px;" @click="changeSubSystem('sys')">
      <img src="@/assets/dashboard_images/exit-logo.png" height="20px" @click="logout">
    </div>
  </div>
</template>

<script>
export default {
  name: 'Portal',
  data() {
    return {
      name: this.$store.getters.name
    }
  },
  computed: {
    systems() {
      return this.$store.getters.systems
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    logout() {
      this.$store.dispatch('LogOut').then(() => {
        location.reload() // 为了重新实例化vue-router对象 避免bug
      })
    },
    fetchData() {
      this.loading = true
      this.$store.dispatch('GetSystems').then(() => {
        this.loading = false
        console.log('获取子系统成功')
      })
    },
    changeSubSystem(code) {
      const system = this.systems.filter(subsys => {
        return subsys.code === code
      })
      if (typeof system !== 'undefined' && system.length > 0) {
        this.$store.commit('SET_CHANGEFLAG', '1')
        this.$store.commit('SET_SYSTEM', system[0])
        this.$store.dispatch('tagsView/delAllViews', true).then(({ visitedViews }) => {
          this.$router.replace(system[0].url)
        })
      }
    }
  }
}
</script>

<style scoped>
  .sub-system {
    width: 20%;
    height: 100vh;
    border: 2px solid #3a8ee6;
    font-size: 24px;
    color: #F5F7FA;
    text-align: center;
    text-shadow: 1px 1px 2px black;
  }

  .control-system {
    background: url("../../assets/dashboard_images/bg-control.jpg") -225px;
    background-size: cover;
  }

  .door-system {
    background: url("../../assets/dashboard_images/bg-door.jpg") center;
    background-size: cover;
  }

  .defence-system {
    background: url("../../assets/dashboard_images/bg-defence.jpg") -225px;
    background-size: cover;
  }

  .region-system {
    background: url("../../assets/dashboard_images/bg-region.jpg") -225px;
    background-size: cover;
  }

  .key-system {
    background: url("../../assets/dashboard_images/bg-key.jpg") -225px;
    background-size: cover;
  }

  .icon-subsystem img {
    padding: 10px;
    margin-top: 50vh;
    margin-bottom: 20px;
    border-radius: 50%;
    background-color: #014886;
    border: 2px solid #00ffff;
    cursor: pointer;
  }

  .logo-title {
    position: absolute;
    width: 420px;
    left: calc(50vw - 210px);
    top: 15vh;
  }

  .welcome {
    position: absolute;
    right: 5vw;
    top: 30px;
    padding-left: 10px;
    cursor: pointer;
  }

  .welcome img {
    filter: drop-shadow(5px 5px 5px rgba(0, 0 , 0, 0.75));
  }

  .title {
    position: absolute;
    top: 15px;
    left: 140px;
    font-size: 40px;
    color: #F5F7FA;
    text-shadow: 2px 2px 2px black;
    display: inline-block;
  }

  .sub-title {
    position: absolute;
    top: 75px;
    left: 140px;
    font-size: 28px;
    color: #F5F7FA;
    text-shadow: 2px 2px 2px black;
    display: inline-block;
  }
</style>
