<template>
  <div>
  <el-row :gutter="40" class="panel-group">
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel" @click="handleSetLineChartData('students')">
        <div class="card-panel-icon-wrapper icon-people">
          <svg-icon icon-class="peoples" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            学员总数
          </div>
          <div class="card-panel-num">
            <count-to :start-val="0" :end-val="panelData.students" :duration="2600" class="card-panel-num" />
          </div>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel" @click="handleSetLineChartData('organizations')">
        <div class="card-panel-icon-wrapper icon-message">
          <svg-icon icon-class="education" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">机构</div>
          <div class="card-panel-num">
            <count-to :start-val="0" :end-val="panelData.organizations" :duration="3000" class="card-panel-num" />
          </div>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel" @click="handleSetLineChartData('projects')">
        <div class="card-panel-icon-wrapper icon-money">
          <svg-icon icon-class="component" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">项目总数</div>
          <div class="card-panel-num">
            <count-to :start-val="0" :end-val="panelData.projects" :duration="3200" class="card-panel-num" />
          </div>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel" @click="handleSetLineChartData('coupons')">
        <div class="card-panel-icon-wrapper icon-shopping">
          <svg-icon icon-class="money" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            优惠券发放
          </div>
          <div class="card-panel-num">
            <count-to :start-val="0" :end-val="panelData.coupons" :duration="3600" class="card-panel-num" />
          </div>
        </div>
      </div>
    </el-col>
  </el-row>
  <el-row :gutter="40" class="panel-group">
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel" @click="handleSetLineChartData('projects')">
        <div class="card-panel-icon-wrapper icon-money">
          <svg-icon icon-class="list" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">已发布项目&活动</div>
          <div class="card-panel-num">
            <count-to :start-val="0" :end-val="panelData.projects_active" :duration="3200" class="card-panel-num" />
          </div>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel" @click="handleSetLineChartData('coupons')">
        <div class="card-panel-icon-wrapper icon-banner">
          <svg-icon icon-class="tab" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">轮播图</div>
          <div class="card-panel-num">
            <count-to :start-val="0" :end-val="panelData.banners_active" :duration="3600" class="card-panel-num" />
          </div>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel" @click="handleSetLineChartData('coupons')">
        <div class="card-panel-icon-wrapper icon-video">
          <svg-icon icon-class="star" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">精彩视频</div>
          <div class="card-panel-num">
            <count-to :start-val="0" :end-val="panelData.showcases_active" :duration="3600" class="card-panel-num" />
          </div>
        </div>
      </div>
    </el-col>
  </el-row>
  </div>
</template>

<script>
import CountTo from 'vue-count-to'

export default {
  components: {
    CountTo
  },
  props: {
    panelData: {
      type: Object,
      required: true,
      default: () => {
        return {
          students: 0,
          organizations: 0,
          projects: 0,
          coupons: 0,
          projects_active: 0,
          banners_active: 0,
          showcases_active: 0
        }
      }
    }
  },
  methods: {
    handleSetLineChartData(type) {
      this.$emit('handleSetLineChartData', type)
    }
  }
}
</script>

<style lang="scss" scoped>
.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: 0 4px 20px rgba(0, 0, 0, 0.08);
    border-color: rgba(0, 0, 0, .05);
    border-radius: 12px;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    padding: 0 24px;

    &:hover {
      transform: translateY(-5px);
      box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
      
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
        box-shadow: 0 4px 12px rgba(64, 201, 198, 0.4);
      }

      .icon-message {
        background: #36a3f7;
        box-shadow: 0 4px 12px rgba(54, 163, 247, 0.4);
      }

      .icon-money {
        background: #f4516c;
        box-shadow: 0 4px 12px rgba(244, 81, 108, 0.4);
      }

      .icon-shopping {
        background: #34bfa3;
        box-shadow: 0 4px 12px rgba(52, 191, 163, 0.4);
      }

      .icon-banner {
        background: #ff9800;
        box-shadow: 0 4px 12px rgba(255, 152, 0, 0.4);
      }

      .icon-video {
        background: #9c27b0;
        box-shadow: 0 4px 12px rgba(156, 39, 176, 0.4);
      }
    }

    .icon-people {
      color: #40c9c6;
      background: rgba(64, 201, 198, 0.1);
    }

    .icon-message {
      color: #36a3f7;
      background: rgba(54, 163, 247, 0.1);
    }

    .icon-money {
      color: #f4516c;
      background: rgba(244, 81, 108, 0.1);
    }

    .icon-shopping {
      color: #34bfa3;
      background: rgba(52, 191, 163, 0.1);
    }

    .icon-banner {
      color: #ff9800;
      background: rgba(255, 152, 0, 0.1);
    }

    .icon-video {
      color: #9c27b0;
      background: rgba(156, 39, 176, 0.1);
    }

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

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

    .card-panel-description {
      float: none;
      font-weight: bold;
      margin: 0;
      margin-left: 20px;
      flex: 1;
      text-align: left;

      .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: block;
  }

  .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>
