<!--个人违规记录-->
<template>
  <div class="app-container violation_my">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="违规类型" prop="bonusType" label-width="80px">
        <el-select v-model="queryParams.violationType" clearable placeholder="请选择违规类型">
          <el-option
            v-for="dict in semesterList"
            :key="dict.id"
            :label="dict.semesterName"
            :value="dict.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="overStatus" label-width="50px">
        <el-select v-model="queryParams.overStatus" clearable placeholder="请选择状态">
          <el-option
            v-for="dict in bonusTypeOptions"
            :key="dict.id"
            :label="dict.name"
            :value="dict.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="时间段">
        <el-date-picker
          :clearable="false"
          v-model="dateRange"
          size="small"
          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>
        <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="violationList">
      <el-table-column label="违规类型" align="left" prop="reason"  width="100">
        <template slot-scope="scope">
          {{scope.row.violationType == 1 ?'负面清单':(scope.row.violationType == 2 ?'黑名单':'')}}
        </template>
      </el-table-column>
      <el-table-column label="违规原因" align="left" prop="reason"  width="300"/>
      <el-table-column label="实验室" align="left" prop="laboratoryName" show-overflow-tooltip width="200"/>
      <el-table-column label="添加人" align="left" prop="createBy" width="140"/>
      <el-table-column label="创建时间" align="left" prop="createTime" width="200"/>
      <el-table-column label="扣分值" align="left"  prop="deductionVal" width="100"/>
      <el-table-column label="处理方式" align="left"  prop="treatmentMethod" width="200"/>
      <el-table-column label="处理状态" align="left" width="140">
        <template slot-scope="scope">
          <div class="scope-big-box" v-if="scope.row.learnStatus == 0 || scope.row.learnStatus == 1 || scope.row.learnStatus == 2">
            <p>学习</p>
            <p :class="scope.row.learnStatus == 0 ?'scopeColorA':(scope.row.learnStatus == 1 ?'scopeColorB':(scope.row.learnStatus == 2 ?'scopeColorC':''))">{{scope.row.learnStatus == 0 ?'未完成':(scope.row.learnStatus == 1 ?'已完成':(scope.row.learnStatus == 2 ?'已恢复':''))}}</p>
          </div>
          <div class="scope-big-box" v-if="scope.row.testStatus == 0 || scope.row.testStatus == 1 || scope.row.testStatus == 2">
            <p>考试</p>
            <p :class="scope.row.testStatus == 0 ?'scopeColorA':(scope.row.testStatus == 1 ?'scopeColorB':(scope.row.testStatus == 2 ?'scopeColorC':''))">{{scope.row.testStatus == 0 ?'未完成':(scope.row.testStatus == 1 ?'已完成':(scope.row.testStatus == 2 ?'已恢复':''))}}</p>
          </div>
          <div class="scope-big-box" v-if="scope.row.practiceStatus == 0 || scope.row.practiceStatus == 1 || scope.row.practiceStatus == 2">
            <p>做题</p>
            <p :class="scope.row.practiceStatus == 0 ?'scopeColorA':(scope.row.practiceStatus == 1 ?'scopeColorB':(scope.row.practiceStatus == 2 ?'scopeColorC':''))">{{scope.row.practiceStatus == 0 ?'未完成':(scope.row.practiceStatus == 1 ?'已完成':(scope.row.practiceStatus == 2 ?'已恢复':''))}}</p>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="处理截止日期" align="left"  prop="handleDay" width="140"/>
      <el-table-column label="信用分" align="left"  prop="creditScore" width="100"/>
      <!--<el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="160">-->
        <!--<template slot-scope="scope">-->
          <!--<div class="button-box">-->
            <!--<p v-if="scope.row.penaltyType==0" class="table-button-red-120"-->
               <!--@click="goPage(1,scope.row)"-->
            <!--&gt;<i class="el-icon-edit-outline"></i>立即学习</p>-->
          <!--</div>-->
          <!--<div class="button-box">-->
            <!--<p v-if="scope.row.testStatus==0" class="table-button-red-120"-->
               <!--@click="goPage(2,scope.row)"-->
            <!--&gt;<i class="el-icon-edit-outline"></i>立即做题</p>-->
          <!--</div>-->
          <!--<div class="button-box">-->
            <!--<p v-if="scope.row.practiceStatus==0" class="table-button-red-120"-->
               <!--@click="goPage(3,scope.row)"-->
            <!--&gt;<i class="el-icon-edit-outline"></i>立即考试</p>-->
          <!--</div>-->
        <!--</template>-->
      <!--</el-table-column>-->
    </el-table>

    <pagination :page-sizes="[20, 30, 40, 50]"
      v-show="total>0"
      :total="total"
      layout="total, prev, pager, next, sizes, jumper"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getByIdlist,getSemesterList } from "@/api/laboratory/violation";

