<!--违规记录列表-->
<template>
  <div class="app-container violation">
    <div class="violationPage" v-if="pageType==1">
      <div class="page-form-title-box">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" class="form-box" v-if="pageType==1">

          <el-form-item label="" prop="searchValue" label-width="60px">
            <el-input
              v-model="queryParams.searchValue"
              placeholder="姓名/学号"
              clearable
              size="small"
            />
          </el-form-item>
          <el-form-item label="" prop="deptId" label-width="80px">
            <el-select v-model="queryParams.deptId" clearable placeholder="请选择学院">
              <el-option
                v-for="dict in deptOptions"
                :key="dict.deptId"
                :label="dict.deptName"
                :value="dict.deptId"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="status" label-width="50px">
            <el-select v-model="queryParams.status" placeholder="请选择状态">
              <el-option
                v-for="dict in deptOptionsTwo"
                :key="dict.deptId"
                :label="dict.deptName"
                :value="dict.deptId"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item style="float: right;">
            <el-col :span="1.5">
              <p class="page-submit-common-style-button"
                 @click="handleAdd()"
                 style="width:120px;"
                 v-hasPermiRouter="['exam:violation:add']"
              >新增违规记录</p>
            </el-col>
          </el-form-item>
          <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" v-loading="loading" border :data="violationList" @sort-change="handleSelectionChange" v-if="pageType==1">
          <el-table-column label="姓名" align="left" prop="joinUserName" show-overflow-tooltip/>
          <el-table-column label="学号" align="left" prop="stuNo" show-overflow-tooltip/>
          <el-table-column label="学院" align="left" prop="deptName" show-overflow-tooltip/>
          <el-table-column label="违规次数" align="left" sortable="custom" prop="violationNum" show-overflow-tooltip/>
          <el-table-column label="负面清单次数" align="left" sortable="custom" prop="negativeListNum" show-overflow-tooltip/>
          <el-table-column label="黑名单次数" align="left" sortable="custom" prop="blackListNum" show-overflow-tooltip/>
          <el-table-column label="信用分" align="left" prop="creditScore" show-overflow-tooltip/>
          <el-table-column label="当前状态" align="left" prop="status" show-overflow-tooltip>
            <template slot-scope="scope">
              {{scope.row.status == 1?'正常':(scope.row.status == 2?'负面清单':(scope.row.status == 3?'黑名单':''))}}
            </template>
          </el-table-column>
          <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="200" v-if="tableButtonType">
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p"
                   @click="goPage(2,scope.row)"
                   v-hasPermiRouter="['exam:violationHistory:list']"
                >历史记录</p>
                <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)">
                  <p class="table-button-p">更多>></p>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item command="1" v-show="scope.row.status == 3"
                                      v-hasPermiRouter="['exam:blacklist:del']">移除黑名单</el-dropdown-item>
                    <el-dropdown-item command="2" v-show="scope.row.status == 1 || scope.row.status == 2"
                                      v-hasPermiRouter="['exam:blacklist:add']">加入黑名单</el-dropdown-item>
                    <el-dropdown-item command="3" v-show="scope.row.status == 2"
                                      v-hasPermiRouter="['exam:violation:del']">移除负面清单</el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
                <p class="table-button-null"></p>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <pagination :page-sizes="[20, 30, 40, 50]"
                    v-if="pageType==1"
                    v-show="total>0"
                    :total="total"
                    layout="total, prev, pager, next, sizes, jumper"
                    :page.sync="queryParams.page"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
    </div>
    <!-- 新增违规 -->
    <el-dialog :title="title" :visible.sync="open" v-if="open" width="720px" append-to-body :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="addRules" label-width="120px">
        <el-form-item label="姓名：" prop="userId">
          <el-select
            style="width:480px;"
            @change="userChange"
            v-model="form.userId"
            filterable
            remote
            placeholder="请输入至少2个字符"
            :remote-method="userSelectList"
            :loading="loading">
            <el-option
              v-for="item in optionsUser"
              :key="item.userId"
              :label="item.userName"
              :value="item.userId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学号：" style="width:600px;">
          <el-input v-model="form.stuNo" :disabled="true" placeholder="请选择学号"/>
        </el-form-item>
        <el-form-item label="学院：" style="width:600px;">
          <el-input v-model="form.deptName" :disabled="true" placeholder="请选择学院" />
        </el-form-item>
        <el-form-item label="实验室：" prop="subId" >
          <el-select
            style="width:480px;"
            v-model="form.subjectId"
            filterable
            remote
            reserve-keyword
            @change="subChange"
            placeholder="请搜索选择实验室"
            :remote-method="subSelectList">
            <el-option
              v-for="item in subOptions"
              :key="item.subId"
              :label="item.subName"
              :value="item.subId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="选择违规项" prop="reasonId">
          <el-select v-model="form.reasonId" style="width:480px;" placeholder="请选择违规项" @change="reasonChange">
            <el-option
              v-for="item in violationSiteTypeList"
              :key="item.id"
              :label="item.violationName"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="违规原因：" prop="violationReasons" style="width:600px;" v-if="form.reasonId==-1">
          <el-input
            v-model="form.violationReasons"
            placeholder="请输入违规原因"
            maxLength="50"
            >
          </el-input>
        </el-form-item>
        <el-form-item label="扣除信用分值：" prop="deductionVal" style="width:600px;" v-if="form.reasonId==-1">
          <el-input-number
            v-model="form.deductionVal"
            placeholder="请输入"
            :min="0"
            maxLength="5"
            @input="getIntegralMatchingRules">
          </el-input-number>
        </el-form-item>
        <el-form-item label="处理方式" prop="checkListTwo">
          <el-form-item label="">
            <el-checkbox-group v-model="form.checkList" style="display: inline-block;width:220px;">
              <el-checkbox label="warningStatus">警告<span style="color:#999;">（系统推送警告消息）</span></el-checkbox>
            </el-checkbox-group>
            <el-checkbox-group v-model="form.checkList" style="display: inline-block;width:160px;">
              <el-checkbox label="interviewStatus">约谈<span style="color:#999;">（线下约谈）</span></el-checkbox>
            </el-checkbox-group>
            <el-checkbox-group v-model="form.checkListTwo" style="display: inline-block;width:100px;">
              <el-checkbox label="testStatus">考试</el-checkbox>
            </el-checkbox-group>
          </el-form-item>
          <div>
            <div style="width:480px;margin-right:20px;display: flex;">
              <el-checkbox-group v-model="form.checkListTwo" @change="(data)=>checkClickOne(data,'xx')" style="height:40px;line-height:40px;width:80px;">
                <el-checkbox label="learnStatus">学习</el-checkbox>
              </el-checkbox-group>
              <p v-if="form.learnStatusType" style="margin:0;line-height:40px;">学习时长：</p>
              <el-form-item label="" prop="learnHour" v-if="form.learnStatusType" style="margin-bottom:20px;">
                <el-input
                  style="width:150px;"
                  v-model="form.learnHour"
                  placeholder="请输入"
                  maxLength="5"
                  clearable
                  size="small">
                  <template slot="append">时</template>
                </el-input>
              </el-form-item>
              <p style="width:30px;"></p>
              <el-form-item label="" prop="learnMinute" v-if="form.learnStatusType" style="margin-bottom:20px;">
                <el-input
                  style="width:150px;"
                  v-model="form.learnMinute"
                  placeholder="请输入"
                  maxLength="5"
                  clearable
                  size="small">
                  <template slot="append">分</template>
                </el-input>
              </el-form-item>
            </div>
            <div class="for-check-box" style="display: flex;">
              <el-checkbox-group v-model="form.checkListTwo" @change="(data)=>checkClickTwo(data,'zt')" style="height:40px;line-height:40px;width:80px;">
                <el-checkbox label="practiceStatus">做题</el-checkbox>
              </el-checkbox-group>
              <p v-if="form.practiceStatusType" style="margin:0;line-height:40px;">题目数量：</p>
              <el-form-item label="" prop="numberTopics" v-if="form.practiceStatusType" style="margin-bottom:20px;">
                <el-input
                  style="width:150px;"
                  v-model="form.numberTopics"
                  placeholder="请输入"
                  maxLength="5"
                  clearable
                  size="small">
                  <template slot="append">道</template>
                </el-input>
              </el-form-item>
              <p style="width:87px;text-align: right;margin:0;line-height:40px;" v-if="form.practiceStatusType">正确率：</p>
              <el-form-item label="" prop="numberAccuracy" v-if="form.practiceStatusType" style="margin-bottom:20px;">
                <el-input
                  style="width:150px;"
                  v-model="form.numberAccuracy"
                  placeholder="请输入"
                  maxLength="5"
                  clearable
                  size="small">
                  <template slot="append">%</template>
                </el-input>
              </el-form-item>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="处理天数时限" prop="handleDay" style="margin-bottom:10px;">
          <el-input
            v-model="form.handleDay"
            placeholder="请输入"
            maxLength="5"
            clearable
            style="width:200px;">
            <template slot="append">天</template>
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer dialog-footer-box">
        <p class="dialog-footer-button-null"></p >
        <p class="dialog-footer-button-info" @click="cancel">取消</p >
        <p class="dialog-footer-button-primary" @click="submitForm">提交</p >
        <p class="dialog-footer-button-null"></p >
      </div>
    </el-dialog>
    <!-- 移除黑名单 -->
    <el-dialog :title="title" :visible.sync="form1Open" v-if="form1Open" width="500px" append-to-body
               :close-on-click-modal="false">
      <el-form ref="form1" :model="form1" :rules="rules1" label-width="90px">
        <el-form-item label="姓名：">
          <el-input v-model="form1.userName" :disabled="true" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="学号：">
          <el-input v-model="form1.stuNo" :disabled="true" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="学院：">
          <el-input v-model="form1.deptName" :disabled="true" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="原因：" prop="reason">
          <el-input
            type="textarea"
            :autosize="{ minRows: 6, maxRows: 6}"
            placeholder="请输入原因"
            maxLength="50"
            resize="none"
            v-model="form1.reason">
          </el-input>
        </el-form-item>
        <el-form-item label="">
          <p style="font-size:14px;color:#999;margin:0;">提交后，该人员信用分自动恢复到合格分。</p>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer dialog-footer-box">
        <p class="dialog-footer-button-null"></p >
        <p class="dialog-footer-button-info" @click="form1Off">取消</p >
        <p class="dialog-footer-button-primary" @click="submitForm1">提交</p >
        <p class="dialog-footer-button-null"></p >
      </div>
    </el-dialog>
    <!-- 加入黑名单 -->
    <el-dialog :title="title" :visible.sync="form2Open" v-if="form2Open" width="720px" append-to-body
               :close-on-click-modal="false">
      <el-form ref="form2" :model="form2" :rules="rules2" label-width="120px">
        <el-form-item label="姓名：" style="width:600px;">
          <el-input v-model="form2.joinUserName" :disabled="true" placeholder="请输入姓名"/>
        </el-form-item>
        <el-form-item label="学号：" style="width:600px;">
          <el-input v-model="form2.stuNo" :disabled="true" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="学院：" style="width:600px;">
          <el-input v-model="form2.deptName" :disabled="true" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="原因：" prop="reason" style="width:600px;">
          <el-input
            type="textarea"
            :autosize="{ minRows: 6, maxRows: 6}"
            placeholder="请输入原因"
            maxLength="50"
            resize="none"
            v-model="form2.reason">
          </el-input>
        </el-form-item>
        <el-form-item label="处理天数时限" prop="handleDay" style="margin-bottom:0;">
          <el-input
            v-model="form2.handleDay"
            placeholder="请输入"
            maxLength="5"
            clearable
            style="width:200px;">
            <template slot="append">天</template>
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer dialog-footer-box">
        <p class="dialog-footer-button-null"></p >
        <p class="dialog-footer-button-info" @click="form2Off">取消</p >
        <p class="dialog-footer-button-primary" @click="submitForm2">提交</p >
        <p class="dialog-footer-button-null"></p >
      </div>
    </el-dialog>
    <!-- 移除负面清单 -->
    <el-dialog :title="title" :visible.sync="form3Open" v-if="form3Open" width="500px" append-to-body
               :close-on-click-modal="false">
      <el-form ref="form3" :model="form3" :rules="rules3" label-width="90px">
        <el-form-item label="姓名：">
          <el-input v-model="form3.userName" :disabled="true" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="学号：">
          <el-input v-model="form3.stuNo" :disabled="true" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="学院：">
          <el-input v-model="form3.deptName" :disabled="true" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="原因：" prop="reason">
          <el-input
            type="textarea"
            :autosize="{ minRows: 6, maxRows: 6}"
            placeholder="请输入原因"
            maxLength="50"
            resize="none"
            v-model="form3.reason">
          </el-input>
        </el-form-item>
        <el-form-item label="">
          <p style="font-size:14px;color:#999;margin:0;">提交后，该人员信用分自动恢复到合格分。</p>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer dialog-footer-box">
        <p class="dialog-footer-button-null"></p >
        <p class="dialog-footer-button-info" @click="form3Off">取消</p >
        <p class="dialog-footer-button-primary" @click="submitForm3">提交</p >
        <p class="dialog-footer-button-null"></p >
      </div>
    </el-dialog>
    <violation-info v-if="pageType==2" :propsData="propsData"></violation-info>
  </div>
