<!--黑名单-->
<template>
  <div class="app-container blacklist">
    <div class="blacklist-page" v-if="pageType == 1">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="学院" prop="deptId" style="margin-left:-30px;">
          <el-select v-model="queryParams.deptId" placeholder="请选择学院" clearable size="small">
            <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="searchValue">
          <el-input
            v-model="queryParams.searchValue"
            placeholder="请输入姓名/学号"
            clearable
            size="small"
          />
        </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="blacklistList" @sort-change="handleSelectionChange">
        <el-table-column label="姓名" align="left" prop="userName" />
        <el-table-column label="学号" align="left" prop="number" />
        <el-table-column label="学院" align="left" prop="deptName" />
        <el-table-column label="违规次数" align="left" sortable="custom" prop="total" />
        <el-table-column label="负面清单次数" align="left" sortable="custom" prop="negativeNum" />
        <el-table-column label="黑名单次数" align="left" sortable="custom" prop="blackNum" />
        <el-table-column label="信用分" align="left" prop="creditScore" />
        <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="230" 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:blackdetail:list']"
              >历史记录</p>
              <p class="table-min-button"
                 v-if="scope.row.blacklistStatus == 1"
                 @click="handleDelete(scope.row)"
                 v-hasPermi="['laboratory:blacklist:remove']"
              >移除黑名单</p>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        layout="total, prev, pager, next, sizes, jumper"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <black-list-info v-if="pageType == 2" :propsData="propsData"></black-list-info>
    <!-- 移除黑名单 -->
    <el-dialog :title="title" :visible.sync="open" 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.number" :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="请输入原因"
            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>
  </div>
</template>

<script>
import { listBlacklist, getBlacklist, delBlacklist, addBlacklist, updateBlacklist, removeBlacklist } from "@/api/laboratory/blacklist";
import { selectListUser } from "@/api/system/user";
import { listDepartments,listbuildings } from "@/api/system/dept";
import blackListInfo from "./blackListInfo.vue";
export default {
  name: "Blacklist",
  components: {
    blackListInfo,
  },
  data() {
    return {
      tableButtonType:this.hasPermiDom(['laboratory:blackdetail:list','laboratory:blacklist:remove']),
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 黑名单表格数据
      blacklistList: [
        {
          id:"id",
          joinUserId:"joinUserId",
          blacklistStatus:"blacklistStatus",
          deptId:"deptId",

        },
      ],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        searchValue: null,
        joinUserId: null,
        blacklistStatus: null,
        deptId: null,
        deptName: null,
        userId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        reason:[
           {required: true, message: '请输入原因', trigger: 'blur'},
          { required: true, message: "请输入原因", validator: this.spaceJudgment, trigger: "blur" }
        ],
      },
      //新增-编辑状态
      disabledType:true,
      //人员
      optionsUser: [],
      //处置方案
      optionsTwo: [],
      // 日期范围
      dateRange: [],
      deptOptions:[],
      //页面状态
      pageType:1,
      propsData:{},
    };
  },
  created() {
    this.getList();
    this.getDicts("penaltyType").then(response => {
      this.optionsTwo = response.data;
    });
  },
  mounted(){
    this.getDeptList();
  },
  methods: {
    goPage(type,row){
      if(this.pageType!=type){
        if(type == 1){
          this.pageType = type;
          this.getList();
        }else if(type == 2){
          this.propsData.userId = row.id
          this.pageType = type;
        }
      }
    },
    /** 查询黑名单列表 */
    getList() {
      this.loading = true;
       if(this.dateRange&&this.dateRange.length>0)
      {
        this.queryParams.startTime=this.dateRange[0]
        this.queryParams.endTime=this.dateRange[1]
      }
      else
      {
        this.queryParams.startTime=null;
        this.queryParams.endTime=null
      }

      listBlacklist(this.queryParams).then(response => {
        this.blacklistList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询学院列表 */
    getDeptList()
    {
      listDepartments().then(response => {
        // this.deptOptions = response.data;
        this.$set(this, 'deptOptions', response.data)
      });
    },
    // 处置类型字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.optionsTwo, row.penaltyType);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        joinUserId: null,
        blacklistStatus: 0,
        deptId: null,
        deptName: null,
        userId: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      // this.resetForm("queryForm");
      this.$set(this,'queryParams',{
        pageNum: 1,
        pageSize: 10,
        deptId:"",
        searchValue: '',
      });
      this.dateRange = 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() {
      this.reset();
      this.disabledType = false;
      this.open = true;
      this.title = "添加黑名单";
    },
    /** 修改按钮操作 */
    // handleUpdate(row) {
    //   this.reset();
    //   const id = row.id || this.ids.join()
    //   getBlacklist(id).then(response => {
    //     this.form = response.data;
    //     this.disabledType = true;
    //     this.open = true;
    //     this.title = "修改黑名单";
    //   });
    // },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          removeBlacklist(this.form).then(response => {
              this.msgSuccess("操作成功");
              this.open = false;
              this.getList();
            });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$set(this,'form',row);
      this.title = "移除黑名单";
      this.open = true;
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('laboratory/blacklist/export', {
        ...this.queryParams
      }, `laboratory_blacklist.xlsx`)
    },
    /** 下列人员-懒加载 */
    userSelectList(query) {
        if (query !== '' && query.length>1) {
          this.loading = true;
          this.userSelectList.nickName=query;
          selectListUser(this.userSelectList).then(response => {
            this.optionsUser = response.data;
            this.loading = false;
          });
        } else {
          this.optionsUser = [];
        }
      }
  }
};
</script>
<style scoped lang="scss">
  .blacklist {
    display: flex!important;
    flex-direction: column;
    box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
    padding:20px!important;
    overflow: hidden;
    .blacklist-page{
      flex:1;
      display: flex!important;
      flex-direction: column;
      overflow: hidden;
      .button-box{
        display: flex;
        width:250px;
        margin:0 auto;
      }
    }
  }
</style>
