<template>
  <div class="app-container">
    <!-- <div class="score_list">成绩列表</div> -->
    <el-descriptions title="成绩列表" :column="3" ></el-descriptions>
    <el-row :gutter="20">
      <!--用户数据1-->
      <el-col :xs="24">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
          <el-form-item label="学员学号" prop="className">
            <el-input
              v-model="queryParams.className"
              placeholder="请输入学员学号"
              clearable
              style="width: 150px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>

          <el-form-item label="学员姓名" prop="className">
            <el-input
              v-model="queryParams.className"
              placeholder="请输入学员姓名"
              clearable
              style="width: 150px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>

          <el-form-item label="班级名称" prop="className">
            <el-input
              v-model="queryParams.className"
              placeholder="请输入班级名称"
              clearable
              style="width: 200px"
              @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="考试时间">
            <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>
            <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">
          <!-- <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['system:user:add']"
            >新增</el-button>
          </el-col> -->
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
              :disabled="single"
              @click="handleUpdate"
            >修改</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              @click="handleExport"
            >导出</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-view"
              size="mini"
              :disabled="single"
              @click="handleView"
            >成绩详情</el-button>
          </el-col>
          <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="userId" prop="userId" v-if="columns[0].visible" />
          <el-table-column label="学员姓名" align="center" key="xuehao" prop="xuehao" v-if="columns[1].visible" />

          <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="className" prop="className" v-if="columns[3].visible" :show-overflow-tooltip="true" />
          <el-table-column label="考试名称" align="center" key="majorName" prop="majorName" v-if="columns[4].visible" :show-overflow-tooltip="true" />
          <el-table-column label="成绩" align="center" key="remark" prop="remark" v-if="columns[5].visible" :show-overflow-tooltip="true" />
          <el-table-column label="考试开始时间" align="center" prop="createTime" v-if="columns[6].visible" width="160" />
          <el-table-column label="考试结束时间" align="center" prop="createTime" v-if="columns[7].visible" width="160" />
          <el-table-column label="学员交卷时间" align="center" prop="createTime" v-if="columns[9].visible" width="160">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="交卷超时间" align="center" prop="createTime" v-if="columns[8].visible" width="160" />

          <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-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['system:user:edit']"
              >修改</el-button>
              <!-- <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['system:user:remove']"
              >删除</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>

    <!-- <div class="score_list">成绩分析</div> -->
    <el-descriptions title="成绩分析" :column="3" border>
      <el-descriptions-item label="平均成绩">88</el-descriptions-item>
      <el-descriptions-item label="最高成绩">90</el-descriptions-item>
      <el-descriptions-item label="最低成绩">30</el-descriptions-item>
    </el-descriptions>

    <!-- <div class="score_list">错误率统计</div> -->
    <el-descriptions title="错误率统计" :column="3" border style="margin-top: 20px"></el-descriptions>
    <el-table
      :data="tableData" 
      border
      style="width: 100%;margin-top:1%">
      <el-table-column 
        prop="name"
        label="模拟器A">
      </el-table-column>
      <el-table-column 
        prop="name1"
        label="">
      </el-table-column>
      <el-table-column 
        prop="name2" 
        label="模拟器B">
      </el-table-column>
      <el-table-column 
        prop="name3" 
        label="">
      </el-table-column>

      <el-table-column 
        prop="name4"
        label="模拟器C">
      </el-table-column>
      <el-table-column 
        prop="name5" 
        label="">
      </el-table-column>
    </el-table>

    <!-- 修改对话框 -->
    <el-dialog :title="title" :visible.sync="dialogVisible1" width="40%" append-to-body style="margin-top: -1%;" >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-col v-for="(item, index) in tableArr" :key="index">
          <div class="box">
            <div class="content1">{{ item.key }}</div>
            <div class="content2">{{ item.value1}}</div>
            <!-- <div class="content2">{{ item.value2}}</div>
            <div class="content2">{{ item.value3}}</div>
            <div class="content2">{{ item.value4}}</div>
            <div class="content2">{{ item.value5}}</div>
            <div class="content2">{{ item.value6}}</div>
            <div class="content2">{{ item.value7}}</div>
            <div class="content2">{{ item.value8}}</div>
            <div class="content2">{{ item.value9}}</div>
            <div class="content2">{{ item.value10}}</div> -->
          </div>
        </el-col>
        <el-table
          :data="tableArr1"
          border
          style="width: 100%;margin-top:1%;text-align: center;">
          <el-table-column
            prop="biaozhun"
            label="评分标准"
            width="390px">
          </el-table-column>
          <el-table-column
            prop="defen"
            label="得分">
            <template >
              <input class="borderless-input_defen" name="duibie" style=""/>
            </template>
          </el-table-column>
        </el-table>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>

    <!---成绩详情-->
    <el-dialog :title="title" :visible.sync="dialogVisible2" style="margin-top: -2%;" width="55%" append-to-body>
      <div style="font-size:22px;text-align: center;display:flex;margin-left: 20%;">
        <template>
          <div style="text-align:left;"> 20
            <input class="borderless-input" name="duibie"/>
          </div>
          <div style="text-align:left;"> 年
            <input class="borderless-input" name="nickname"/>
          </div>
          <div style="text-align:left;">装备维修评分标准
          </div>
        </template>
      </div>
      <el-descriptions :column="3" border style="margin-top: 1%">
        <el-descriptions-item label="考号">88</el-descriptions-item>
        <el-descriptions-item label="姓名">90</el-descriptions-item>
        <el-descriptions-item label="单位">30</el-descriptions-item>
        <el-descriptions-item label="规定作业时间">30</el-descriptions-item>
        <el-descriptions-item label="实际作业时间">30</el-descriptions-item>
        <el-descriptions-item label="成绩">30</el-descriptions-item>
      </el-descriptions>
      <el-table
        :data="tableData2"
        :span-method="arraySpanMethod"
        border
        style="width: 100%;margin-top:1%;">
        <el-table-column
          prop="id"
          label="序号"
          width="180">
        </el-table-column>
        <el-table-column
          prop="name"
          label="评分标准">
        </el-table-column>
        <el-table-column
          prop="name2"
          label="扣分">
        </el-table-column>
        <el-table-column
          prop="name3"
          label="备注">
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>
<style>
.custom-table .el-table__row {
  padding: 5px 0; /* 根据需要调整padding的值来设置行间距 */
}
.borderless-input_defen {
  border: none; /* 移除边框 */
  outline: none; /* 移除点击输入框时浏览器自带的轮廓线 */
}