</template>

<script>
  import { delNegivelist,delBlacklist,blackAdd,
    getViolation, delViolation, addViolation, updateViolation,joinBlackList,
    getIntegralMatchingRules,addBlacklist } from "@/api/creditViolation/index";
  import {
    selectListUser,
    getDeptDropList,
    systemUserSelectUser,
    laboratorySubRelInfoGetListByFloor,
    systemUserDropDateAuthList
  } from '@/api/commonality/permission'
  import { listDepartments, getDicts, systemSubjectGetList } from '@/api/commonality/noPermission'
  import { examViolationList,examViolationSiteGetListByType,examViolationAdd,
    examViolationBlackAdd,examViolationDelBlacklist,examViolationDelNegivelist } from "@/api/creditViolation/index";
  import violationInfo from "./violationInfo.vue";
export default {
  name: "Violation",
  components: {
    violationInfo
  },
  data() {
    return {
      tableButtonType:this.hasPermiDom(['exam:violationHistory:list','exam:blacklist:add','exam:blacklist:del','exam:violation:del']),
      pageType:1,
      propsData:{},
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 违规记录表格数据
      violationList: [],
      // 弹出层标题
      title: "",
      // 查询参数
      queryParams: {
        page: 1,
        pageSize:20,
        userName: null,
        searchValue: null,
        stuNo: null,
        status: null,
        joinUserId: null,
        negativeId: null,
        violationType: null,
        violationContent: null,
        deptId: null,
        deptName: null,
        userId: null,
        endTime: null,
        violationReasons: null
      },
      subOptions:[],
      // 是否显示弹出层
      open: false,
      form1Open:false,
      form2Open:false,
      form3Open:false,
      // 表单参数
      form: {},
      form1: {},
      form2: {},
      form3: {},
      // 表单校验
      rules: {
        joinUserId:[
          {required: true, message: '请选择人员', trigger: 'blur'}
        ],
        violationTypes:[
          {required: true, message: '请选择违规内容', trigger: 'blur'}
        ],
        penaltyType:[
          {required: true, message: '请选择处置方案', trigger: 'blur'}
        ],
        reason:[
          {required: true, message: '请输入原因', trigger: 'blur'},
          { required: true, message: "请输入原因", validator: this.spaceJudgment, trigger: "blur" }
        ],
        checkListTwo: [
          { required: true, message: "请在考试/学习/做题中至少选择一种", trigger: "blur" }
        ],
        learnHour: [
          { required: true, message: "请输入小时", trigger: "blur" },
          { required: true, message: "请输入小时", validator: this.spaceJudgment, trigger: "blur" }
        ],
        learnMinute: [
          { required: true, message: "请输入分钟", trigger: "blur" },
          { required: true, message: "请输入分钟", validator: this.spaceJudgment, trigger: "blur" }
        ],
        numberTopics: [
          { required: true, message: "请输入数量", trigger: "blur" },
          { required: true, message: "请输入数量", validator: this.spaceJudgment, trigger: "blur" }
        ],
        numberAccuracy: [
          { required: true, message: "请输入百分比", trigger: "blur" },
          { required: true, message: "请输入百分比", validator: this.spaceJudgment, trigger: "blur" }
        ],
        handleDay: [
          { required: true, message: "请输入处理天数时限", trigger: "blur" },
          { required: true, message: "请输入处理天数时限", validator: this.spaceJudgment, trigger: "blur" },
          { required: true, message: "只能输入数字", validator: this.isNum, trigger: "blur" },
        ],
      },
      rules1: {
        reason:[
          {required: true, message: '请输入原因', trigger: 'blur'},
          { required: true, message: "请输入原因", validator: this.spaceJudgment, trigger: "blur" }
        ],
      },
      rules2: {
        reason:[
          {required: true, message: '请输入原因', trigger: 'blur'},
          { required: true, message: "请输入原因", validator: this.spaceJudgment, trigger: "blur" }
        ],
        handleDay: [
          { required: true, message: "请输入处理天数时限", trigger: "blur" },
          { required: true, message: "请输入处理天数时限", validator: this.spaceJudgment, trigger: "blur" },
          { required: true, message: "只能输入数字", validator: this.isNum, trigger: "blur" },
        ],
      },
      rules3: {
        reason:[
          {required: true, message: '请输入原因', trigger: 'blur'},
          { required: true, message: "请输入原因", validator: this.spaceJudgment, trigger: "blur" }
        ],
      },
      addRules:{
        userId:[
          {required: true, message: '请输入姓名', trigger: 'blur'},
          { required: true, message: "请输入姓名", validator: this.spaceJudgment, trigger: "blur" }
        ],
        subjectId:[
          {required: true, message: '请选择实验室', trigger: 'change'}
        ],
        reasonId:[
          {required: true, message: '请选择违规项', trigger: 'blur'}
        ],
        violationReasons:[
          {required: true, message: '请输入违规原因', trigger: 'blur'},
          { required: true, message: "请输入违规原因", validator: this.spaceJudgment, trigger: "blur" }
        ],
        deductionVal:[
          {required: true, message: '请输入扣除信用分值', trigger: 'blur'},
          { required: true, message: "请输入扣除信用分值", validator: this.spaceJudgment, trigger: "blur" },
          { required: true, message: "只能输入数字", validator: this.isNum, trigger: "blur" },
        ],
        checkListTwo:[
          {required: true, message: '请在考试/学习/做题中至少选择一项', trigger: 'blur'}
        ],
        learnHour: [
          { required: true, message: "请输入小时", trigger: "blur" },
          { required: true, message: "请输入小时", validator: this.spaceJudgment, trigger: "blur" },
          { required: true, message: "只能输入数字", validator: this.isNum, trigger: "blur" },
        ],
        learnMinute: [
          { required: true, message: "请输入分钟", trigger: "blur" },
          { required: true, message: "请输入分钟", validator: this.spaceJudgment, trigger: "blur" },
          { required: true, message: "只能输入数字", validator: this.isNum, trigger: "blur" },
        ],
        numberTopics: [
          { required: true, message: "请输入数量", trigger: "blur" },
          { required: true, message: "请输入数量", validator: this.spaceJudgment, trigger: "blur" },
          { required: true, message: "只能输入数字", validator: this.isNum, trigger: "blur" },
        ],
        numberAccuracy: [
          { required: true, message: "请输入百分比", trigger: "blur" },
          { required: true, message: "请输入百分比", validator: this.spaceJudgment, trigger: "blur" },
          { required: true, message: "只能输入数字", validator: this.isNum, trigger: "blur" },
        ],
        handleDay: [
          { required: true, message: "请输入处理天数时限", trigger: "blur" },
          { required: true, message: "请输入处理天数时限", validator: this.spaceJudgment, trigger: "blur" },
          { required: true, message: "只能输入数字", validator: this.isNum, trigger: "blur" },
        ],
      },
      //人员
      optionsUser: [],
      //详情数据
      infoData:{},
      violationId:"",
      violCount: "",
      lastHandleTime: "",
      lastViolTime: "",
      // newViolationTypes: null,
      //黑名单弹窗开关
      openTwo:false,
      //黑名单弹窗数据
      formTwo:{},
      //学院
      deptOptions:[],
      //状态
      deptOptionsTwo:[
        {deptId:1,deptName:"正常"},
        {deptId:2,deptName:"负面清单"},
        {deptId:3,deptName:"黑名单"},
      ],
      // 是否显示移除负面清单弹出层
      checklistOpen: false,
      // 是否显示移除加入黑名单弹出层
      blacklistOpen: false,
      //实验室列表
      subjectOptions:[],
      //违规类型列表
      violationSiteTypeList:[],
      //处罚列表
      punishmentList:[],
    };
  },
  created() {
    this.getList();
    this.getDeptList();
    this.examViolationSiteGetListByType();
  },
  methods: {
    //选中实验室
    subChange(val){
      let self = this;

      this.subOptions.forEach(function(item) {
        if (val ==item.subId){
          self.form.subjectName=item.subName;
        }
      })
    },
    //搜索实验室
    subSelectList(query){
      if (query !== '' && query.length>1) {
        systemSubjectGetList({"subName":query,}).then(response => {
          this.$set(this,'subOptions',response.data);
        });
      } else {
        this.$set(this,'subOptions',[]);
      }
    },
    //勾选方法
    checkClickOne(data,name){
      if(name == 'xx'){
        let num = 0;
        for(let i=0;i<data.length;i++){
          if('learnStatus' == data[i]){
            num++
          }
        }
        this.form.learnStatusType = num != 0;
      }
    },
    checkClickTwo(data,name){
      if(name == 'zt'){
        let num = 0;
        for(let i=0;i<data.length;i++){
          if('practiceStatus' == data[i]){
            num++
          }
        }
        this.form.practiceStatusType = num != 0;
      }
    },
    // 更多操作触发
    handleCommand(command, row) {
      switch (command) {
        case "1":
          //移除黑名单
          this.blacklistClick(row);
          break;
        case "2":
          //加入黑名单
          this.blacklistClick(row);
          break;
        case "3":
          this.checklistClick(row);
          break;
        default:
          break;
      }
    },
    //负面清单按钮
    checklistClick(row){
      row.buttonType = 2;
      this.$set(this,"form3",row);
      this.title = "移除负面清单";
      this.form.negativeId = row.negativeId;
      this.form3Open = true;
    },
    //黑名单按钮
    blacklistClick(row){
      if(row.status == 3){
        row.buttonType = 1;
        this.$set(this,"form1",row);
        this.title = "移除黑名单";
        this.form1Open = true;
      }else if(row.status == 1 || row.status == 2){
        this.title = "加入黑名单";
        let obj = JSON.parse(JSON.stringify(row));
        obj.buttonType = 3;
        obj.checkList = [];
        obj.checkListTwo = [];
        obj.learnStatusType = false;
        obj.practiceStatusType = false;
        this.$set(this,"form2",obj);
        this.form2Open = true;
      }
    },
    //页面切换
    goPage(type,row){
      if(this.pageType!=type){
        if(type == 1){
          this.pageType = type;
          this.getList();
        }else if(type == 2){
          this.propsData.joinUserId = row.joinUserId;
          this.pageType = type;
        }
      }
    },
    /** 查询违规记录列表 */
    getList() {
      this.loading = true;
      examViolationList(this.queryParams).then(response => {
        this.violationList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      // this.reset();
    },
    // 取消按钮
    form1Off(){
      this.form1Open = false;
    },
    form2Off(){
      this.form2Open = false;
    },
    form3Off(){
      this.form3Open = false;
    },
    /** 提交按钮 */
    submitForm1(){
      this.$refs["form1"].validate(valid => {
        if (valid) {
          //移除黑名单
          let obj = {
            id:this.form1.id,
            joinUserId:this.form1.joinUserId,
            reason:this.form1.reason,
          };
          examViolationDelBlacklist(obj).then(response => {
            this.form1Open = false;
            this.$set(this,'form1',{})
            this.msgSuccess("操作成功");
            this.getList();
          });
        }
      });
    },
    submitForm2(){
      this.$refs["form2"].validate(valid => {
        if (valid) {
          if(this.form2.buttonType == 3){
            let obj = {
              id:this.form2.id,
              joinUserId:this.form2.joinUserId,
              reason:this.form2.reason,
              handleDay:this.form2.handleDay,
            };
            examViolationBlackAdd(obj).then(response => {
              this.form2Open = false;
              this.$set(this,'form2',{})
              this.msgSuccess("操作成功");
              this.getList();
            });
          }
        }
      });
    },
    submitForm3() {
      this.$refs["form3"].validate(valid => {
        if (valid) {
          if(this.form3.buttonType == 2){
            //移除负面清单
            let obj = {
              id:this.form3.id,
              joinUserId:this.form3.joinUserId,
              reason:this.form3.reason,
            };
            examViolationDelNegivelist(obj).then(response => {
              this.form3Open = false;
              this.$set(this,'form3',{})
              this.msgSuccess("操作成功");
              this.getList();
            });
          }
        }
      });
    },
    cancelTwo() {
      this.blacklistOpen = false;
      this.checklistOpen = false;
      // this.reset();
    },
    resetTwo(){
      this.formTwo = {};
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      // this.resetForm("queryForm");
      this.$set(this,'queryParams',{
        page: 1,
        pageSize:20,
      });
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(type) {
      if(type.order == 'ascending'){
        this.queryParams.order = type.prop;//降
        this.queryParams.orderType = 'asc';//升ascending
      }else if(type.order == 'descending'){
        this.queryParams.order = type.prop;//降
        this.queryParams.orderType = 'desc';//降
      }else{
        this.queryParams.order = null;//无
        this.queryParams.orderType = null;//无
      }
      this.getList();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      let obj = {
        userId:"",
        userName:"",
        deptName:"",
        reasonId:"",
        checkList:[],
        checkListTwo:[],
        learnStatusType:false,
        practiceStatusType:false,
        learnHour:"",
        learnMinute:"",
        numberTopics:"",
        numberAccuracy:"",
        handleDay:"",
      }
      this.$set(this,"form",obj);
      this.optionsUser = [];
      this.title = "新增违规记录";
      this.open = true;
    },
    /** 新增违规 */
    submitForm() {
      let self = this;
      this.$refs["form"].validate(valid => {
        if (valid) {
          let obj = {
            deptId:this.form.deptId,
            deptName:this.form.deptName,
            stuNo:this.form.stuNo,
            joinUserId:this.form.joinUserId,
            joinUserName:this.form.joinUserName,
            subjectId:this.form.subjectId,
            subjectName:this.form.subjectName,
            reasonId:this.form.reasonId,
            violationContent:this.form.violationContent,
            deductionVal:this.form.deductionVal,
            handleDay:this.form.handleDay,
            violationReasons:this.form.violationReasons,
          };

          //处理二级多选--警告/约谈
          let warningStatusNum = 0;
          let interviewStatusNum = 0;
          for(let o=0;o<this.form.checkList.length;o++){
            if(this.form.checkList[o] == 'warningStatus'){
              warningStatusNum++
            }
            if(this.form.checkList[o] == 'interviewStatus'){
              interviewStatusNum++
            }
          }
          if(warningStatusNum == 0){
            obj.warningStatus = null;
          }else{
            obj.warningStatus = 1;
          }
          if(interviewStatusNum == 0){
            obj.interviewStatus = null;
          }else{
            obj.interviewStatus = 1;
          }
          //处理二级多选--考试
          let testStatusNum = 0;
          for(let o=0;o<this.form.checkListTwo.length;o++){
            if(this.form.checkListTwo[o] == 'testStatus'){
              testStatusNum++
            }
          }
          if(testStatusNum == 0){
            obj.testStatus = null;
          }else{
            obj.testStatus = 1;
          }
          //处理二级多选--学习
          if(this.form.learnStatusType){
            obj.learnStatus = 1;
            obj.learnHour = this.form.learnHour;
            obj.learnMinute = this.form.learnMinute;
          }else{
            obj.learnStatus = null;
            obj.learnHour = null;
            obj.learnMinute = null;
          }
          //处理二级多选--做题
          if(this.form.practiceStatusType){
            obj.practiceStatus = 1;
            obj.numberTopics = this.form.numberTopics;
            obj.numberAccuracy = this.form.numberAccuracy;
          }else{
            obj.practiceStatus = null;
            obj.numberTopics = null;
            obj.numberAccuracy = null;
          }
          examViolationAdd(obj).then(response => {
            this.msgSuccess("操作成功");
            this.open = false;
            this.getList();
          });
        }
      });
    },
    //人员选中
    userChange(data){
      let self = this;
      for(let i=0;i<self.optionsUser.length;i++){
        if(data == self.optionsUser[i].userId){
          this.$set(this.form,'stuNo',self.optionsUser[i].account);
          this.$set(this.form,'deptId',self.optionsUser[i].deptId);
          this.$set(this.form,'deptName',self.optionsUser[i].deptName);
          this.$set(this.form,'joinUserId',self.optionsUser[i].userId);
          this.$set(this.form,'joinUserName',self.optionsUser[i].userName);
          this.$set(this.form,'subjectId','');
          this.laboratorySubRelInfoGetListByFloor();
        }
      }
    },
    //处罚方式懒加载
    getIntegralMatchingRules(query){
      if (query !== '') {
        console.log(this.form.deductionVal)
        this.loading = true;
        let obj = {
          creditScore : this.form.deductionVal?this.form.deductionVal:'0'
        };
        getIntegralMatchingRules(obj).then(res => {
          this.loading = false;
          if(res.data){
            //判断-约谈
            if(res.data.warningStatus == 1){
              this.form.checkList.push('interviewStatus')
            }
            //判断-警告
            if(res.data.warningStatus == 1){
              this.form.checkList.push('warningStatus')
            }
            //判断-考试
            if(res.data.testStatus == 1){
              this.form.checkListTwo.push('testStatus')
            }
            //判断-学习
            if(res.data.learnStatus == 1){
              this.form.checkListTwo.push('learnStatus')
              this.form.learnStatusType = true;
              this.form.learnHour = res.data.learnHour;
              this.form.learnMinute = res.data.learnMinute;
            }else{
              this.form.learnStatusType = false;
            }
            //判断-考试
            if(res.data.practiceStatus == 1){
              this.form.checkListTwo.push('practiceStatus')
              this.form.practiceStatusType = true;
              this.form.numberTopics = res.data.numberTopics;
              this.form.numberAccuracy = res.data.numberAccuracy;
            }else{
              this.form.practiceStatusType = false;
            }
            this.form.handleDay = res.data.handleDay;
          }else{
            this.$set(this.form,'checkList',[]);
            this.$set(this.form,'checkListTwo',[]);
            this.$set(this.form,'learnHour','');
            this.$set(this.form,'learnMinute','');
            this.$set(this.form,'learnStatusType',false);
            this.$set(this.form,'numberTopics','');
            this.$set(this.form,'numberAccuracy','');
            this.$set(this.form,'practiceStatusType',false);
            this.$set(this.form,'handleDay','');
          }
          this.$forceUpdate();
        });
      }
    },
    //人员懒加载
    userSelectList(query) {
      if (query !== '' && query.length>1) {
        this.loading = true;
        let obj = {
          userName : query,
          userType: 2,
        };
        systemUserDropDateAuthList(obj).then(response => {
          this.optionsUser = response.data;
          this.loading = false;
        });
      } else {
        this.optionsUser = [];
      }
    },
    /** 查询学院列表 */
    getDeptList() {
      getDeptDropList({deptType:1}).then(response => {
        this.$set(this,'deptOptions',response.data);
      });
    },
    //查询实验室列表
    laboratorySubRelInfoGetListByFloor(){
      if(!this.form.deptId){
        this.msgError('请先选择人员');
        return
      }
      let obj = {
        deptId:this.form.deptId,
        subName:'',
      }
      laboratorySubRelInfoGetListByFloor(obj).then(response => {
        this.$set(this,'subjectOptions',response.data);
        this.$forceUpdate();
      });
    },
    //选中实验室
    subjectChange(e){
      this.$set(this.form,'subjectId',e);
      this.$forceUpdate();
    },
    //选择违规项
    reasonChange(e){
      let self=this;
      for(let i=0;i<self.violationSiteTypeList.length;i++){
        if(e == self.violationSiteTypeList[i].id){
          self.form.violationContent = self.violationSiteTypeList[i].violationName
        }
      }
    },
    //获取违规类型列表
    examViolationSiteGetListByType(){
      examViolationSiteGetListByType({}).then(response => {
        this.violationSiteTypeList = response.data;
        this.violationSiteTypeList.push({"id":"-1","violationName":"其他"});
      });
    },
  }
};
</script>
<style scoped lang="scss">
  .violation {
    display: flex!important;
    flex-direction: column;
    box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    .violationPage{
      flex:1;
      display: flex!important;
      flex-direction: column;
      overflow: hidden;
    }
    .button-box{
      width:200px;
      display: flex;
      margin:0 auto;
    }
  }
</style>

