<template>
  <ks-page-scroll-container
    :page="page"
    :pagination="pagination"
    :page-count="pageCount"
    @page-change="getMyCourseList"
  >
    <div class="my-exam">
      <router-link class="my-exam__a" to="/user/MyClassroom">我的班级</router-link>
      <router-link class="my-exam__aa" to="/user/MyCourse">我的课程</router-link>
      <router-link class="my-exam__a" to="/user/MyExam">练习中心</router-link>
    </div>
    <ks-box :title="'全部课程(' + len + ')'">
      <div class="mybox__item" v-for="(item, index) in list" :key="index">
        <div class="mybox-img">
          <!-- <img :src="item.photourl"> -->
          <a :href="item.view_url ? item.view_url : ''" :class="item.view_url ? '' : 'no-click'">
            <ktj-image :src="item.photourl" width="100%" height="100%" />
          </a>
        </div>
        <div class="mybox-right" :class="index + 1 < list.length && 'ks-line'">
          <div class="mybox-right__title">
            <a
              :href="item.view_url ? item.view_url : ''"
              :class="item.view_url ? '' : 'no-click'"
            >{{ item.name }}</a>
          </div>
          <div class="mybox-right__teacher">{{ item.teacher_name }}</div>
          <!--<van-button
            class="bottom-btn"
            size="mini"
            round
            type="danger"
            @click="getCoursePaperList()"
          >试卷</van-button>
           <van-button
            class="bottom-btn"
            size="mini"
            round
            type="danger"
            @click="getCourseDataList(item.courseid)"
            >资料</van-button>
            -->
          <van-progress
            class="mylist-content__progress"
            :show-pivot="false"
            color="#f44"
            :percentage="Number(item.has_learnpercent)"
          />
          <div class="mybox-right__percentage">{{ item.has_learnpercent }}%</div>
        </div>
      </div>
      <!-- 无数据提示 -->
      <Nodata v-if="showNodata" />
    </ks-box>
    <van-action-sheet v-model="show" title="课程资料">
      <div class="course" v-for="(data, i) in dataList" :key="i">
        <div class="course-ast">
          {{ data.zl_name }}
          <a
            :href="data.get_viewurl ? data.get_viewurl : ''"
            :class="data.get_viewurl ? '' : 'no-click'"
          >
            <img class="course-ast_dload" src="../../assets/user/download.png" />
          </a>
        </div>
        <div class="ks-line" v-if="i + 1 < dataList.length"></div>
      </div>
      <!-- 无数据提示 -->
      <Nodata v-if="dataListNodata" />
    </van-action-sheet>
    <van-action-sheet v-model="show2" title="试卷资料">
      <div class="course" v-for="(data, i) in paperList" :key="i">
        <div class="course-ast">
          {{ data.title }}
          <a
            :href="data.get_viewurl ? data.get_viewurl : ''"
            :class="data.get_viewurl ? '' : 'no-click'"
          >
            <img class="course-ast_dload" src="../../assets/user/download.png" />
          </a>
        </div>
        <div class="ks-line" v-if="i + 1 < paperList.length"></div>
      </div>
      <!-- 无数据提示 -->
      <Nodata v-if="paperListNodata" />
    </van-action-sheet>
  </ks-page-scroll-container>