export default {
  name: "Violation",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 违规记录表格数据
      violationList: [],
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize:20,
        joinUserId: null,
        violationType: null,
        violationContent: null,
        deptId: null,
        deptName: null,
        userId: null,
        beginTime: null,
        endTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      //状态条件
      bonusTypeOptions:[
        {id:null,name:"全部"},
        {id:1,name:"已完成"},
        {id:0,name:"未完成"},
        {id:2,name:"已恢复"},
      ],
      //学期
      semesterList:[
        {semesterName:'负面清单',id:'1'},
        {semesterName:'黑名单',id:'2'}
      ],
    };
  },
  created() {
  },
  mounted(){
    this.getList();
    // this.getSemesterList();
  },
  methods: {
    getSemesterList(){
      getSemesterList(this.queryParams).then( res => {
        this.semesterList = res.data;
      });
    },
    //立即考试
    goPage(type,row){
      if (type == 1){
        // this.$router.push({
        //   path: '/safe/myexam'
        // })
      } else if(type == 2){
        // this.$router.push({
        //   path: '/safe/myexam'
        // })
      } else if(type == 3){
        this.$router.push({
          path: '/safe/myexam'
        })
      }
      // this.$router.push({
      //   path: '/safe/myexam',
      //   query: {
      //     violationId: row.id
      //     ,scopeType: 2
      //   }
      // })
    },
    /** 查询违规记录列表 */
    getList() {
      this.loading = true;
      if(this.dateRange[0]){
        this.queryParams.beginTime = this.dateRange[0];
        this.queryParams.endTime = this.dateRange[1];
      }else {
        this.queryParams.beginTime=null;
        this.queryParams.endTime=null
      }
      getByIdlist(this.queryParams).then(response => {
        this.violationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        joinUserId: null,
        violationType: null,
        violationContent: null,
        createTime: null,
        deptId: null,
        deptName: null,
        userId: null,
        remark: null,
        updateBy: null,
        updateTime: null,
        createBy: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.queryParams.pageSize = 20;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      // this.resetForm("queryForm");
      // this.queryParams = {};
      this.$set(this,'queryParams',{
        pageNum: 1,
        pageSize:20,
        overStatus:"",
        bonusType: '',
      });
      this.dateRange = [];
      this.violationList = [];
      this.handleQuery();
    },
  }
};
</script>

<style scoped lang="scss">
  .violation_my {
    display: flex!important;
    flex-direction: column;
    box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
    padding:20px 20px 20px!important;
    .button-box{
      width:120px;
      display: flex;
    }
    .scope-big-box{
      display: flex;
      p{
        font-size:14px;
        height:20px;
        line-height:20px;
        margin:4px 0;
      }
      p:nth-child(1){
        margin-right:10px;
      }
      p:nth-child(2){

      }
      .scopeColorA{
        padding:0 4px;
        border-radius:4px;
        color:#fff;
        background: #FF3131;
      }
      .scopeColorB{
        padding:0 4px;
        border-radius:4px;
        color:#fff;
        background: #39A922;
      }
      .scopeColorC{
        padding:0 4px;
        border-radius:4px;
        color:#fff;
        background: #0183FA;
      }
    }
  }
</style>
