<template>
  <div class="app-container">
    <div style="background-color: #fff;padding: 20px;border-radius: 10px;">
      <p style="margin: 0; font-weight: 800;font-size: 16px;color: #343434;display: flex;align-items: center;margin-bottom: 20px;">
        <img src="../../../assets/images/icon_htgl_btzs.png" alt="" style="width: 16px;height: 20px;">
       <span style="margin-left: 10px;">黑名单管理</span>
      </p>
      <div style="background: #F3F3F3;padding: 20px 15px; padding-bottom: 0;margin-bottom: 20px;">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-row>
        <el-col :span="8">
          <el-form-item label="类型" prop="blackType">
            <el-select v-model="queryParams.blackType" placeholder="请选择黑名单类型" clearable>
              <el-option
                v-for="dict in dict.type.heimindtype"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="说明" prop="blackTitle">
            <el-input
              v-model="queryParams.blackTitle"
              placeholder="请输入黑名单说明"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item class="butt">
            <el-button  type="primary"  size="mini" @click="handleQuery">搜索</el-button>
            <el-button  size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>



    </el-form>
    </div>
      <div class="casr">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="handleAdd"
          v-hasPermi="['wuYe:blackManage:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['wuYe:blackManage:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['wuYe:blackManage:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          size="mini"
          @click="handleExport"
          v-hasPermi="['wuYe:blackManage:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table :max-height="tableMaxHeight" v-loading="loading" :data="blackManageList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="黑名单管理id" align="center" prop="blackManageId" /> -->
      <el-table-column label="黑名单类型" align="center" prop="blackType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.heimindtype" :value="scope.row.blackType"/>
        </template>
      </el-table-column>
      <el-table-column label="黑名单说明" align="center" prop="blackTitle" />
      <el-table-column label="黑名单的阈值" align="center" prop="blackNum" />
      <el-table-column label="是否启用" align="center" key="isDel" >
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.isDel"
            active-value="Y"
            inactive-value="N"
            @change="handleStatusChange(scope.row)"
          ></el-switch>
        </template>
      </el-table-column>
      <!-- <el-table-column label="是否启用" align="center" prop="isDel" /> -->
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['wuYe:blackManage:edit']"
            style="color: #28C529;"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleDelete(scope.row)"
            style="color: red;"
            v-hasPermi="['wuYe:blackManage:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    </div>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    </div>

    <!-- 添加或修改黑名单管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
             <el-form-item label="类型" prop="blackType">
               <el-select v-model="form.blackType" placeholder="请选择黑名单类型">
                 <el-option
                   v-for="dict in dict.type.heimindtype"
                   :key="dict.value"
                   :label="dict.label"
                   :value="dict.value"
                 ></el-option>
               </el-select>
             </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="说明" prop="blackTitle">
              <el-input v-model="form.blackTitle" placeholder="请输入黑名单说明" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
          <el-form-item label="阈值" prop="blackNum">
            <el-input v-model="form.blackNum" placeholder="请输入黑名单的阈值" />
          </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否启用" prop="isDel">
              <el-select v-model="form.isDel" placeholder="请选择黑名单类型" clearable>
                <el-option
                  v-for="dict in dict.type.sys_yes_no"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
          <el-form-item label="备注" prop="remark">
            <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
          </el-form-item>
          </el-col>

        </el-row>





      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listBlackManage, getBlackManage, delBlackManage, addBlackManage, updateBlackManage } from "@/api/wuguan/blackManage";

