<template>
  <div class="app-container">
    <el-row>
      <!--考试数据-->
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
          <el-form-item label="考试名称" prop="examCollectionName">
            <el-input
              v-model="queryParams.examCollectionName"
              placeholder="请输入考试名称"
              clearable
              style="width: 150px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="考试时间">
            <el-date-picker
              v-model="dateRange"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="模拟器型号" prop="simType">
            <el-select
              v-model="queryParams.simType"
              placeholder="模拟器型号"
              clearable
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            >
              <el-option
                v-for="dict in dict.type.sim_sim_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <!-- <el-form-item label="考试状态" prop="status">
            <el-select
              v-model="queryParams.status"
              placeholder="考试状态"
              clearable
              style="width: 150px"
            >
              <el-option
                v-for="dict in dict.type.sys_normal_disable"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item> -->
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="userList" >
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="编号" align="center" key="realExam.examId" prop="realExam.examId" v-if="columns[0].visible" width="80"/>
          <el-table-column label="考试名称" align="center" key="realExamCollection.examCollectionName" prop="realExamCollection.examCollectionName" v-if="columns[1].visible" :show-overflow-tooltip="true" />
          <el-table-column label="考试时间" align="center" key="realExamCollection.kaoshiTime" prop="realExamCollection.kaoshiTime" v-if="columns[3].visible" :show-overflow-tooltip="true" >
            <template slot-scope="scope">
              <span>{{scope.row.realExamCollection.startTime}}</span> ~  <span>{{scope.row.realExamCollection.endTime}}</span>
            </template>
          </el-table-column>
          <el-table-column label="模拟器类型" align="center" key="realExamCollection.simType" prop="realExamCollection.simType" v-if="columns[4].visible" :show-overflow-tooltip="true" >
            <template slot-scope="scope">
                <dict-tag class="text-navy" :options="dict.type.sim_sim_type" :value="scope.row.realExamCollection.simType"/>
            </template>
          </el-table-column>
          <el-table-column label="创建老师" align="center" key="realExamCollection.createBy" prop="realExamCollection.createBy" v-if="columns[4].visible" :show-overflow-tooltip="true" width="100" />
          <el-table-column label="考试状态" align="center" key="realExamCollection.examCollectionState" v-if="columns[5].visible" width="100">
            <template slot-scope="scope">
              <el-switch
                v-model="scope.row.realExamCollection.examCollectionState"
                active-value="2"
                inactive-value="3"
                disabled
              ></el-switch>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            width="160"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-thumb"
                @click="handleInto(scope.row)" 
              >进入</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
    </el-row>

  
  </div>
</template>
<script>
import { examStudentList,examStudentGet,examStudentEnter} from "@/api/sim/exam";

export default {
  name: "Exam",
  dicts: ['sim_sim_type'],
  data() {
    return {
      user: {},
      multipleSelection: [],
      selectedEquip:'',
      tableData:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      userList: null,
      // 弹出层标题
      title: "",
      // 部门树选项
      deptOptions: undefined,
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 表单参数
      form: {
        startTime:'',
        endTime:'',
      },
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 列信息
      columns: [
        { key: 0, label: `编号`, visible: true },
        { key: 1, label: `考试名称`, visible: true },
        { key: 2, label: `考试时间`, visible: true },
        { key: 3, label: `模拟器类型`, visible: true },
        { key: 4, label: `考试状态`, visible: true },
        { key: 5, label: `创建老师`, visible: true },
      ],
      // 表单校验
      rules: {
      }
    };
  },
  watch: {
  },
  created() {
    this.getList();
    //this.getDeptTree();
    this.getConfigKey("sys.user.initPassword").then(response => {
      this.initPassword = response.msg;
    });
  },
  methods: {
    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
          console.log(row.ids+'###')
          console.log(row.name+'@@@')
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionRow(val) {
      this.multipleSelection = val;
    },
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      examStudentList().then(response => {
          this.userList = response.rows;
          this.total = response.total;
          this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.form = {
        userId: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.$refs.tree.setCurrentKey(null);
      this.handleQuery();
    },
    /** 进入操作 */
    handleInto: function(row) {
      const examId = row.realExam.examId;
      console.log(examId)
      examStudentEnter(examId).then(response => {
        if(response.code='200'){
          this.$router.push("/people/exam-exam1/examid/" + examId);
        }
          //将返回值注释
          // this.userList = response.rows;
          // this.total = response.total;
          // this.loading = false;
          // this.$router.push("/people/exam-exam1/examid/" + examId);
      });
      // this.$router.push("/people/exam-exam1/examid/" + userId);
    },
  }
};
</script>
