<!-- 课件管理 -->
<template>
  <div class="app-container coursewareManagement" :class="pageType != 1?'no-app-container':''">
    <div class="page-container coursewareManagementPage" v-if="pageType === 1">
      <div class="page-form-title-box">
        <el-form :model="queryParams" class="form-box" ref="queryForm"
                 :inline="true" style="width:100%;">
          <el-form-item label="" prop="shareStatus">
            <el-select v-model="queryParams.shareStatus" placeholder="是否共享" style="width: 120px">
              <el-option label="共享" value="1"/>
              <el-option label="不共享" value="0"/>
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="materialType">
            <el-select v-model="queryParams.materialType" placeholder="课件类型" style="width: 200px">
              <el-option
                v-for="dict in optionListA"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="knowledgePointId">
            <el-cascader
              style="width: 180px"
              v-model="queryParams.knowledgePointId"
              :options="optionListB"
              :props="{
                    emitPath:false,
                    checkStrictly: true,
                    value: 'id',
                    label: 'knowledgePointName',
                    children: 'children',
                  }"
              :show-all-levels="false"
              filterable
              placeholder="知识点"
            ></el-cascader>
          </el-form-item>
          <el-form-item label="" prop="deptId">
            <el-cascader
              style="width: 180px"
              v-model="queryParams.deptId"
              :options="optionListC"
              :props="{
                    emitPath:false,
                    checkStrictly: true,
                    value: 'deptId',
                    label: 'deptName',
                    children: 'child',
                  }"
              :show-all-levels="false"
              filterable
              placeholder="来源"
            ></el-cascader>
          </el-form-item>
          <el-form-item label="" prop="disciplineTypeId">
            <el-select v-model="queryParams.disciplineTypeId" placeholder="课件分类" style="width: 200px">
              <el-option
                v-for="dict in disciplineOptionList"
                :key="dict.id"
                :label="dict.disciplineName"
                :value="dict.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="searchValue">
            <el-input
              maxLength="30"
              v-model="queryParams.searchValue"
              placeholder="搜索名称"
              style="width: 200px"
            />
          </el-form-item>
          <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
          <p class="page-submit-common-style-button"
             style="float: right;"
             @click="tableButton(1)"
             v-hasPermiRouter="['exam:courseware:add']"
          >添加课件</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box"  border :data="dataList">
          <el-table-column label="课件名称" prop="coursewareName"  show-overflow-tooltip>
            <template slot-scope="scope">
              <span @click="tableButton(2,scope.row)" style="color:#0183fa;cursor: pointer">{{scope.row.coursewareName}}</span>
            </template>
          </el-table-column>
          <el-table-column label="知识点" prop="knowledgePointName" width="120" show-overflow-tooltip/>
          <el-table-column label="课件分类" prop="disciplineTypeName" width="120" show-overflow-tooltip/>
          <!--<el-table-column label="专业类别" prop="content" width="100" show-overflow-tooltip/>-->
          <el-table-column label="是否共享" prop="shareStatus" width="100" show-overflow-tooltip>
            <template slot-scope="scope">
              <span v-if="scope.row.shareStatus == 1" style="padding:2px 10px;border:1px solid rgb(1, 131, 251);border-radius:4px;color: rgb(1, 131, 251);background-color:rgba(1, 131, 251,0.2)">共享</span>
              <span v-if="scope.row.shareStatus == 0" style="padding:2px 10px;border:1px solid rgb(245, 154, 35);border-radius:4px;color: rgb(245, 154, 35);background-color:rgba(245, 154, 35,0.2)">不共享</span>
            </template>
          </el-table-column>
          <el-table-column label="课件类型" prop="materialType" width="100" show-overflow-tooltip>
            <template slot-scope="scope">
              {{scope.row.materialType == 1?'视频':(scope.row.materialType == 3?'文档':(scope.row.materialType == 4?'文章':''))}}
            </template>
          </el-table-column>
          <el-table-column label="文件大小" prop="attachmentSize" width="100" show-overflow-tooltip>
            <template slot-scope="scope">
              {{scope.row.attachmentSize?scope.row.attachmentSize+'Mb':'-'}}
            </template>
          </el-table-column>
          <el-table-column label="要求时长" prop="minLearningDuration" width="100" show-overflow-tooltip>
            <template slot-scope="scope">
              {{scope.row.minLearningDuration}}分钟
            </template>
          </el-table-column>
          <el-table-column label="可得学时" prop="creditHours" width="100" show-overflow-tooltip/>
          <el-table-column label="可得积分" prop="points" width="100" show-overflow-tooltip/>
          <el-table-column label="来源" prop="deptName" width="100" show-overflow-tooltip/>
          <el-table-column label="创建人" prop="createName" width="100" show-overflow-tooltip/>
          <el-table-column label="创建时间" prop="createTime" width="160" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime,"{y}-{m}-{d} {h}:{i}") }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="140" show-overflow-tooltip v-if="tableButtonType">
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p"
                   @click="tableButton(3,scope.row)"
                   v-if="scope.row.canEditDelete"
                   v-hasPermiRouter="['exam:courseware:edit']"
                >编辑</p>
                <p class="table-button-p"
                   @click="tableButton(4,scope.row)"
                   v-if="scope.row.canEditDelete"
                   v-hasPermiRouter="['exam:courseware:del']"
                >删除</p>
                <p class="table-button-null"></p>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <pagination :page-sizes="[20, 30, 40, 50]"
                    v-show="total>0"
                    :total="total"
                    :page.sync="queryParams.page"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
    </div>
    <add-page :propsData="propsData" v-if="pageType === 2"></add-page>
    <fullScreenFileLook ref="fullScreenFileLook"></fullScreenFileLook>
  </div>