export default {
  name: "BlackManage",
  dicts: ['heimindtype','sys_yes_no'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 黑名单管理表格数据
      blackManageList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        blackType: null,
        blackTitle: null,
        blackNum: null,
        isDel: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        blackType: [
          { required: true, message: "黑名单类型不能为空", trigger: "change" }
        ],

        isDel: [
          { required: true, message: "黑名单是否启用不能为空", trigger: "blur" }
        ],
      },
      tableMaxHeight:'200',
    };
  },
  created() {
    this.getList();
 window.onresize = () => {
 	      this.changeTableMaxHeight()
 	    }
 	    this.changeTableMaxHeight()
 },
 mounted() {
 	window.onresize = () => {
 	          this.changeTableMaxHeight()
 	        }
 	        this.changeTableMaxHeight()
 },
  methods: {
    /** 查询黑名单管理列表 */
    getList() {
      this.loading = true;
      listBlackManage(this.queryParams).then(response => {
        this.blackManageList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        blackManageId: null,
        blackType: null,
        blackTitle: null,
        blackNum: null,
        isDel: 'Y',
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.blackManageId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加黑名单管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const blackManageId = row.blackManageId || this.ids
      getBlackManage(blackManageId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改黑名单管理";
      });
    },
    // 用户状态修改
    handleStatusChange(row) {
      let text = row.isDel === "Y" ? "启用" : "停用";
      console.log(7)
      var that = this
      this.$modal.confirm('确认要"' + text + '"吗？').then(function() {
        console.log(5)
         that.getti(row);
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
      }).catch(function() {
        console.log(6)
        row.isDel = row.isDel === "Y" ? "N" : "Y";
      });
    },
    getti(row){
      console.log(3)
      updateBlackManage(row).then(response => {
        // this.$modal.msgSuccess("修改成功");
        // this.open = false;
        // this.getList();
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.blackManageId != null) {
            updateBlackManage(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBlackManage(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const blackManageIds = row.blackManageId || this.ids;
      this.$modal.confirm('是否确认删除黑名单管理编号为"' + blackManageIds + '"的数据项？').then(function() {
        return delBlackManage(blackManageIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('wuYe/blackManage/export', {
        ...this.queryParams
      }, `blackManage_${new Date().getTime()}.xlsx`)
    },
    // 获取屏幕高度
    showFilterForm () {
          this.filterActive = !this.filterActive
          this.changeTableMaxHeight()
        },

        changeTableMaxHeight () {
          let height = document.body.offsetHeight // 网页可视区域高度
          // if (this.filterActive) {
          //   this.tableMaxHeight = height - 320
          // } else {
            this.tableMaxHeight = height - 150
          // }
          console.log(height)
        }
  }
};
</script>
<style  lang="scss">
  .imagwew{
    .el-upload--picture-card{
      width: 80px;
      height: 80px;
      line-height: 80px;
    }
    .el-upload-list--picture-card .el-upload-list__item{
      width: 80px;
      height: 80px;
    }
  }
  .butt{
    .el-button--small{
      padding: 9px 23px !important;
      font-size: 14px;
    }
  }
  .casr{
    .el-tabs__item.is-active{
      color: #196CFF;
    }
    .el-tabs--card > .el-tabs__header .el-tabs__item{
      padding: 0  30px !important;
    }
  }
  .el-table .el-table__header-wrapper th{
    background-color:#F5F6F8;
    color:#343434;
  }
  .el-table{
    color:#343434;
  }
</style>
<style scoped lang="scss">
  .goe{
    p{
      margin: 0;
      font-weight: 800;
      font-size: 16px;
      color: #161616;
      margin-top: 10px;
      margin-bottom: 3px;
      padding: 0 10px;
      overflow: hidden;
      text-overflow: ellipsis;
      display:-webkit-box; //作为弹性伸缩盒子模型显示。
      -webkit-box-orient:vertical; //设置伸缩盒子的子元素排列方式--从上到下垂直排列
      -webkit-line-clamp:1; //显示的行
    }
    p:nth-child(2){
      // margin-bottom: 10px;
      margin-top: 0;
     font-weight: 400;
     font-size: 14px;
     color: #AAAAAA;
     display: flex;
     justify-content: space-between;
     align-items: center;
     padding-bottom: 10px;
     span:nth-child(2){
       padding: 3px 5px;
       background: #EDEDED;
       border-radius: 10px;
     }
    }
  }
  .ingwe{
    border: 2px solid #196CFF;
  }
  </style>

