<template>
  <div class="normal-card">
    <div class="header-panl">
      <!-- 搜索及分类筛选 -->
      <filterList @changeTypeId="changeTypeId" @startSearch="startSearch">
          <hot-new-control @sortTypeChange="sortTypeChange"/>
      </filterList>
    </div>
    <!--课件列表-->
    <div class="file" v-if="list.length != 0 && tool.checkAuth($route.name,'read')">
      <div class="file-item" v-for="(item,index) in list" :key="index" @click="itemClick(item)">
        <div class="top">
          <el-image style="width: 100%; height: 100%" :src="item.cover || require('@/assets/video.png')" fit="fill">
          </el-image>
        </div>
        <div class="bottom">
          <p class="title">{{item.title}}</p>
          <p class="descript">{{item.notes}}</p>
          <p class="people">{{item.readcount}}人学习</p>
        </div>
      </div>
    </div>
    <el-empty description="暂无数据" v-else></el-empty>
    <!--分页-->
    <pagination :total="total" :pageSize="param.content.pageSize" :currentPage="param.content.pageNumber"
      @pageChange="pageChange">
    </pagination>
    <!--课程详情-->
    <detail ref="detail" :currentSelectFile="currentSelectFile"
      v-if="currentSelectFile && tool.checkAuth($route.name,'read')"></detail>
  </div>
</template>

<script>
import search from '@/components/search/index'
import HotNewControl from '@/components/hot-new-control/HotNewControl'
import Pagination from '@/components/pagination/Pagination'
import CategorySelect from '@/components/category-select/CategorySelect'
import detail from '@/SManagement/archives_sc/archives_details/detail'
import filterList from "@/components/filter-list/filterList"


import FileType from '@/utils/matchingFeilType'
export default {
  name: 'index',
  data () {
    return {
      param: {
        "classname": "saletool.courseware.courseware",
        "method": "selectList",
        "content": {
          nocache: true,
          "pageNumber": 1,
          "pageSize": 12,
          "where": {
            "condition": "",
            "sat_courseware_classid": ''
          }
        }
      },
      detail: {
        "classname": "saletool.courseware.courseware",
        "method": "selectDetail",
        "content": {
          "sat_coursewareid": ''
        }
      },
      //分类配置
      select: {
        "classname": "saletool.courseware.courseware",
        "method": "selectMenu",
        "content": {

        }
      },
      //列表数据
      list: [],
      //分类列表
      selectList: [],
      selectId: 11111,
      total: 0,
      //当前选中的课程
      currentSelectFile: ''
    };
  },
  components: {
    HotNewControl,
    Pagination,
    CategorySelect,
    detail,
    search,
    filterList
  },
  computed: {
  },
  watch: {
  },
  created () {
    this.getFileData()
  },
  methods: {
    //获取列表数据
    async getFileData () {
      let res = await this.$api.requested(this.param)
      this.total = res.total
      this.list = res.data
      this.param.content.sort = res.sort
    },
    sortTypeChange (name) {
      for (let i = 0; i < this.param.content.sort.length; i++) {
        this.param.content.sort[i].sorted = this.param.content.sort[i].sortname == name ? 1 : 0
      }
      this.getFileData()
    },
    //分页切换
    pageChange (n) {
      this.param.content.pageNumber = n
      this.getFileData()
    },
    //单击进入详情
    async itemClick (item) {
      this.detail.content.sat_coursewareid = item.sat_coursewareid
      let res = await this.$api.requested(this.detail)
      this.currentSelectFile = res.data
      this.$nextTick(() => {
        this.$refs.detail.isFileInfoPanlShow = true
      })
    },
    /* 改变分类ID */
    changeTypeId(id) {
      this.param.content.where.sat_courseware_classid = id == 0 ? null : id;
      this.param.content.pageNumber = 1
      this.getFileData();
    },
    /* 开始搜索 */
    startSearch(value) {
      this.param.content.where.condition = value;
      this.param.content.pageNumber = 1
      this.getFileData();
    }
  },
};
</script>

<style scoped>
*{
  box-sizing: border-box;
}
.normal-card {
  min-height: 100%;
  box-sizing: border-box;
  position: relative;
}
.normal-card .header-panl {
  display: flex;
  justify-content: space-between;
  margin-bottom: 30px;
}
.normal-card .header-panl .left {
  display: flex;
}
.normal-card .header-panl .left .select {
  margin-right: 16px;
}

.normal-card .file {
  display: flex;
  flex-wrap: wrap;
}
.normal-card .file .file-item {
  width: 212px;
  height: 204px;
  background: #ffffff;
  border-radius: 4px;
  border: 1px solid #cccccc;
  transition: all 0.1s ease-in;
  margin: 0 16px 16px 0;
  cursor: pointer;
}
.normal-card .file .file-item:hover {
  box-shadow: rgba(99, 99, 99, 0.2) 0px 2px 8px 0px;
}
.normal-card .file .file-item .top {
  width: 212px;
  height: 118px;
  border-top-right-radius: 4px;
  border-top-left-radius: 4px;
}
.normal-card .file .file-item .top img {
  width: 100%;
  height: 100%;
  border-top-right-radius: 4px;
  border-top-left-radius: 4px;
}
.normal-card .file .file-item .bottom {
  padding: 10px 18px 10px 16px;
}
.normal-card .file .file-item .bottom .title {
  font-size: 14px;
  font-family: PingFang SC-Bold, PingFang SC;
  font-weight: bold;
  color: #333333;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
  margin-bottom: 5px;
}
.normal-card .file .file-item .bottom .descript {
  font-size: 12px;
  font-family: PingFang SC-Regular, PingFang SC;
  font-weight: 400;
  color: #666666;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
  margin-bottom: 4px;
}
.normal-card .file .file-item .bottom .people {
  font-size: 10px;
  font-family: PingFang SC-Regular, PingFang SC;
  font-weight: 400;
  color: #999999;
}
.normal-card .el-pagination {
  position: absolute;
  bottom: 0;
  right: 16px;
}
.select {
  margin-left: 20px;
}
.el-empty {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
</style>