</template>
<script>
import {
  GetCourseDataList,
  GetUserCourseList,
  GetCoursePaperList
} from "@/api/user";
export default {
  name: "myCourse",
  data() {
    return {
      list: [], //资料列表
      show: false,
      show2: false,
      showNodata: false,
      dataListNodata: false,
      paperListNodata: false,
      page: 1,
      pageCount: null,
      pagination: true,
      len: "", //课程数
      dataList: [], //资料列表
      paperList: [] //试卷列表
    };
  },
  methods: {
    open() {
      this.$router.push({
        name: "MyCourse"
      });
    },
    getCoursePaperList(courseid) {
      //获取试卷列表
      this.show2 = true;
      GetCoursePaperList({
        courseid: courseid,
        page: 1,
        pagesize: 10
      }).then(res => {
        if (res.result) {
          this.paperList = res.data;
          this.paperListNodata = false;
        } else {
          this.paperList = [];
          this.paperListNodata = true;
        }
      });
    },
    getMyCourseList(p = 1) {
      //获取课程列表
      if (p == 1) {
        this.list = [];
      }
      this.page = p;
      GetUserCourseList({
        page: p,
        pagesize: 5
      }).then(res => {
        if (res.result) {
          this.list = this.list.concat(res.data);
          this.pageCount = res.pagecount;
          this.len = res.totalcount;
          this.showNodata = false;
        } else {
          this.list = [];
          this.showNodata = true;
        }
      });
    },
    getCourseDataList(courseid) {
      //课程资料数据
      this.show = true;
      GetCourseDataList({
        courseid: courseid,
        page: 1,
        pagesize: 10
      }).then(res => {
        if (res.result) {
          console.log(courseid, res.data);
          this.dataList = res.data;
          this.dataListNodata = false;
        } else {
          this.dataList = [];
          this.dataListNodata = true;
        }
      });
    }
  },
  created() {
    this.getMyCourseList();
  },
  activated() {
    document.title = "我的课程";
  }
};
</script>
<style scoped>
.middlep {
  background-color: #fff;
  width: 100%;
  height: 180px;
  margin-top: 6px;
  border-radius: 10px;
}
.my-exam {
  height: 44px;
  line-height: 44px;
  background-color: #fff;
}
.my-exam__a {
  font-size: 16px;
  margin: 0 10px 0 20px;
  line-height: 40px;
  /* font-weight: bolder; */
  color: rgba(51, 51, 51, 1);
  margin-top: 14.5px;
}
.my-exam__aa {
  font-size: 16px;
  margin: 0 10px 0 20px;
  /* font-weight: bolder; */
  color: rgba(251, 110, 82, 1);
}
.mybox {
  margin-top: 10px;
  background-color: #fff;
  width: 100%;
  height: 100%;
  border-radius: 10px;
}
.mybox-content {
  padding: 15px;
}
.mybox-acous {
  font-size: 18px;
  font-weight: bold;
}

.mybox__item {
  display: flex;
}
.bottom-btn {
  font-size: 12px;
  color: #fff;
  background: rgba(251, 110, 82, 1);
  border-radius: 20px;
  border: 1px solid transparent;
  width: 35px;
  height: 25px;
  margin-top: -18px;
  margin-left: 10px;
  float: right;
}
.mybox-right {
  flex: 1;
  padding-bottom: 10px;
}
.mybox-right__title {
  margin-top: 11px;
  font-size: 15px;
  font-weight: bold;
}
.mybox-right__teacher {
  margin-top: 5px;
  font-size: 13px;
  color: rgba(153, 153, 153, 1);
  width: 50%;
  height: 18px;
  line-height: 18px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.mybox-right__percentage {
  margin-top: 3px;
  margin-bottom: 10px;
  font-size: 12px;
  color: rgba(153, 153, 153, 1);
}
.mybox-img {
  width: 140px;
  height: 90px;
  margin-right: 0.5rem;
  margin-top: 10px;
  float: left;
  border-radius: 6px;
  overflow: hidden;
}
.mybox-img img {
  width: 100%;
  height: 100%;
}
.mylist-content__progress {
  margin-top: 15px;
}
.mybox-right__hr {
  float: right;
  height: 0.5px;
  width: 66%;
  margin-top: 5px;
  background: rgba(233, 230, 230, 1);
}
.van-progress {
  height: 5px;
  position: relative;
  border-radius: 5px;
  background: #fddcdc;
}
.course-ast {
  text-align: center;
  line-height: 44px;
  font-size: 13px;
}
.course-ast_dload {
  right: 0;
  padding-top: 3px;
  padding-right: 15px;
  position: absolute;
  line-height: inherit;
  font-size: 18px;
}
.van-popup--bottom {
  border-radius: 10px 10px 0 0;
}
.van-action-sheet__header {
  font-size: 16px;
  line-height: 55px;
  text-align: center;
  font-weight: bold;
}
.no-click {
  pointer-events: none;
}
</style>
