<template>
  <div class="app">
    <div class="m-right-block">
      <div class="right-block-bd">
        <div class="panel-tit mt30 clear">
          <p class="fl">最近学习课程</p>
        </div>
        <div class="clear mt20">
          <div class="m-history-course fl" v-for="item in list" @click="gotoPlay(item.courseId)"
            :key="item.courseId" style="width:300px; margin-left:8px;cursor:pointer">
            <div class="history-course-bd" style="width:260px">
              <p class="tit ng-binding">
                {{item.name}}
              </p>
              <div class="info">
                需要学时:
                <span class="t-b">{{item.getXs/10}}/{{item.totalXs/10}}</span>
              </div>

              <div class="info">
                证书编号:
                <span class="t-b">{{item.rzCode}}</span>
              </div>
              <div class="info">
                学习时间:
                <span>{{item.startDate}} 到 {{item.endDate}}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

  </div>

</template>

<script>
  import {
    httpServer
  } from "@/components/httpServer/httpServer.js";
  export default {
    name: "Index",
    data() {
      return {
        page: 1,
        size: 6,
        total: 1,
        media: {},
        list: [],
      };
    },
    beforeMount() {
      this.getData()
    },
    methods: {
      gotoPlay(courseId) {
        this.$router.push({name:'play', params:{courseId}})
      },
      gotoPage(route) {
        this.$router.push(route);
      },
      getPercent(item) {
        if (item.getXs > item.totalXs) {
          return 100
        } else {
          return parseInt(item.getXs * 10000 / item.totalXs) / 100
        }
      },
      getData() {
        let {
          page,
          size
        } = this
        let param = {
          from: (page - 1) * size,
          isFree: 1,
          size
        }
        httpServer('course.GetHistoryCourseList', param).then(({
          data,
          code
        }) => {
          this.list = data.list || 0;
          this.total = data.total || 0;
        })
      }
    }
  };
</script>

<style lang="less">
  @import "./index.less";
  @import "../../../assets/css/course.css";
</style>
