<style>
  .Exam_PaperName {
    width: 300px;
    display: inline;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .Exam_PaperName i {
    font-size: 18px;
  }

  .examPaper .el-table th {
    background-color: #F5F6F7;
  }

  .examPNav {
    margin: 10px 0;
    color: #3A8BFF;
    font-size: 12px;
  }

  .examPNav span {
    cursor: pointer;
  }

  .examPNav span:hover {
    text-decoration: underline;
  }

  .lastExam {
    cursor: default !important;
    pointer-events: none;
  }

  .ExamPaper_Sysuser_Date .el-range-editor .el-range-input {
    background-color: transparent;
  }

  .ExamPaper_Sysuser_Date .el-range-editor.el-input__inner {
    background-color: transparent;
  }

</style>
<!--试卷库管理-->
<template>
  <div class="page-body">
    <div class="page-search row items-center">
      <div class="col row wrap q-mr-lg q-col-gutter-md">
        <div class="col-3">
          <q-input @change="getList" clearable filled v-model="msg.PaperName" @clear="getList" maxlength="20"
            label="输入试卷名称、组卷人查找" />
        </div>
        <div class="col-3 ExamPaper_Sysuser_Date">
          <q-field filled>
             <template v-slot:control>
              <el-date-picker v-model="dateTimeList" @change="refreshPage" value-format="yyyy-MM-dd" type="daterange" style="border:none;" range-separator="至"
                 start-placeholder="开始时间"  end-placeholder="结束时间"></el-date-picker>       
            </template>
          </q-field>
        </div>
        <div class="col-3">
          <q-select @input="refreshPage" clearable filled v-model="msg.QExamineStatus" :options="auditStatusList"
            emit-value map-options label="审核状态" />
        </div>
        <div class="col-3">
          <q-select v-model="msg.QCreateBy" :options="EmployeeList" filled use-input label="创建人" @input="refreshPage"
            clearable option-label="EmployeeName" option-value="Id" ref="EmployeeName" class="col-6" emit-value
            map-options @filter="filterFn">
            <template v-slot:no-option>
              <q-item>
                <q-item-section class="text-grey">
                  未找到相关数据
                </q-item-section>
              </q-item>
            </template>
          </q-select>
        </div>
      </div>
      <div class="page-option">
        <q-btn color="accent" size="sm" v-if="IsCreateFolder" class="q-mr-md" label="新增文件夹"
          @click="showExamFolder(null)" />
        <q-btn-dropdown flat size="xs" color="dark" label="新增试卷" v-if="IsCreatePaper" style="margin-left:10px;">
          <q-list>
            <q-item clickable v-close-popup @click="CreatePaper()">
              <q-item-section>
                <q-item-label>智能组卷</q-item-label>
              </q-item-section>
            </q-item>
            <q-item clickable v-close-popup @click="goExameEdit(null)">
              <q-item-section>
                <q-item-label>手动组卷</q-item-label>
              </q-item-section>
            </q-item>
          </q-list>
        </q-btn-dropdown>
      </div>
    </div>
    <div class="page-content examPaper">
      <exampaperlist :dataList="dataList" ref="examPaper" :msg="msg" :navList="navList" :loading="loading"
        @success="refreshPage"></exampaperlist>
      <q-pagination class="full-width justify-end" :value="msg.pageIndex" color="primary" :max="pageCount" :input="true"
        @input="changePage" />
    </div>
  </div>
</template>
<script>
  import exampaperlist from '../../components/exam/exampaperlist'
  import {
    GetPaperPage
  } from '../../api/teacher/index';
  import {
    queryEmployee
  } from '../../api/users/user'; //获取员工
  //获取校区列表
  export default {
    components: {
      exampaperlist
    },
    meta: {
      title: "考试管理"
    },
    data() {
      return {
        data: [],
        msg: {
          pageIndex: 1,
          pageSize: 10,
          rowsPerPage: 10,
          PaperName: '', //题库名
          ParentId: 0,
          QStartTime: "", //开始时间
          QEndTime: "", //结束时间
          QExamineStatus: '', //审核状态
          QCreateBy: '' //创建人
        },
        pageCount: 0,
        loading: false,
        dataList: [],
        navList: [], //导航列表
        IsCreateFolder: false, //是否试卷创建文件夹权限
        IsCreatePaper: false, //是否创建试卷权限
        currentUserInfo: {}, //当前登录用户
        dateTimeList: [], //选择时间
        auditStatusList: [{
            value: 0,
            label: "草稿"
          },
          {
            value: 1,
            label: "审核中"
          },
          {
            value: 2,
            label: "正常"
          },
          {
            value: 3,
            label: "驳回"
          },
          {
            value: 6,
            label: "作废"
          }
        ],
        EmployeeList: [], //员工列表
        AllemployeeList: [], //所有员工列表
      }
    },
    created() {
      let userinfo = this.getLocalStorage();
      this.currentUserInfo = userinfo;
      userinfo.ActionMenuList.map(x => { //判断权限
        if (x.FunctionCode == "Paper_CreateManager") { //判断是否试卷创建文件夹权限
          this.IsCreateFolder = true;
        }
        if (x.FunctionCode == "Paper_CreatePaper") { //判断是否有创建试卷权限
          this.IsCreatePaper = true;
        }
      })
    },
    mounted() {
      this.getEmployee();
      this.getList();
    },
    methods: {
      //筛选员工
      filterFn(val, update) {
        update(() => {
          if (val === '') {
            this.EmployeeList = JSON.parse(JSON.stringify(this.AllemployeeList))
          } else {
            const needle = val.toLowerCase();
            this.EmployeeList = this.AllemployeeList.filter(v => v.EmployeeName.toLowerCase().indexOf(needle) > -1);
          }
        })
      },
      //获取业务员
      getEmployee() {
        var qMsg = {
          Dept_Id: 0
        }
        queryEmployee(qMsg).then(res => {
          if (res.Code == 1) {
            this.EmployeeList = res.Data;
            this.AllemployeeList = res.Data;
            let obj = {
              Id: 0,
              EmployeeName: '不限'
            }
            this.EmployeeList.unshift(obj);
          }
        })
      },
      //翻页
      changePage(val) {
        if (val != this.msg.pageIndex) {
          this.msg.pageIndex = val;
          this.getList()
        }
      },
      getPaperChild(Id) {
        this.msg.ParentId = Id;
        this.refreshPage();
      },
      //获取菜单分页列表
      getList() {
        if (this.dateTimeList && this.dateTimeList.length > 0) {
          this.msg.QStartTime = this.dateTimeList[0];
          this.msg.QEndTime = this.dateTimeList[1];
        } else {
          this.msg.QStartTime = '';
          this.msg.QEndTime = '';
        }
        this.loading = true;
        this.dataList = [];
        GetPaperPage(this.msg).then(res => {
          this.loading = false;
          if (res.Code == 1) {
            this.dataList = res.Data.pageModel.PageData;
            this.pageCount = res.Data.pageModel.PageCount;
            this.navList = res.Data.navList;
          }
        }).catch(() => {
          this.loading = false
        })
      },
      //刷新页面
      refreshPage() {
        this.getList();
      },
      //点击编辑 跳转
      goExameEdit(item) {
        var obj = {
          Id: 0,
          ToParentId: this.msg.ParentId
        }
        if (item) {
          obj.Id = item.PaperId;
          obj.ToParentId = item.ParentId;
        }
        this.OpenNewUrl('/exam/paperEdit', obj)
      },
      //新增修改文件夹
      showExamFolder(obj) {
        this.$refs.examPaper.showExamFolder(obj);
      },
      //创建试卷
      CreatePaper() {
        this.OpenNewUrl('/exam/paperCreate', {
          ToParentId: this.msg.ParentId
        })
      }
    }
  }

</script>
<style lang="sass">
  @import url('~assets/css/table.sass')

</style>
