<template>
  <div class="app-container home">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span style="font-size: 18px; font-weight: bold;">洪水知识库系统</span>
      </div>
      
      <!-- 统计数据展示 -->
      <el-row :gutter="40" class="panel-group" v-loading="loading">
        <el-col :xs="24" :sm="8" :lg="8" class="card-panel-col">
          <div class="card-panel" @click="goToKnowledgeBase">
            <div class="card-panel-icon-wrapper icon-knowledge">
              <svg-icon icon-class="documentation" class-name="card-panel-icon" />
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">
                知识库总数
              </div>
              <count-to :start-val="0" :end-val="statistics.knowledgeBaseCount" :duration="2600" class="card-panel-num" />
            </div>
          </div>
        </el-col>
        <el-col :xs="24" :sm="8" :lg="8" class="card-panel-col">
          <div class="card-panel" @click="goToEmergencyPlan">
            <div class="card-panel-icon-wrapper icon-emergency">
              <svg-icon icon-class="guide" class-name="card-panel-icon" />
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">
                应急预案总数
              </div>
              <count-to :start-val="0" :end-val="statistics.emergencyPlanCount" :duration="3000" class="card-panel-num" />
            </div>
          </div>
        </el-col>
        <el-col :xs="24" :sm="8" :lg="8" class="card-panel-col">
          <div class="card-panel" @click="goToCase">
            <div class="card-panel-icon-wrapper icon-case">
              <svg-icon icon-class="list" class-name="card-panel-icon" />
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">
                案例库总数
              </div>
              <count-to :start-val="0" :end-val="statistics.caseCount" :duration="3200" class="card-panel-num" />
            </div>
          </div>
        </el-col>
      </el-row>
    </el-card>
  </div>
</template>

<script>
import { getStatistics } from "@/api/flood/statistics";
import CountTo from 'vue-count-to'

export default {
  name: "Index",
  components: {
    CountTo
  },
  data() {
    return {
      loading: false,
      statistics: {
        knowledgeBaseCount: 0,
        emergencyPlanCount: 0,
        caseCount: 0
      }
    };
  },
  mounted() {
    this.loadStatistics();
  },
  methods: {
    /** 加载统计数据 */
    loadStatistics() {
      this.loading = true;
      getStatistics().then(response => {
        if (response.code === 200) {
          this.statistics = response.data;
        }
        this.loading = false;
      }).catch(() => {
        this.loading = false;
      });
    },
    /** 跳转到知识库管理 */
    goToKnowledgeBase() {
      this.$router.push('/flood/knowledge');
    },
    /** 跳转到应急预案管理 */
    goToEmergencyPlan() {
      this.$router.push('/flood/emergency');
    },
    /** 跳转到案例库管理 */
    goToCase() {
      this.$router.push('/flood/case');
    },
    goTarget(href) {
      window.open(href, "_blank")
    }
  }
}
</script>

<style scoped lang="scss">
.home {
  .box-card {
    margin: 20px;
  }

  .panel-group {
    margin-top: 18px;

    .card-panel-col {
      margin-bottom: 32px;
    }

    .card-panel {
      height: 108px;
      cursor: pointer;
      font-size: 12px;
      position: relative;
      overflow: hidden;
      color: #666;
      background: #fff;
      box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
      border-color: rgba(0, 0, 0, .05);

      &:hover {
        .card-panel-icon-wrapper {
          color: #fff;
        }

        .icon-knowledge {
          background: #40c9c6;
        }

        .icon-emergency {
          background: #36a3f7;
        }

        .icon-case {
          background: #f4516c;
        }
      }

      .icon-knowledge {
        color: #40c9c6;
      }

      .icon-emergency {
        color: #36a3f7;
      }

      .icon-case {
        color: #f4516c;
      }

      .card-panel-icon-wrapper {
        float: left;
        margin: 14px 0 0 14px;
        padding: 16px;
        transition: all 0.38s ease-out;
        border-radius: 6px;
      }

      .card-panel-icon {
        float: left;
        font-size: 48px;
      }

      .card-panel-description {
        float: right;
        font-weight: bold;
        margin: 26px;
        margin-left: 0px;

        .card-panel-text {
          line-height: 18px;
          color: rgba(0, 0, 0, 0.45);
          font-size: 16px;
          margin-bottom: 12px;
        }

        .card-panel-num {
          font-size: 20px;
        }
      }
    }
  }

  @media (max-width:550px) {
    .card-panel-description {
      display: none;
    }

    .card-panel-icon-wrapper {
      float: none !important;
      width: 100%;
      height: 100%;
      margin: 0 !important;

      .svg-icon {
        display: block;
        margin: 14px auto !important;
        float: none !important;
      }
    }
  }
}
</style>
