<!--负面清单列表-->
<template>
  <div class="app-container negative-list-records">
    <div class="negative-list-records-page" v-if="pageType == 1">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
        <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 >
          <p class="inquire-button-one" @click="handleQuery">查询</p>
          <p class="reset-button-one" @click="resetQuery">重置</p>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" border :data="negativeListRecordsList" @sort-change="handleSelectionChange">
        <!--<el-table-column type="selection" width="55" align="center" />-->
        <!--<el-table-column label="序号" align="center" prop="id" />-->
        <el-table-column label="姓名" align="left" prop="userName" />
        <el-table-column label="学号" align="left" prop="stuNo" />
        <el-table-column label="学院" align="left" prop="deptName" />
        <el-table-column label="违规次数" align="left" sortable="custom" prop="violationNum" />
        <el-table-column label="负面清单次数" align="left" sortable="custom" prop="negativeListNum" />
        <el-table-column label="黑名单次数" align="left" sortable="custom" prop="blackListNum" />
        <el-table-column label="信用分" align="left" prop="ceditScore" />
        <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="350" v-if="tableButtonType">
          <template slot-scope="scope">
            <div class="button-box">
              <p class="table-min-button"
                 style="margin-right:10px;"
                 @click="goPage(2,scope.row)"
                 v-hasPermi="['laboratory:negativeListHistory:list']"
              >历史记录</p>
              <p v-show="scope.row.isBlackList != 1"
                 class="table-min-button"
                 style="margin-right:10px;"
                 @click="blacklistClick(scope.row)"
                 v-hasPermi="['laboratory:blacklist:add']"
              >加入黑名单</p>
              <p class="table-min-button"
                 @click="checklistClick(scope.row)"
                 v-hasPermi="['laboratory:negativeListRecords:remove']"
              >移除负面清单</p>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <page-info :propsData="propsData" v-if="pageType == 2"></page-info>
    <!-- 移除负面清单 -->
    <el-dialog :title="title" :visible.sync="checklistOpen" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="90px">
        <el-form-item label="姓名：">
          <el-input v-model="form.userName" :disabled="true" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="学号：">
          <el-input v-model="form.stuNo" :disabled="true" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="学院：">
          <el-input v-model="form.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="form.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">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 加入黑名单 -->
    <el-dialog :title="title" :visible.sync="blacklistOpen" width="720px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="姓名：" style="width:600px;">
          <el-input v-model="form.userName" :disabled="true" placeholder="请输入姓名"/>
        </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="reason" style="width:600px;">
          <el-input
            type="textarea"
            :autosize="{ minRows: 6, maxRows: 6}"
            placeholder="请输入原因"
            maxLength="50"
            resize="none"
            v-model="form.reason">
          </el-input>
        </el-form-item>
        <el-form-item label="处理天数时限" prop="handleDay" style="margin-bottom:0;">
          <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">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listNegativeListRecords, getNegativeListRecords, delNegativeListRecords, addNegativeListRecords, updateNegativeListRecords, delBlacklist, delNegivelist,blackAdd } from "@/api/laboratory/negativeListRecords";