.borderless-input {
  border: none; /* 移除边框 */
  border-bottom: 1px solid #dfe6ec; /* 下划线样式 */
  outline: none; /* 移除点击输入框时浏览器自带的轮廓线 */
  padding-bottom: 5px; /* 添加一些填充以便于点击区域 */
}
.score_list{
  font-size: 16px;
  color: #606266;
  margin: 5px;
}
.box {
  width: 100%;
  height: 40px;
  display: flex;
  border-left: 1px solid #e9e9e9;
  border-top: 1px solid #e9e9e9;
  }
.content1 {
  width: 70%;
  height: 40px;
  line-height: 40px;
  text-align: center;
  background-color: #fafafa;
  border-right: 1px solid #e9e9e9;
  border-bottom: 1px solid #e9e9e9;
  color: #333;
  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;
}

</style>
<script>
import { listStudent, getStudent, delStudent, addStudent, updateStudent } from "@/api/sim/student";
import { getToken } from "@/utils/auth";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "User",
  dicts: ['sys_normal_disable', 'sys_user_sex','sim_sim_type'],
  components: { Treeselect },
  data() {
    return {
      tableArr: [
          {
            key: "座号",
            value1: "坐席1",
          },
          {
            key: "姓名",
            value1: "张",
          },
          {
            key: "学号",
            value1: "2023004",
          },
          {
            key: "班级",
            value1: "二班",
          },
          {
            key: "考试名称",
            value1: "模拟考试",
          },
          // {
          //   key: "一.排除故障(75分)",
          //   value1: "50",
          // },
          // {
          //   key: "故障一未排除扣25分",
          //   value1: "50",
          // },
          // {
          //   key: "故障二未排除扣25分",
          //   value1: "50",
          // },
          // {
          //   key: "故障三未排除扣25分",
          //   value1: "50",
          // },
        ],
        tableArr1: [{
          biaozhun: '一.排除故障(75分)',
          defen: '',
        }, {
          biaozhun: '故障一未排除扣25分',
          defen: '',
        },{
          biaozhun: '故障二未排除扣25分',
          defen: '',
        },{
          biaozhun: '故障三未排除扣25分',
          defen: '',
        },
        {
          biaozhun: '二.维修报告表(15分)',
          defen: '',
        }, {
          biaozhun: '故障现象少写或错写1条扣1分',
          defen: '',
        },{
          biaozhun: '可能原因少写或错写1条扣1分',
          defen: '',
        },{
          biaozhun: '故障部位少写或错写1条扣1分',
          defen: '',
        },{
          biaozhun: '排除方法少写或错写1条扣1分',
          defen: '',
        },{
          biaozhun: '修复结论错扣2分',
          defen: '',
        },{
          biaozhun: '三.维修时间(10分)',
          defen: '',
        },{
          biaozhun: '按每超过1分钟扣1分的比例扣分',
          defen: '',
        }
        ],
        tableData: [{
          name:'故障名称',
          name1: '错误率',
          name2: '故障名称',
          name3: '错误率',
          name4: '故障名称',
          name5: '错误率',
        },{
          id:1,
          name: '80%',
          name2: '1',
          name3: '70%',
          name4: '1',
          name5: '85%'
        }, 
        {
          id:2,
          name: '70%',
          name2: '2',
          name3: '65%',
          name4: '2',
          name5: '70%%'
        }, {
          id:3,
          name: '60%',
          name2: '2',
          name3: '75%',
          name4: '3',
          name5: '79%',
        }
      ],
      tableData2: [{
          id:'一.故障排除(75分)',
        },{
          id:1,
          name: '故障一未排除扣25分',
          name2: '',
          name3: '排除',
        }, {
          id:2,
          name: '故障二未排除扣25分',
          name2: '',
          name3: '未排除',
        }, {
          id:3,
          name: '故障三未排除扣25分',
          name2: '',
          name3: '排除',
        }, {
          id:'二.维修报告表(15分)',
        },{
          id:1,
          name: '故障现象少写或错写1条扣1分',
          name2: '',
          name3: '正确',
        }, {
          id:2,
          name: '可能原因少写或错写1条扣1分',
          name2: '',
          name3: '错误',
        }, {
          id:3,
          name: '故障部位少写或错写1条扣1分',
          name2: '',
          name3: '正确',
        }, {
          id:4,
          name: '排除方法少写或错写1条扣1分',
          name2: '',
          name3: '正确',
        }, {
          id:5,
          name: '修复结论错扣2分',
          name2: '',
          name3: '正确',
        }, {
          id:'三.维修时间(10分)',
          name: '',
          name2: '',
          name3: '',
        }, {
          id:'按没超过1分钟扣1分的比例扣分',
          name: '',
          name2: '',
          name3: '',
        }, {
          id:'扣分小计',
          name: '',
          name2: '超时：',
          name3: '',
        }, {
          id:'五.成绩',
          name: '',
          name2: '-50',
          name3: '',
        }, {
          id:'说明',
          name: '',
          name2: '',
          name3: '',
        }],

      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      userList: null,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      dialogVisible1:false,
      dialogVisible2:false,
      // 部门名称
      deptName: undefined,
      // 默认密码
      initPassword: undefined,
      // 日期范围
      dateRange: [],
      // 岗位选项
      postOptions: [],
      // 角色选项
      roleOptions: [],
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/system/user/importData"
      },
      // 查询参数
      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 },
        { 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 }
      ],
      // 表单校验
      rules: {
        userName: [
          { required: true, message: "用户名称不能为空", trigger: "blur" },
          { min: 2, max: 20, message: '用户名称长度必须介于 2 和 20 之间', trigger: 'blur' }
        ],
        nickName: [
          { required: true, message: "用户昵称不能为空", trigger: "blur" }
        ],
        password: [
          { required: true, message: "用户密码不能为空", trigger: "blur" },
          { min: 5, max: 20, message: '用户密码长度必须介于 5 和 20 之间', trigger: 'blur' },
          { pattern: /^[^<>"'|\\]+$/, message: "不能包含非法字符：< > \" ' \\\ |", trigger: "blur" }
        ],
        email: [
          {
            type: "email",
            message: "请输入正确的邮箱地址",
            trigger: ["blur", "change"]
          }
        ],
        phonenumber: [
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur"
          }
        ]
      }
    };
  },
  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: {
    //首页合并
    arraySpanMethod({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0 || rowIndex === 4 || rowIndex === 10) {
        if (columnIndex === 0) {
          return [1, 4];
        } else {
          return [0, 0];
        }
      }
      //按每超时1分钟扣分的比例扣分
      if (rowIndex>10) {
        if (columnIndex === 0) {
          return [1, 2];
        }else if(columnIndex ===2){
          return [1, 3];
        } else {
          return [0, 0];
        }
      }
    },


    /** 查询用户列表 */
    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;
    },
    // 用户状态修改
    handleStatusChange(row) {
      let text = row.status === "0" ? "启用" : "停用";
      this.$modal.confirm('确认要"' + text + '""' + row.userName + '"用户吗？').then(function() {
        return changeUserStatus(row.userId, row.status);
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
      }).catch(function() {
        row.status = row.status === "0" ? "1" : "0";
      });
    },
    // 取消按钮
    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;
    },
    // 更多操作触发
    handleCommand(command, row) {
      switch (command) {
        case "handleResetPwd":
          this.handleResetPwd(row);
          break;
        case "handleAuthRole":
          this.handleAuthRole(row);
          break;
        default:
          break;
      }
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const userId = row.userId || this.ids;
      // getUser(userId).then(response => {
        // this.form = response.data;
        // this.postOptions = response.posts;
        // this.roleOptions = response.roles;
        // this.$set(this.form, "postIds", response.postIds);
        // this.$set(this.form, "roleIds", response.roleIds);
        this.dialogVisible1 = true;
        this.title = "修改成绩";
        this.form.password = "";
      // });
    },
     /** 成绩详情按钮操作 */
     handleView(row) {
      this.reset();
      // const userId = row.userId || this.ids;
      // getUser(userId).then(response => {
        // this.form = response.data;
        this.dialogVisible2 = true;
        this.title = "";
      // });
    },
    /** 提交按钮 */
    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();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const userIds = row.userId || this.ids;
      this.$modal.confirm('是否确认删除用户编号为"' + userIds + '"的数据项？').then(function() {
        return delUser(userIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/user/export', {
        ...this.queryParams
      }, `user_${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "用户导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('system/user/importTemplate', {
      }, `user_template_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    }
  }
};
</script>