<template>
  <div class="app-container">
    <el-row>
      <!--考试成绩数据-->
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="学员学号" prop="userName">
            <el-input
              v-model="queryParams.userName"
              placeholder="请输入学员学号"
              clearable
              style="width: 150px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="学员姓名" prop="userName">
            <el-input
              v-model="queryParams.userName"
              placeholder="请输入学员姓名"
              clearable
              style="width: 150px"
              @keyup.enter.native="handleQuery"
            />
          </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="userName">
            <el-input
              v-model="queryParams.userName"
              placeholder="请输入区队/班级"
              clearable
              style="width: 150px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="专业名称" prop="userName">
            <el-input
              v-model="queryParams.userName"
              placeholder="请输入专业名称"
              clearable
              style="width: 150px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="考试名称" prop="userName">
            <el-input
              v-model="queryParams.userName"
              placeholder="请输入考试名称"
              clearable
              style="width: 150px"
              @keyup.enter.native="handleQuery"
            />
          </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" @selection-change="handleSelectionChange">
          <!-- <el-table-column type="selection" width="50" align="center" /> -->
          <el-table-column label="学员学号" align="center" key="userName" prop="userName" v-if="columns[0].visible" :show-overflow-tooltip="true" />
          <el-table-column label="学员姓名" align="center" key="kaoshiTime" prop="kaoshiTime" v-if="columns[1].visible" :show-overflow-tooltip="true" />
          <el-table-column label="模拟器型号" align="center" key="simType" prop="simType" v-if="columns[2].visible" :show-overflow-tooltip="true" >
            <template slot-scope="scope">
                <dict-tag class="text-navy" :options="dict.type.sim_sim_type" :value="scope.row.simType"/>
            </template>
          </el-table-column>
          <el-table-column label="区队/班级" align="center" key="banji" prop="banji" v-if="columns[3].visible" :show-overflow-tooltip="true" />
          <el-table-column label="专业名称" align="center" key="zhuanye" prop="zhuanye" v-if="columns[4].visible" :show-overflow-tooltip="true" />
          <el-table-column label="考试名称" align="center" key="kaoshi" prop="kaoshi" v-if="columns[5].visible" :show-overflow-tooltip="true" />
          <el-table-column label="成绩" align="center" key="chengji" prop="chengji" v-if="columns[6].visible" :show-overflow-tooltip="true" />
          <el-table-column label="考试开始时间" align="center" key="kaoshi_start_time" prop="kaoshi_start_time" v-if="columns[7].visible" :show-overflow-tooltip="true" />
          <el-table-column label="考试结束时间" align="center" key="kaoshi_end_time" prop="kaoshi_end_time" v-if="columns[8].visible" :show-overflow-tooltip="true" />
          <el-table-column label="学员交卷时间" align="center" key="jiaojuan_time" prop="jiaojuan_time" v-if="columns[9].visible" :show-overflow-tooltip="true" />
          <el-table-column label="交卷超时时间" align="center" key="chaoshi_time" prop="chaoshi_time" v-if="columns[10].visible" :show-overflow-tooltip="true" />
        </el-table>
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
    </el-row>
  </div>
</template>
<style>
  .el-form-item__label{
    width: 85px !important;
  }
</style>
<script>
import { listUser, getUser, delUser, addUser, updateUser, resetUserPwd, changeUserStatus } from "@/api/system/user";
import { getToken } from "@/utils/auth";

export default {
  dicts: ['sim_sim_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      userList: null,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: undefined,
      },
      // 列信息
      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 },
        { key: 6, label: `成绩`, visible: true },
        { key: 7, label: `考试开始时间`, visible: true },
        { key: 8, label: `考试结束时间`, visible: true },
        { key: 9, label: `学员交卷时间`, visible: true },
        { key: 10, label: `交卷超时时间`, visible: true },
      ],
      // 表单校验
      rules: {
      }
    };
  },
  watch: {

  },
  created() {
    this.getList();
    //this.getDeptTree();
    // this.getConfigKey("sys.user.initPassword").then(response => {
    //   this.initPassword = response.msg;
    // });
  },
  methods: {
   
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          //将返回值注释
          this.userList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 表单重置
    reset() {
      this.form = {
        userId: undefined,
        userName: undefined,
        password: undefined,
        phonenumber: undefined,
        status: "0",
        remark: undefined,
        postIds: [],
        roleIds: []
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.queryParams.deptId = undefined;
      this.$refs.tree.setCurrentKey(null);
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.userId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
   
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.userId != undefined) {
            updateUser(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addUser(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    
  }
};
</script>