<template>
    <div class="course-analysis-wrap">
      <div v-for="(item , index) in cardData" :key="index" class="">
        <el-card class="box-card">
          <div slot="header" class="title">
            <span class="weight">{{ item.title }}</span>
          </div>
          <div class="box-content">
            <span class="weight">{{ item.num }} </span> {{ item.unit }}
          </div>
        </el-card>
       </div>
      <el-table
        :data="tableData"
        class="course-table">
        <el-table-column prop="name" label="课程名" align="center">
        </el-table-column>
        <el-table-column prop="courseTime" label="课程时长" align="center">
        </el-table-column>
        <el-table-column prop="personTime" label="人均学习时长" align="center">
        </el-table-column>
        <el-table-column prop="joinNum" label="参与培训人数" align="center">
        </el-table-column>
        <el-table-column prop="completeNum" label="完成培训人数" align="center">
        </el-table-column>
        <el-table-column fixed="right" label="操作" min-width="50" align="center">
          <template slot-scope="scope">
            <el-button
              @click="checkName(scope.row)"
              type="primary"
              size="small"
            >查看名单</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="formInline.pageNo"
          :page-sizes="[10, 30, 50, 100]"
          :page-size="formInline.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="totalRows"
        ></el-pagination>
      </div>
    </div>
</template>
<script>
import { create } from "domain";
import { openLoading, closeLoading } from "../../utils/utils";
let vm = null;
export default {
  props: {
    formInline: {
      type: Object
    },
    activeName: {
      type: String
    }
  },
  data() {
    return {
      cardData: [],
      tableData: [],
      totalRows: 0,
    }
  },
  created() {
    vm = this;
    this.getCardData();
    this.search();
  },
  mounted: function() {
    this.$on('search',()=>{
      console.log(this.formInline);
      this.getCardData();
      this.search();
    })
  },
  methods: {
    getCardData() {
      this.cardData = [
        {
          title: '项目所有课程数',
          num: 9,
          unit: '门课程',
        },{
          title: '项目所有课程总时长',
          num: 500,
          unit: '分钟',
        },{
          title: '项目人均学习时长',
          num: 265,
          unit: '分钟',
        }
      ];
    },
    search() {
      this.tableData = [{
        id: 1,
        name: '科学诊治高血压',
        courseTime: '120分钟',
        personTime: '90分钟',
        joinNum: '9892',
        completeNum: '5992',
      },{
        id: 2,
        name: '科学诊心脏病',
        courseTime: '120分钟',
        personTime: '90分钟',
        joinNum: '9892',
        completeNum: '5992',
      }];
    },
    checkName(data) {
      this.$router.push("course-training");
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.formInline.pageSize = val;
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.formInline.pageNo = val;
      this.search();
    }, 
  },
}
</script>
<style lang="scss">
.course-analysis-wrap {
    background: #fff;
    padding: 10px;
    .weight {
      font-weight: bold;
    }
    .title:after {
      clear: both
    }
    .box-card {
      width: 240px;
      margin-right: 30px;
      float: left;
      .box-content {
         text-align: center;
         height: 40px;
      }
    }
    .course-table {
      top: 20px;
    }
}
</style>