</template>
<script>
  import fullScreenFileLook from "@/components/fullScreenFileLook/fullScreenFileLook.vue";
  import {
    examElCoursewarePage,examElCoursewareDel,examElKnowledgePointTreeList,
    systemDeptCurrentDept,examElCoursewareDetail,examElDisciplineTypeList
  } from "@/api/safetyEducationExaminationNew/index";
  import addPage from "./addPage.vue";
  export default {
    name: 'index',
    components: {
      addPage,
      fullScreenFileLook
    },
    data () {
      return {
        tableButtonType:this.hasPermiDom(['exam:courseware:edit','exam:courseware:del',]),
        //页面状态
        pageType:1,
        //下拉列表数据
        optionListA:[{value:1,label:'视频'},{value:3,label:'文档'},{value:4,label:'文章'}],
        optionListB:[],
        optionListC:[],
        disciplineOptionList:[],
        queryParams:{
          page:1,
          pageSize:20,
          searchValue:'',
          shareStatus:'',
          materialType:null,
          knowledgePointId :null,
          deptId :null,
        },
        //列表数据
        dataList:[],
        //数据数量
        total:0,
        //组件传参
        propsData:{},
      }
    },
    created () {

    },
    mounted () {
      this.systemDeptCurrentDept();
      this.examElKnowledgePointTreeList();
      this.examElDisciplineTypeList();
      this.getList();
    },
    methods: {
      //切换按钮
      tableTypeButton(val){
        if(this.queryParams.shareStatus != val){
          this.$set(this.queryParams,'shareStatus',val);
          this.handleQuery();
        }
      },
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          searchValue:'',
          shareStatus:'',
          materialType:null,
          knowledgePointId :null,
          deptId :null,
        });
        this.getList();
      },
      //获取数据列表
      getList(){

        let obj = JSON.parse(JSON.stringify(this.queryParams))
        examElCoursewarePage(obj).then(response => {

          this.$set(this,'dataList',response.data.records);
          this.$set(this,'total',response.data.total);
        });
      },
      //操作按钮
      tableButton(type,row){
        let self = this;
        if(type == 1){
          //新增
          this.$set(this,'pageType',2);
          this.$set(this,'propsData',{});
        }else if(type == 2){
          //预览
          let name=row.coursewareName;
          let url='';
          let type='';
          if(row.materialType == 1){
            //视频
            type = 'video'
            url = row.attachmentPath;
            this.$refs['fullScreenFileLook'].initialize(name,url,type);
          }else if(row.materialType == 3){
            //文档
            if(row.attachmentType == '.docx'){
              type = 'docx'
            }else if(row.attachmentType == '.xlsx'){
              type = 'excel'
            }else if(row.attachmentType == '.pdf'){
              type = 'pdf'
            }
            url = row.attachmentPath;
            this.$refs['fullScreenFileLook'].initialize(name,url,type);
          }else if(row.materialType == 4){
            //富文本
            examElCoursewareDetail({id:row.id}).then(response => {
              type = 'text'
              url = response.data.articleContent;
              this.$refs['fullScreenFileLook'].initialize(name,url,type);
            });
          }
        }else if(type == 3){
          //编辑
          this.$set(this,'pageType',2);
          let obj = JSON.parse(JSON.stringify(row))
          this.$set(this,'propsData',obj);
        }else if(type == 4){
          //删除
          this.$confirm('是否确认删除?', "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
          }).then(() => {
            examElCoursewareDel({id:row.id}).then(response => {
              self.msgSuccess(response.message)
              self.getList();
            });
          }).catch(() => {});
        }else if(type == 6){
          //返回并刷新
          this.$set(this,'pageType',1);
          this.getList();
        }
      },
      //知识点
      examElKnowledgePointTreeList(){
        examElKnowledgePointTreeList({}).then(response => {
          const list = response.data || [];
          this.formatTreeData(list);
          this.$set(this, 'optionListB', list);
        });
      },
      //学院列表
      systemDeptCurrentDept(){
        systemDeptCurrentDept({}).then(response => {
          const list = response.data || [];
          this.formatTreeData(list);
          this.$set(this,'optionListC',list);
        });
      },
      //查询全部专业类别
      examElDisciplineTypeList(){
        examElDisciplineTypeList({}).then(response => {
          this.$set(this,'disciplineOptionList',response.data);
        });
      },
    },
  }
</script>
<style scoped lang="scss">
  .no-app-container{
    border-radius:0 !important;
    margin:0 !important;
    box-shadow: none !important;
  }
  .coursewareManagement{
    .coursewareManagementPage{
      .table-top-button-box{
        display: inline-block;
        vertical-align: top;
        margin-right:10px;
        div{
          display: flex;
          p{
            border:1px solid #DCDFE6;
            width:80px;
            text-align: center;
            height:40px;
            line-height:40px;
            cursor: pointer;
            font-size:14px;
          }
          p:nth-child(1){
            border-top-left-radius:4px;
            border-bottom-left-radius:4px;
          }
          p:nth-child(2){
            border-left:none;
            border-right:none;
          }
          p:nth-child(3){
            border-top-right-radius:4px;
            border-bottom-right-radius:4px;
          }
          .check-table-button{
            border:1px solid #0183fa;
            background-color: #0183fa;
            color:#fff;
          }
        }
      }
    }
  }
</style>