import { listDepartments } from "@/api/system/dept";
import pageInfo from "./info.vue";
export default {
  name: "NegativeListRecords",
  components: {
    pageInfo,
  },
  data() {
    return {
      tableButtonType:this.hasPermiDom(['laboratory:negativeListHistory:list','laboratory:blacklist:add','laboratory:negativeListRecords:remove']),
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 负面清单列表表格数据
      negativeListRecordsList: [],
      // 弹出层标题
      title: "",
      // 是否显示移除负面清单弹出层
      checklistOpen: false,
      // 是否显示移除加入黑名单弹出层
      blacklistOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize:20,
        searchValue: null,
        stuName: null,
        stuNo: null,
        belongCollege: null,
        reason: null,
        status: null,
        violationNum: null,
        negativeListNum: null,
        blackListNum: null,
        ceditScore: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        reason:[
          {required: true, message: '请输入原因', trigger: 'blur'},
          { required: true, message: "请输入原因", validator: this.spaceJudgment, trigger: "blur" }
        ],
        checkListTwo: [
          { required: true, message: "请在考试/学习/做题中至少选择一种", trigger: "blur" }
        ],
        handleDay: [
          { required: true, message: "请输入处理天数时限", trigger: "blur" },
          { required: true, message: "请输入处理天数时限", validator: this.spaceJudgment, trigger: "blur" },
          { required: true, message: "只能输入数字", validator: this.isNum, trigger: "blur" },
        ],

      },
      // 学院
      deptOptions: [],
      //传参数据
      propsData:{},
      //页面状态
      pageType:1,
    };
  },
  created() {
    this.getList();
    this.getDeptList();
  },
  methods: {
    //勾选方法
    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;
      }
    },
    //页面切换
    goPage(type,row){
      if(this.pageType != type){
        if(type == 1){
          this.pageType = type;
          this.getList();
        }else if(type == 2){
          this.propsData.userId = row.joinUserId
          this.pageType = type;
        }
      }
    },
    /** 查询负面清单列表列表 */
    getList() {
      this.loading = true;
      listNegativeListRecords(this.queryParams).then( response => {
        this.negativeListRecordsList =  response.rows;
        this.total =  response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.blacklistOpen = false;
      this.checklistOpen = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      // this.resetForm("queryForm");
      this.$set(this,'queryParams',{
        pageNum: 1,
        pageSize:20,
        searchValue:"",
        deptId: '',
      });
      this.queryParams.searchValue='';
      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();
    },
    //负面清单按钮
    checklistClick(row){
      row.buttonType = 2;
      this.$set(this,"form",row);
      this.title = "移除负面清单";
      this.checklistOpen = true;
    },
    //黑名单按钮
    blacklistClick(row){
        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,"form",obj);
        this.blacklistOpen = true;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if(this.form.buttonType == 1){
            //移除黑名单
            let obj = {
              id:this.form.id,
              userId:this.form.joinUserId,
              reason:this.form.reason,
            };
            delBlacklist(obj).then(response => {
              this.checklistOpen = false;
              this.msgSuccess("操作成功");
              this.getList();
            });
          }else if(this.form.buttonType == 2){
            //移除负面清单
            let obj = {
              id:this.form.id,
              userId:this.form.joinUserId,
              reason:this.form.reason,
            };
            delNegivelist(obj).then(response => {
              this.checklistOpen = false;
              this.msgSuccess("操作成功");
              this.getList();
            });
          }else if(this.form.buttonType == 3){
            let obj = {
              id:this.form.id,
              joinUserId:this.form.joinUserId,
              reason:this.form.reason,
              // deductionVal:this.form.deductionVal,
              handleDay:this.form.handleDay,
            };
            /*
            //处理二级多选--警告/约谈
            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 = "";
            }else{
              obj.warningStatus = 1;
            }
            if(interviewStatusNum == 0){
              obj.interviewStatus = "";
            }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 = "";
            }else{
              obj.testStatus = 1;
            }
            //处理二级多选--学习
            if(this.form.learnStatusType){
              obj.learnStatus = 1;
              obj.learnHour = this.form.learnHour;
              obj.learnMinute = this.form.learnMinute;
            }else{
              obj.learnStatus = "";
              obj.learnHour = "";
              obj.learnMinute = "";
            }
            //处理二级多选--做题
            if(this.form.practiceStatusType){
              obj.practiceStatus = 1;
              obj.numberTopics = this.form.numberTopics;
              obj.numberAccuracy = this.form.numberAccuracy;
            }else{
              obj.practiceStatus = "";
              obj.numberTopics = "";
              obj.numberAccuracy = "";
            }
            */
            blackAdd(obj).then(response => {
              this.blacklistOpen = false;
              this.msgSuccess("操作成功");
              this.getList();
            });
          }
        }
      });
    },
    /** 查询学院列表 */
    getDeptList() {
      listDepartments().then(response => {
        this.$set(this, 'deptOptions', response.data)
      });
    },
  }
};
</script>

<style scoped lang="scss">
  .negative-list-records {
    display: flex!important;
    flex-direction: column;
    box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
    padding:20px!important;
    overflow: hidden;
    .negative-list-records-page{
      flex:1;
      display: flex!important;
      flex-direction: column;
      overflow: hidden;
      .button-box{
        display: flex;
        width:380px;
        margin:0 auto;
      }
    }
  }
</style>
