<template>
  <div class="normal-card">
    <div class="header-panl">
      <div class="left">
        <!--分类选择器-->
        <category-select label="课程分类" @changeSelect="changeSelect" :selectList="selectList"
          :prop="{value:'sat_courseware_classid',label:'classname'}" v-if="tool.checkAuth($route.name,'read')"></category-select>
        <!--搜索-->
        <search @searchActive="searchActive" @clearData="clearData" v-if="tool.checkAuth($route.name,'read')"></search>
      </div>
      <!--最新最热切换-->
      <hot-new-control :sortType='param.content.where.sorttype' @sortTypeChange="sortTypeChange" v-if="tool.checkAuth($route.name,'read')"></hot-new-control>
    </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">
          <img :src="item.cover" alt="">
        </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 FileType from '@/utils/matchingFeilType'
export default {
  name: 'index',
  data () {
    return {
      param: {
        "classname": "saletool.courseware.courseware",
        "method": "selectList",
        "content": {
          "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
  },
  computed: {
  },
  watch: {
  },
  created () {
    this.getFileData()
    this.getSelectList()
  },
  methods: {
    //获取列表数据
    getFileData () {
      this.$api.requested(this.param).then(res => {
        this.total = res.total
        this.list = res.data
        this.param.content.sort = res.sort
      })
    },
    //获取分类列表
    getSelectList () {
      this.$api.requested(this.select).then(res => {
        this.selectList = res.data
      })
    },
    //查询
    searchActive (result) {
      this.param.content.where.condition = result
      this.param.content.where.pageNumber = 1
      this.$api.requested(this.param).then(res => {
        this.list = res.data
        this.total = res.total
      })
    },
    //清除查询
    clearData () {
      this.param.content.where.condition = ''
      this.getFileData()
    },
    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()
    },
    //单击进入详情
    itemClick (item) {
      this.detail.content.sat_coursewareid = item.sat_coursewareid
      this.$api.requested(this.detail).then(res => {
        this.currentSelectFile = res.data
        this.$nextTick(() => {
          this.$refs.detail.isFileInfoPanlShow = true
        })
      })
    },
    changeSelect (id) {
      this.param.content.pageNumber = 1
      this.param.content.where.sat_courseware_classid = id[id.length - 1];
      this.getFileData()
    }
  },
};
</script>

<style scoped>
.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 20px 16px 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;
  right: 16px;
  bottom: 0;
}
.select {
  margin-left: 20px;
}
.el-empty {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
</style>
