<template>
  <el-row :gutter="40" class="panel-group">
    <el-col :span="6" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper icon-people">
          <svg-icon icon-class="clipboard" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            <!-- 项目 -->
            {{ $t('trials:workbench:label:trialsStats') }}
          </div>
          <div class="card-panel-num">
            <countTo :start-val="0" :end-val="trialCount" :duration="3000" />
          </div>
        </div>
      </div>
    </el-col>

    <el-col :span="6" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper icon-documentation">
          <svg-icon icon-class="documentation" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            <!-- 签署文件 -->
            {{ $t('trials:workbench:label:attachmentsStats') }}
          </div>
          <div class="card-panel-num">
            <countTo :start-val="0" :end-val="signedDocumentsCount" :duration="3000" />
            <span> / </span>
            <countTo :start-val="0" :end-val="documentsCount" :duration="3000" />
          </div>
        </div>
      </div>
    </el-col>

    <el-col :span="6" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper icon-monitor">
          <svg-icon icon-class="monitor" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            <!-- 待办任务 -->
            {{ $t('trials:workbench:label:pendingTasksStats') }}
          </div>
          <div class="card-panel-num">
            <countTo :start-val="0" :end-val="taskCount" :duration="3000" />
          </div>
        </div>
      </div>
    </el-col>

    <el-col :span="6" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper icon-message">
          <svg-icon icon-class="message" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            <!-- 消息 -->
            {{ $t('trials:workbench:label:messagesStats') }}
          </div>
          <div class="card-panel-num">
            <countTo :start-val="0" :end-val="needReadSystemNoticeCount" :duration="3000" />
            <span> / </span>
            <countTo :start-val="0" :end-val="messageCount" :duration="3000" />
          </div>
        </div>
      </div>
    </el-col>

  </el-row>
</template>

<script>
import { getBasicStat } from '@/api/trials'
import countTo from 'vue-count-to'
import store from '@/store'
export default {
  name: 'PanelCount',
  components: { countTo },
  data() {
    return {
      trialCount: 0, // 参与项目数量
      signedDocumentsCount: 0, // 已签署文件数量
      documentsCount: 0, // 文件总数
      taskCount: 0, // 待办任务数量
      messageCount: 0, // 消息数量
      needReadSystemNoticeCount: 0, // 待回复消息数量
      TotalNeedSignSystemDocCount: 0 // 待签署系统数量
    }
  },
  mounted() {
    this.getData()
  },
  methods: {
    getData() {
      getBasicStat().then(async res => {
        this.trialCount = res.Result.TrialCount
        this.signedDocumentsCount = res.Result.HaveSignedSystemDocCount + res.Result.HaveSignedTrialDocCount
        this.documentsCount = res.Result.TotalNeedSignSystemDocCount + res.Result.TotalNeedSignTrialDocCount
        this.TotalNeedSignSystemDocCount = res.Result.WaitSignSystemDocCount
        await store.dispatch('user/setTotalNeedSignSystemDocCount', this.TotalNeedSignSystemDocCount)
        this.taskCount = res.Result.TotalApprovalRequiredCount
        this.messageCount = res.Result.TotalSystemNoticeCount
        this.needReadSystemNoticeCount = res.Result.NeedReadSystemNoticeCount
        this.$emit('getSignSystemDocCount', res.Result.WaitSignSystemDocCount)
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.panel-group {
  margin-top: 10px;

  .card-panel-col {
    margin-bottom: 10px;
  }
  .card-panel {
    // width: 300px;
    height: 100px;
    // 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-people {
        background: #40c9c6;
      }

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

      .icon-monitor {
        background: #f4516c;
      }

      .icon-documentation {
        // background: #34bfa3
        background: #428bca
      }
    }

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

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

    .icon-monitor {
      color: #f4516c;
    }

    .icon-documentation {
      // color: #34bfa3
      color: #428bca;
    }

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

</style>
