<!--违规记录列表-->
<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="keyWord" label-width="60px">
            <el-input
              v-model="queryParams.keyWord"
              placeholder="姓名/学号"
              clearable
              size="small"
            />
          </el-form-item>
          <el-form-item label="" prop="collegeId" label-width="80px">
            <el-select v-model="queryParams.collegeId" 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.value"
                :label="dict.name"
                :value="dict.value"
              ></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="name" show-overflow-tooltip/>
          <el-table-column label="学号" align="left" prop="identity" show-overflow-tooltip/>
          <el-table-column label="学院" align="left" prop="collegeName" show-overflow-tooltip/>
          <el-table-column label="违规次数" align="left" sortable="custom" prop="fouls" show-overflow-tooltip/>
          <el-table-column label="负面清单次数" align="left" sortable="custom" prop="negatives" show-overflow-tooltip/>
          <el-table-column label="黑名单次数" align="left" sortable="custom" prop="blacklists" show-overflow-tooltip/>
          <el-table-column label="信用分" align="left" prop="scoreCredit" show-overflow-tooltip/>
          <el-table-column label="当前状态" align="left" prop="status" show-overflow-tooltip>
            <template slot-scope="scope">
              {{scope.row.status == 0?'正常':(scope.row.status == 1?'负面清单':(scope.row.status == 2?'黑名单':''))}}
            </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)"
                >历史记录</p>
                <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)" v-if="scope.row.status != 0">
                  <p class="table-button-p">更多>></p>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item command="1" v-show="scope.row.status == 2">移除黑名单</el-dropdown-item>
                    <el-dropdown-item command="2" v-show="scope.row.status == 1">加入黑名单</el-dropdown-item>
                    <el-dropdown-item command="3" v-show="scope.row.status == 1">移除负面清单</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.identity" :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="labId" >
          <el-select
            style="width:480px;"
            v-model="form.labId"
            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="foulsId">
          <el-select @change="violationChange" v-model="form.foulsId" style="width:480px;" placeholder="请选择违规项">
            <el-option
              v-for="item in violationSiteTypeList"
              :key="item.configValue"
              :label="item.configName"
              :value="item.configValue">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="违规原因：" prop="reason" style="width:600px;" v-if="form.foulsId==-1">
          <el-input
            v-model="form.reason"
            placeholder="请输入违规原因"
            maxLength="50">
          </el-input>
        </el-form-item>
        <el-form-item label="扣除信用分值：" prop="reduceScore" style="width:600px;" v-if="form.foulsId==-1">
          <el-input-number
            v-model="form.reduceScore"
            placeholder="请输入"
            :min="0"
            maxLength="5"
            @input="getIntegralMatchingRules">
          </el-input-number>
        </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.name" :disabled="true" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="学号：">
          <el-input v-model="form1.identity" :disabled="true" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="学院：">
          <el-input v-model="form1.collegeName" :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.name" :disabled="true" placeholder="请输入姓名"/>
        </el-form-item>
        <el-form-item label="学号：" style="width:600px;">
          <el-input v-model="form2.identity" :disabled="true" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="学院：" style="width:600px;">
          <el-input v-model="form2.collegeName" :disabled="true" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="原因：" prop="msg" style="width:600px;">
          <el-input
            type="textarea"
            :autosize="{ minRows: 6, maxRows: 6}"
            placeholder="请输入原因"
            maxLength="50"
            resize="none"
            v-model="form2.msg">
          </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.name" :disabled="true" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="学号：">
          <el-input v-model="form3.identity" :disabled="true" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="学院：">
          <el-input v-model="form3.collegeName" :disabled="true" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="原因：" prop="msg">
          <el-input
            type="textarea"
            :autosize="{ minRows: 6, maxRows: 6}"
            placeholder="请输入原因"
            maxLength="50"
            resize="none"
            v-model="form3.msg">
          </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 { creditFoulsAdd,creditFoulsList,creditFoulsAddBlacklists,creditFoulsRemoveBlacklists,creditItemListAllCredit } from "@/api/creditViolation/newIndex";
  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,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','credit:blacklists:del','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,
        keyWord: null,
        stuNo: null,
        status: null,
        joinUserId: null,
        negativeId: null,
        violationType: null,
        violationContent: null,
        collegeId: 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: {
        msg:[
          {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: {
        msg:[
          {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" }
        ],
        labId:[
          {required: true, message: '请选择实验室', trigger: 'change'}
        ],
        foulsId:[
          {required: true, message: '请选择违规项', trigger: 'blur'}
        ],
        reason:[
          {required: true, message: '请输入违规原因', trigger: 'blur'},
          { required: true, message: "请输入违规原因", validator: this.spaceJudgment, trigger: "blur" }
        ],
        reduceScore:[
          {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:[
        {value:0,name:"正常"},
        {value:1,name:"负面清单"},
        {value:2,name:"黑名单"},
      ],
      // 是否显示移除负面清单弹出层
      checklistOpen: false,
      // 是否显示移除加入黑名单弹出层
      blacklistOpen: false,
      //实验室列表
      subjectOptions:[],
      //违规类型列表
      violationSiteTypeList:[],
      //处罚列表
      punishmentList:[],
    };
  },
  created() {
    this.getList();
    this.getDeptList();
    this.creditItemListAllCredit();
  },
  methods: {
    //选中违规项
    violationChange(val){
      let self = this;
      this.violationSiteTypeList.forEach(function(item) {
        if (val ==item.configValue){
          self.$set(self.form,'foulsName',item.configName);
        }
      })
    },
    //选中实验室
    subChange(val){
      let self = this;
      this.subOptions.forEach(function(item) {
        if (val ==item.subId){
          self.$set(self.form,'labId',item.subId);
          self.$set(self.form,'labName',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.form3Open = true;
    },
    //黑名单按钮
    blacklistClick(row){
      if(row.status == 2){
        row.buttonType = 1;
        this.$set(this,"form1",row);
        this.title = "移除黑名单";
        this.form1Open = true;
      }else if(row.status == 0 || row.status == 1){
        this.title = "加入黑名单";
        let obj = JSON.parse(JSON.stringify(row));
        obj.buttonType = 3;
        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.identity = row.identity;
          this.pageType = type;
        }
      }
    },
    /** 查询违规记录列表 */
    getList() {
      this.loading = true;
      creditFoulsList(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 = {
            identity:this.form1.identity,
            msg:this.form1.reason,
          };
          creditFoulsRemoveBlacklists(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,
              msg:this.form2.msg,
              // handleDay:this.form2.handleDay,
            };
            creditFoulsAddBlacklists(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,
        userName: null,
        keyWord: null,
        stuNo: null,
        status: null,
        joinUserId: null,
        negativeId: null,
        violationType: null,
        violationContent: null,
        collegeId: null,
        deptName: null,
        userId: null,
        endTime: null,
        violationReasons: null,
      });
      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() {
      let obj = {
        userId:"",
        identity:"",
        name:"",
        deptName:"",
        labId:"",
        labName:"",
        foulsId:"",
        foulsName:"",
        reason:"",
        reduceScore:"",
        remark:"",
      }
      this.$set(this,"form",obj);
      this.$set(this,"optionsUser",[]);
      this.title = "新增违规记录";
      this.open = true;
    },
    /** 新增违规 */
    submitForm() {
      let self = this;
      this.$refs["form"].validate(valid => {
        if (valid) {
          let obj = {
            identity: this.form.identity,
            name: this.form.name,
            foulsType:'negative',
            labId: this.form.labId,
            labName: this.form.labName,
            foulsName: this.form.foulsName,
            reduceScore:this.form.reduceScore,
            remark:this.form.remark,
          };
          creditFoulsAdd(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){
          self.$set(self.form,'identity',self.optionsUser[i].account);
          self.$set(self.form,'name',self.optionsUser[i].userName);
          self.$set(self.form,'deptName',self.optionsUser[i].deptName);
        }
      }
    },
    //处罚方式懒加载
    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();
      });
    },
    //获取违规类型列表
    creditItemListAllCredit(){
      creditItemListAllCredit({}).then(response => {
        let list = [];
        for(let i=0;i<response.data.length;i++){
          if(response.data[i].configName!= '负面清单次数设置'){
            list.push(response.data[i])
          }
        }
        list.push({"configValue":"-1","configName":"其他"});
        this.$set(this,'violationSiteTypeList',list);
      });
    },
  }
};
</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>

