<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :xs="24">
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-refresh"
              size="mini"
              @click="refreshTable1"
            >刷新 </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
            >批量确认已送</el-button>
          </el-col>
        </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="userId" prop="userId" v-if="columns[0].visible" />
          <el-table-column label="更换件" align="center" key="className" prop="className" v-if="columns[1].visible" :show-overflow-tooltip="true" />
          <el-table-column label="学员姓名" align="center" key="majorName" prop="majorName" v-if="columns[2].visible" :show-overflow-tooltip="true" />
          <el-table-column label="状态" align="center" key="remark" prop="remark1" v-if="columns[3].visible" :show-overflow-tooltip="true" />
          <el-table-column label="申请时间" align="center" prop="createTime" v-if="columns[4].visible" width="160">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime) }}</span>
            </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-position"
                @click="handleUpdate(scope.row)"
              >已送</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-finished"
                @click="handleDelete(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-col>
    </el-row>

    <el-row style="margin-top: 2%;">
      <el-col>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-refresh"
              size="mini"
              @click="refreshTable1"
            >刷新</el-button>
          </el-col>
        </el-row>
        <el-table v-loading="loading" :data="tableArr1" >
          <el-table-column label="座号" align="center" key="xuehao" prop="zuohao" v-if="tab_columns[0].visible" />
          <el-table-column label="模拟器状态" align="center" key="className" prop="monitype" v-if="tab_columns[1].visible" :show-overflow-tooltip="true" >
            <template scope="scope">
              <span v-if="scope.row.monitype==='就绪'" style="color: green">就绪</span>
              <span v-else-if="scope.row.monitype==='离线'" style="color: red">离线</span>
            </template>
          </el-table-column>
          <el-table-column label="学员学号" align="center" key="majorName" prop="xuehao" v-if="tab_columns[2].visible" :show-overflow-tooltip="true" />
          <el-table-column label="学员姓名" align="center" key="remark" prop="xingming" v-if="tab_columns[3].visible" :show-overflow-tooltip="true" />
          <el-table-column label="考试状态" align="center" prop="kaoshitype" v-if="tab_columns[4].visible" width="160">
            <template scope="scope">
              <span v-if="scope.row.kaoshitype==='已交卷'" style="color: green">已交卷</span>
              <span v-else-if="scope.row.kaoshitype==='未登录'" style="color: red">未登录</span>
              <span v-else-if="scope.row.kaoshitype==='已登录'" style="color: blue">已登录</span>
            </template>
          </el-table-column>
          <el-table-column label="考试成绩" align="center" prop="chengji" v-if="tab_columns[5].visible" width="160"></el-table-column>
          <el-table-column label="出题题目" align="center" prop="timu" v-if="tab_columns[6].visible" width="160"></el-table-column>
          <el-table-column label="故障现象" align="center" prop="xianxiang" v-if="tab_columns[7].visible" width="160"></el-table-column>
          <el-table-column label="可能原因" align="center" prop="reason" v-if="tab_columns[8].visible" width="160"></el-table-column>
          <el-table-column label="故障部位" align="center" prop="buwen" v-if="tab_columns[9].visible" width="160"></el-table-column>
          <el-table-column label="排除方法" align="center" prop="fangfa" v-if="tab_columns[10].visible" width="160"></el-table-column>
          <el-table-column label="修复结论" align="center" prop="jielun" v-if="tab_columns[11].visible" width="160"></el-table-column>
        </el-table>
      </el-col>
    </el-row>
    <div slot="footer" style="margin-top: 2%; text-align: center;">
      <el-button type="primary">关闭</el-button>
    </div>

  </div>
</template>
<style>
.borderless-input_defen {
  border: none; 
  /* 移除边框 */
  outline: none; /* 移除点击输入框时浏览器自带的轮廓线 */
  text-align: center;
}
.box {
  width: 100%;
  height: 40px;
  display: flex;
  border-left: 1px solid #e9e9e9;
  border-top: 1px solid #e9e9e9;
  }
  .box1{
  width: 100%;
  height: 40px;
  display: flex;
  border-left: 1px solid #e9e9e9;
  border-top: 1px solid #e9e9e9;
  }
.content1 {
  width: 80%;
  height: 40px;
  line-height: 40px;
  text-align: center;
  background-color: #fafafa;
  border-right: 1px solid #e9e9e9;
  border-bottom: 1px solid #e9e9e9;
  color:green;
  font-size: 14px;
}
.content11 {
  width: 199px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  background-color: #fafafa;
  border-right: 1px solid #e9e9e9;
  border-bottom: 1px solid #e9e9e9;
  color: green;
  font-size: 14px;
}
.content2 {
  width: 60%;
  height: 40px;
  line-height: 40px;
  text-align: center;
  background-color: #fff;
  border-right: 1px solid #e9e9e9;
  border-bottom: 1px solid #e9e9e9;
  /* color: #b0b0b2; */
  font-size: 14px;
}
.content12 {
  width: 147px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  background-color: #fff;
  border-right: 2px solid #e9e9e9;
  border-bottom: 1px solid #e9e9e9;
  /* color: #b0b0b2; */
  font-size: 14px;
}
</style>
<script>
import { listStudent, getStudent, delStudent, addStudent, updateStudent } from "@/api/sim/student";
import { getToken } from "@/utils/auth";

export default {
  name: "User",
  dicts: ['sys_normal_disable', 'sys_user_sex'],
  data() {
    return {
      tableArr1: [{
          zuohao: '01',
          monitype: '就绪',
          xuehao: '2024001',
          xingming: '张三',
          kaoshitype: '未登录',
          chengji: '80',
        },
        {
          zuohao: '02',
          monitype: '离线',
          xuehao: '2024001',
          xingming: '李四',
          kaoshitype: '已登录',
          chengji: '80',
        },{
          zuohao: '03',
          monitype: '就绪',
          xuehao: '2024001',
          xingming: '张',
          kaoshitype: '已交卷',
          chengji: '80',
        },{
          zuohao: '04',
          monitype: '离线',
          xuehao: '2024001',
          xingming: '王',
          kaoshitype: '剩余时间',
          chengji: '80',
        },
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      userList: null,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 部门名称
      deptName: undefined,
      // 默认密码
      initPassword: undefined,
      // 日期范围
      dateRange: [],
      // 岗位选项
      postOptions: [],
      // 角色选项
      roleOptions: [],
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: undefined,
        phonenumber: undefined,
        status: undefined,
        deptId: 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 }
      ],
      tab_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 },
        { key: 11, label: `修复结论`, visible: true },
      ],


    };
  },
  watch: {
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val);
    }
  },
  created() {
    this.getList();
    // this.getDeptTree();
    this.getConfigKey("sys.user.initPassword").then(response => {
      this.initPassword = response.msg;
    });
  },
  methods: {
    refreshTable1(){
      this.loading = true;
      listStudent(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.userList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      listStudent(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.userList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        userId: undefined,
        deptId: undefined,
        userName: undefined,
        nickName: undefined,
        password: undefined,
        phonenumber: undefined,
        email: undefined,
        sex: 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);
    },
    // 多选框选中数据
    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>