<!-- 课程管理 -->
<template>
  <div class="app-container courseManagement" :class="pageType != 1?'no-app-container':''">
    <div class="page-container courseManagementPage" 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="shelfStatus">
            <el-select v-model="queryParams.shelfStatus" 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="knowledgePointIds">
            <el-cascader
              style="width: 180px"
              @change="knowledgePointIdsChange"
              v-model="queryParams.knowledgePointIds"
              :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="disciplineId">
            <el-select v-model="queryParams.disciplineId" placeholder="课程分类" style="width: 200px">
              <el-option
                v-for="dict in optionListC"
                :key="dict.id"
                :label="dict.disciplineName"
                :value="dict.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="deptId">
            <el-cascader
              style="width: 180px"
              v-model="queryParams.deptId"
              :options="optionListD"
              :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="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;"
             v-hasPermiRouter="['exam:course:add']"
             @click="tableButton(1)"
          >新建课程</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box"  border :data="dataList">
          <el-table-column label="课程名称" prop="courseName"  show-overflow-tooltip>
            <template slot-scope="scope">
              <span @click="tableButton(5,scope.row)" style="color:#0183fa;cursor: pointer">{{scope.row.courseName}}</span>
            </template>
          </el-table-column>
          <el-table-column label="知识点" prop="knowledgePointNames" width="200" show-overflow-tooltip/>
          <el-table-column label="是否共享" prop="content" width="100" show-overflow-tooltip>
            <template slot-scope="scope">
              <span 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)" v-if="scope.row.shareStatus==1">共享</span>
              <span 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)" v-if="scope.row.shareStatus==0">不共享</span>
            </template>
          </el-table-column>
          <el-table-column label="课程分类" prop="disciplineTypeName" width="120" show-overflow-tooltip/>
          <el-table-column label="课件总数" prop="coursewareTotalCount" width="100" show-overflow-tooltip/>
          <el-table-column label="总时长" prop="totalLearningDuration" width="100" show-overflow-tooltip/>
          <el-table-column label="可得学时" prop="totalCreditHours" width="100" show-overflow-tooltip/>
          <el-table-column label="状态" prop="shelfStatus" width="100" show-overflow-tooltip>
            <template slot-scope="scope">
              <span style="padding:2px 10px;border:1px solid #5AD8A6;border-radius:4px;color: #5AD8A6;background-color:rgba(90, 216, 166,0.2)" v-if="scope.row.shelfStatus==1">上架</span>
              <span style="padding:2px 10px;border:1px solid #999999;border-radius:4px;color: #999999;background-color:rgba(153, 153, 153,0.2)" v-if="scope.row.shelfStatus==0">未上架</span>
            </template>
          </el-table-column>
          <el-table-column label="来源" prop="deptName" width="120" show-overflow-tooltip/>
          <el-table-column label="最近更新" prop="updateTime" width="200" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ scope.row.updateTime?parseTime(scope.row.updateTime,"{y}-{m}-{d} {h}:{i}"):parseTime(scope.row.createTime,"{y}-{m}-{d} {h}:{i}") }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="200" 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"
                   v-hasPermiRouter="['exam:course:add']"
                   @click="tableButton(2,scope.row)"
                >复制</p>
                <p class="table-button-p"
                   v-if="scope.row.canEditDelete"
                   v-hasPermiRouter="['exam:course:edit']"
                   @click="tableButton(3,scope.row)"
                >编辑</p>
                <p class="table-button-p"
                   v-if="scope.row.canEditDelete"
                   v-hasPermiRouter="['exam:course:del']"
                   @click="tableButton(4,scope.row)"
                >删除</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>
  </div>
</template>
<script>
  //import { getDicts } from "@/api/commonality/noPermission";
  //import { systemUserSelect } from "@/api/commonality/permission";
  //import { getInfo } from "@/api/basicsModules/index";
  import {
    examElCoursePage,examElCourseDel,examElCourseCopy,
    examElKnowledgePointTreeList,examElDisciplineTypeList,systemDeptCurrentDept,
  } from "@/api/safetyEducationExaminationNew/index";
  import addPage from "./addPage.vue";
  export default {
    name: 'index',
    components: {
     addPage
    },
    data () {
      return {
        tableButtonType:this.hasPermiDom(['exam:course:add','exam:course:edit','exam:course:del']),
        //页面状态
        pageType:1,
        //下拉列表数据
        optionListA:[{value:1,label:'上架'},{value:0,label:'未上架'}],
        optionListB:[],
        optionListC:[],
        optionListD:[],
        queryParams:{
          page:1,
          pageSize:20,
          shareStatus:"",
          shelfStatus:null,
          knowledgePointIds:[],
          disciplineId:null,
          deptId:null,
          searchValue:"",
        },
        //列表数据
        dataList:[],
        //数据数量
        total:0,
        //组件传参
        propsData:{},
      }
    },
    created () {

    },
    mounted () {
      this.examElDisciplineTypeList();
      this.systemDeptCurrentDept();
      this.examElKnowledgePointTreeList();
      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,
          shareStatus:"",
          shelfStatus:null,
          knowledgePointIds:[],
          disciplineId:null,
          deptId:null,
          searchValue:"",
        });
        this.getList();
      },
      //获取数据列表
      getList(){

        let obj = JSON.parse(JSON.stringify(this.queryParams))
        examElCoursePage(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){
          //复制
          this.$confirm('是否确认复制?', "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
          }).then(() => {
            examElCourseCopy({id:row.id}).then(response => {
              self.msgSuccess(response.message)
              self.getList();
            });
          }).catch(() => {});
        }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(() => {
            examElCourseDel({id:row.id}).then(response => {
              self.msgSuccess(response.message)
              self.getList();
            });
          }).catch(() => {});
        }else if(type == 5){
          //预览课程
          this.$set(this,'pageType',2);
          let obj = JSON.parse(JSON.stringify(row))
          obj.showType = true;
          this.$set(this,'propsData',obj);

        }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,'optionListD',list);
        });
      },
      //查询全部专业类别
      examElDisciplineTypeList(){
        examElDisciplineTypeList({}).then(response => {
          this.$set(this,'optionListC',response.data);
        });
      },
      //知识点选中变更为数组
      knowledgePointIdsChange(val){
        this.$set(this.queryParams,'knowledgePointIds',[val]);
      },
    },
  }
</script>
<style scoped lang="scss">
  .no-app-container{
    border-radius:0 !important;
    margin:0 !important;
    box-shadow: none !important;
  }
  .courseManagement{
    .courseManagementPage{
      .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>
