
<template>
  <div class="u-page">
    <div style="padding: 2px 0px 10px 0px;">
           <el-row :gutter="10">
          <!-- <el-col :span="6">
              <el-cascader placeholder="资源归属" clearable v-model="resOwner" :props="defaultProps" :options="resOwnerListMap"></el-cascader>
          </el-col> -->
           <el-col :span="4">
            <el-cascader placeholder="内容分类" clearable v-model="sysTypeList" :props="defaultTypeProps" :options="sysTypeListMap"></el-cascader>
          </el-col>
          <el-col :span="4">
              <el-input placeholder="创建人" v-model="params.createUser" clearable></el-input>
          </el-col>
          <el-col :span="4">
             <el-input placeholder="名称" v-model="params.keyword" clearable></el-input>
          </el-col>
          <el-col :span="4">
              <el-select v-model="params.publish" placeholder="是否发布" clearable>
                <el-option label="全部" :value="null"></el-option>
                <el-option label="已发布" :value="true"></el-option>
                <el-option label="未发布" :value="false"></el-option>
              </el-select>
          </el-col>
            <el-col  :span="8">
              <el-button type="primary"  @click="searchData()" icon="el-icon-search">搜索</el-button>
              <el-button icon="el-icon-refresh-right" type="primary"  @click="reset">重置</el-button>
          </el-col>
        </el-row>
       
    </div>
    <el-table :data="pageData" border stripe>
	  <el-table-column label="序号" type="index" width="50"></el-table-column>
      <el-table-column label="名称" prop="name" show-overflow-tooltip width="200px">
        <template slot-scope="scope">
           <span class="previewStyle" @click="viewTopic(scope.row)">{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="内容分类" prop="sysType" sortable width="240px">
        <template slot-scope="scope">
           <span v-if="scope.row.sysType1 != ''">{{sysTypeName(scope.row.sysType1)}}</span>
          <span v-if="scope.row.sysType2 != ''">/{{sysTypeName(scope.row.sysType2)}}</span>
          <span v-if="scope.row.sysType3 != ''">/{{sysTypeName(scope.row.sysType3)}}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="资源归属" sortable prop="author" width="240px">
        <template slot-scope="scope">
          <span>{{resOwnerName(scope.row.resOwner1)}}</span>
          <span v-if="scope.row.resOwner2 != ''">/{{resOwnerName(scope.row.resOwner2)}}</span>
          <span v-if="scope.row.resOwner3 != ''">/{{resOwnerName(scope.row.resOwner3)}}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="状态" prop="status" width="120px">
        <template slot-scope="scope">
          <!-- 1，未提交 2.已提交 = 未审核 5 已审核 -->
          <span v-if="scope.row.status == 1">未提交</span>
          <span v-if="scope.row.status == 2">待审核</span>
          <span v-if="scope.row.status == 5">已审核</span>
          <span v-if="scope.row.status == 3">审核未通过</span>
        </template>
      </el-table-column>
      <el-table-column label="是否发布" width="130px">
        <template slot-scope="scope">
          {{ scope.row.published !== true ? '未发布' : '已发布' }}
        </template>
      </el-table-column>
      <el-table-column label="创建人" prop="sysCreateBy"></el-table-column>
      <el-table-column label="创建时间" prop="sysCreateTime" width="200px" show-overflow-tooltip></el-table-column>
     <el-table-column label="操作" width="100px" fixed="right">
        <template slot-scope="scope">
          <el-button @click="toExamine(scope.row)" type="text" >审核记录</el-button>
        </template>
      </el-table-column>
    </el-table>

    <div v-if="pageData.length > 0" style="text-align: center;margin-top:70px">
       <el-pagination background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page.pageIndex"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="page.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page.count"
      ></el-pagination>
    </div>
   
    <div style="height: 100px;"></div>
    <el-dialog title="审核记录" :visible.sync="dialogVisible" width="900px" custom-class="g-dialog">
      <div>
            <el-table max-height="500" border :data="inviteTeacher.list" style="width: 100%;">
              <el-table-column prop="sysCreateBy" label="姓名" width="180"></el-table-column>
               <el-table-column prop="type" label="审核状态">
                   <template slot-scope="scope">{{scope.row.auditState? '通过': '不通过'}}
                </template>
               </el-table-column>
               <el-table-column prop="auditTime" label="审核时间"></el-table-column>
              <el-table-column prop="auditRemark" label="备注"></el-table-column>
            </el-table>
          </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>
     <el-dialog title="课程详情" :visible.sync="showDetails" @close="examin = {};" width="900px" custom-class="g-dialog">
        <div v-if="examin.detailType == 10"><auditCourse1 :showTest="true" :isDetails="false" :isShow="false" :id="examin.examineId"></auditCourse1></div>
        <div v-if="examin.detailType == 20"><auditCourse2 :showTest="true" :isDetails="false" :isShow="false" :id="examin.examineId"></auditCourse2></div>
   
      <span slot="footer" class="dialog-footer">
        <el-button @click="showDetails = false;examin = {};">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import courseForm from '@/components/Course/courseForm.vue';
import manager from '@/components/Study/manager.vue';
import auditCourse1 from '@/components/Course/auditCourse1.vue';
import auditCourse2 from '@/components/Course/auditCourse2.vue';
import adminPage from '@/components/Administration/adminPage.vue';
import apiType from '../../api/modules/type.js';
import apiCourse from '../../api/modules/course.js';
import apiAudit from '@/api/system/audit.js';
// import {resOwnerIndexName,sysTypeIndexName} from '@/utils/type.js';
import { mapGetters,mapActions} from 'vuex';
export default {
  name: 'manageCourse',
  components: {courseForm, manager, auditCourse1, auditCourse2,adminPage },
  computed: {
      ...mapGetters(['resOwnerMap','sysTypeMap']),
    },
  data() {
    return {
     sysTypeList:[],
     sysTypeListMap:[],
     resOwnerListMap:[],
     showDetails:false,
     examin:{
       detailType: '',
       examineId: '',
       examineName: '',
      },
      page: {
        pageIndex: 1,//第几页
        pageSize: 10, // 每页多少条
        count: 0
      },
      resOwner: [],
      defaultProps:{
        value: 'code',
        label: 'name',
      },
      defaultTypeProps:{
        value: 'id',
        label: 'name',
      },
      isExamine: 1,
      detailType: 1,
      dialogVisible: false,
      inviteTeacher: {
        //邀请
        dlgShow: false,
        params: { name: '' },
        list: []
      },
      params: {},
      pageData:[],
      courseChooseShow: false,
    };
  },
  mounted() {
    this.loadResOwners();
    this.searchData();
     this.getResOwnerTree().then(rs=>{
      this.resOwnerListMap=rs;
    });
    this.getSysTypeTree().then(rs=>{
      this.sysTypeListMap=rs;
    })
   
  },
  methods: {
    getseatch(){
     this.params.pageIndex= 1;
     this.searchData();
   },
    reset(){
       this.resOwner = ''
      this.params.sysType = ''
      this.params.createUser = ''
      this.params.keyword = ''
      this.params.type = ''
      this.params.publish = ''
      this.sysTypeList = [];
      this.params.sysType1 = '';
      this.params.sysType2 = '';
      this.params.sysType3 = '';
      this.params.pageIndex= 1;
	    this.searchData();
    },
    ...mapActions({
      getResOwnerTree:'resOwner/getResOwnerTree',
      loadResOwners:'resOwner/loadResOwners',
      getSysTypeTree:'sysType/getSysTypeTree',
      loadSysTypes:'sysType/loadSysTypes'
    }),
    resOwnerName(code){
      if(code==''){return '';}
      return this.resOwnerMap.get(code);
    },
    sysTypeName(code){
      if(code==''){return '';}
      return this.sysTypeMap.get(code);
    },
      async searchData() {
     this.params.resOwner1 = this.resOwner[0];
     this.params.resOwner2 = this.resOwner[1];
     this.params.resOwner3 = this.resOwner[2];
     this.params.status = 5;
     this.params.pageIndex = this.page.pageIndex;
     this.params.pageSize = this.page.pageSize;
     this.params.sysType1 = this.sysTypeList[0];
     this.params.sysType2 = this.sysTypeList[1];
     this.params.sysType3 = this.sysTypeList[2];
      try {
        const {result, status} = await apiCourse.auditList(this.params);
        if(status === 200) {
          this.pageData = result.list;
          this.page.count = result.count;
        }
      } catch (error) {
        console.log(error);
      }
    },
     viewTopic(row) {
      this.examin.detailType = row.type;
      this.examin.examineId = row.id;
      this.examin.examineName = row.name;
      this.showDetails = true;
    },
    toExamine(row) {
      this.detailType = row.type;
      this.dialogVisible = true;
      apiAudit.page(1,row.id).then(res=>{
          if (res.status === 200) {
             this.inviteTeacher.list = res.result;
          } else {
            this.$message.error(res.message);
          }
      })
    },
    handleSizeChange(val) {
      this.page.pageSize = val;
      this.page.pageIndex = 1;
      this.searchData();
    },
    handleCurrentChange(val) {
      this.page.pageIndex = val;
      this.searchData();
    },
  }
};
</script>

<style lang="scss" scoped>
.list-wu{
  text-align: center;
  margin: 40px;
  color: #333;
}
.course-types {
  display: flex;
  justify-content: center;
  padding: 15px;

  .course-type {
    margin: 10px;
    text-align: center;
    padding: 5px;
    cursor: pointer;
    img {
      width: 110px;
      height: 110px;
      
    }
    .info {
      padding-top: 10px;
    }
  }
  .choose {
    border: 2px solid #008000;
  }
}

.el-aside {
  padding: 5px 10px;
}
.cctree {
  .cctree-chapter {
    .cctree-chapter-name {
      border-bottom: 1px solid #dddddd;
    }
    .cctree-chapter-cells {
      margin: 0px;
      list-style-type: circle;
      padding: 0px;
      .cctree-chapter-cell {
        line-height: 30px;
        list-style-type: circle;
        padding-left: 25px;
      }
    }
  }
}
</style>
