<template>
  <div class="review-access-wrap">
    <bread-crumb :curmbFirst="curmbFirst" :curmbSecond="curmbSecond"></bread-crumb>

    <div class="review-access screenSet" id="screenSet">
      <div class="header-title">外部资源管理</div>
      <el-form ref="form" :model="searchForm" label-width="100px" class="search-form-wrap">
        <el-row>
          <el-form-item label="课程名称：" class="search-item" >
            <el-input v-model="searchForm.courseName" size="small" class="form-width" placeholder="请输入课程名称"></el-input>
          </el-form-item>
          <el-form-item label="状态：" class="search-item">
            <el-select v-model="searchForm.checkStatus" placeholder="请选择" size="small" class="form-width">
              <el-option v-for="(item, index) in checkStatusList" :key="index" :label="item.name" :value="item.value"></el-option>
            </el-select>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="创建人：" class="search-item" >
            <el-input v-model="searchForm.createdDoctorName" size="small" class="form-width" placeholder="请输入创建人"></el-input>
          </el-form-item>
          <el-form-item label="创建日期：" class="search-item">
            <el-date-picker
              v-model="searchForm.createdTime"
              type="date"
              size="small"
              class="form-width"
              value-format="yyyy-MM-dd"
              placeholder="请选择创建日期">
            </el-date-picker>
            <!-- <span style="color: #DCDFE6;">～</span>
            <el-date-picker
              v-model="searchForm.endTime"
              type="datetime"
              size="small"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="请选择结束时间">
            </el-date-picker> -->
          </el-form-item>          
          <el-form-item class="btn-list">
            <el-button @click="search()" type="primary" size="small">查询</el-button>
            <el-button @click="reset" size="small">重置</el-button>
          </el-form-item>
        </el-row>
      </el-form>
      <el-table :data="tableList" border style="width: 100%">
        <el-table-column align="center" prop="courseName" label="课程名称"></el-table-column>
        <el-table-column align="center" prop="subjectName" label="课程分类" ></el-table-column>
        <el-table-column align="center" prop="createdDoctorName" label="创建人" ></el-table-column>
        <el-table-column align="center" prop="createdHospitalName" label="所属机构" ></el-table-column>
        <el-table-column align="center" prop="createdTime" label="创建日期" ></el-table-column>
        <el-table-column align="center" prop="checkStatus" label="审核状态" ></el-table-column>
        <el-table-column align="center" label="操作">
          <template slot-scope="scope">
            <el-button @click="viewOrAudit(scope.row)" type="text" size="small"><span style="color: #449284;">查看</span></el-button>
          </template>
        </el-table-column>
        <div slot="empty">
          <div class="table-empty">
            <img src="../../assets/image/no-content1.png">
            <p>没有查询到外部资源</p>
          </div>
        </div>
      </el-table>

      <div class="pagination">
        <el-pagination
          class="pagination-style"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :total="totalRows"
          :current-page="searchForm.pageNo"
          :page-sizes="[15, 30, 50, 100]"
          :page-size="searchForm.pageSize"
          layout="total, sizes, prev, pager, next, jumper">
        </el-pagination>
      </div>
    </div>

    <!-- 拒绝原因 -->
    <el-dialog
      title="拒绝原因"
      @close="hideAuditForm"
      :visible.sync="addEditVisible"
      :close-on-click-modal="false"
      width="600px"
      center>
      <el-form ref="auditForm" :model="auditForm" label-width="120px">
        <el-form-item label="拒绝原因：">
          <el-radio-group v-model="auditForm.auditRadio">
            <div style="padding-top: 12px;">
              <el-radio label="含有政治类、医疗健康、社会事件类不实信息" value="1"></el-radio>
            </div>
            <div style="padding-top: 16px;">
              <el-radio label="含有欺诈，色情，诱导、违法犯罪非法字符" value="2"></el-radio>
            </div>
            <div style="padding-top: 16px;">
              <el-radio label="其他" value="3"></el-radio>
            </div>
          </el-radio-group>
          <el-input type="textarea" v-model="auditForm.desc" maxlength="25" style="width: 310px;margin-top: 10px;"></el-input>
          <span class="word-num">{{(auditForm.desc).replace(/\s+/g,"").length}}/25</span>
        </el-form-item>        
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="hideAuditForm">取 消</el-button>
        <el-button type="primary" @click="auditAction()">确 定</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
  import { openLoading, closeLoading } from "../../utils/utils";
  import BreadCrumb from "../../components/breadcrumb.vue";
  import * as commonUtil from "../../utils/utils";
  import {
    handleDeleteReq,
  } from '@/utils/cme/cmeApi'

  export default {
    data() {
      return {
        curmbFirst: "CME",
        curmbSecond: "外部资源管理",
        totalRows: 0,
        addEditVisible: false,
        isAdd: true,            // 新增或编辑状态：新增 true; 编辑 false 
        deleteVisible: false,
        currentRow: null,       // 当前行数据
        searchForm: {
          courseName: '',
          checkStatus: -1,
          createdDoctorName: '',
          createdTime: '',
          // createdHospitalName: '',
          // subjectName: '',
          pageNo: 1,
          pageSize: 15,
        },
        auditForm: {
          auditRadio: '',
          desc: '',
        },
        checkStatusList: [
          {
            name: '全部状态',
            value: -1
          },{
            name: '待审核',
            value: 0
          },{
            name: '通过',
            value: 1
          },{
            name: '拒绝',
            value: 2
          }
        ],  
        tableList: [],
      }
    },

    components: {
      BreadCrumb,
    },

    created() {
      this.search();
    },
    mounted() {
      commonUtil.resizeHeight();
    },
    methods: {

      // 查询列表
      search() {
        let searchForm = Object.assign({}, this.searchForm);
        let createdTime = searchForm.createdTime;
        if(createdTime) {
          searchForm.createdTime = new Date(searchForm.createdTime).getTime();
        } else {
          searchForm.createdTime = '';
        }
        this.GET("contents/course/custom/check/v1/list", searchForm).then(res => {
          if (res.code == "000000") {
            this.tableList = res.data && res.data.courseList || [];
            this.totalRows = res.data.totalSize || 0;
            // this.protocolInfo = res.data;
          }
        });
      },
      
      // 重置
      reset() {
        this.searchForm = {
          courseName: '',
          checkStatus: -1,
          createdDoctorName: '',
          createdTime: '',
          // createdHospitalName: '',
          // subjectName: '',
          pageNo: 1,
          pageSize: 15,
        };
      },
      
      // 查看 每种查看的方式不一样
      viewOrAudit(row) {
        console.log(row);
        this.$router.push({
          path: 'audit-custom-course',
          query: {
            courseId: row.courseId
          }
        })
      },
   
      auditAction() {
        console.log(row);
      },

      // 重置
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },

      hideAuditForm() {
        this.addEditVisible = false;
        this.resetForm('auditForm');
        this.auditForm = {
          auditRadio: '',
          desc: '',
        };
      },


      handleSizeChange(val){
        this.searchForm.pageSize = val;
        this.search();
      },
      
      // 切换当前页
      handleCurrentChange(val){
        this.searchForm.pageNo = val;
        this.search();
      },
    },

  }
</script>  

<style lang="scss">
  .review-access-wrap{
    .review-access{
      padding: 10px;
      background: #fff;
      .el-button--small{
        font-size: 14px;
      }
      .header-title {
        padding: 10px 12px 20px;
        font-size: 14px;
        color: #606266;
        border-bottom: 1px solid #efefef;
      }
      .search-form-wrap{
        padding: 25px 0 20px;
        overflow: hidden;
        // border-bottom: 1px dashed #efefef;
      }
      .search-item{
        float: left;
      }
      .btn-list{
        float: right;
        .el-form-item__content{
          margin-left: 0 !important;
        }
      }
      .new-add{
        float: right;
        margin: 10px 0 20px;
      }
      .table-empty {
        img {
          width: 100px;
        }
        p {
          margin-top: -50px;
        }
      }
    }
  }
</style>