<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="拦截手机号" prop="userMobile">
        <el-input
            v-model="queryParams.userMobile"
            placeholder="请输入拦截用户手机号"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="'拦截'+systemName+'号'" prop="userUsercode">
        <el-input
            v-model="queryParams.userUsercode"
            :placeholder="'请输入拦截用户'+systemName+'号'"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="拦截对象" prop="member">
        <el-input
            v-model="queryParams.member"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="拦截编号" prop="traceNo">
        <el-input
            v-model="queryParams.traceNo"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="拦截类型" prop="type">
        <el-select v-model="queryParams.type" clearable size="small">
          <el-option
              v-for="dict in forbidTypeList"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
              @keyup.enter.native="handleQuery"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="forbidFilterList" @selection-change="handleSelectionChange">
<!--      <el-table-column type="selection" width="55" align="center"/>-->
      <el-table-column label="类型" align="center" prop="type">
        <template v-slot="scope">
          <cai-dict-tag :options="forbidTypeList" :value="scope.row.type" />
        </template>
      </el-table-column>
      <el-table-column label="拦截对象" align="center" prop="member">
        <template v-slot="scope">
          <div class="context-avatar-center" v-if="scope.row.type === 1">
            {{scope.row.memberNickname}}【{{scope.row.member}}】<image-avatar :src="scope.row.memberAvatar"/>
          </div>
          <span v-if="scope.row.type !== 1">
            {{scope.row.member}}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="拦截用户手机号" align="center" prop="userMobile"/>
      <el-table-column :label="'拦截用户'+systemName+'号'" align="center" prop="userUsercode"/>
      <el-table-column label="拦截编号" align="center" prop="traceNo"/>
      <el-table-column label="理由" align="center" prop="filterReason"/>
      <el-table-column label="拦截时间" align="center" prop="createTime"/>
    </el-table>

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

  </div>
</template>

<script>
import {listForbidFilter} from "@/api/cai/forbidFilter";
import {forbidStatusList, forbidTimeList, forbidTypeList} from "@/constant/statusMap";

export default {
  name: "ForbidFilter",
  data() {
    return {
      systemName: process.env.VUE_APP_SYSTEM_HOME,
      forbidTimeList, forbidTypeList, forbidStatusList,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 登陆拦截记录表格数据
      forbidFilterList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        type: undefined,
        member: undefined,
        traceNo: undefined,
        userMobile: undefined,
        userUsercode: undefined,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询登陆拦截记录列表 */
    getList() {
      this.loading = true;
      listForbidFilter(this.queryParams).then(response => {
        this.forbidFilterList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
    },
    /** 提交按钮 */
    submitForm() {
    },
    /** 删除按钮操作 */
    handleDelete(row) {
    },
  }
};
</script>
<style lang="scss" scoped>
.context-avatar-center {
  display: flex;
  align-items: center; /* 垂直居中 */
  justify-content: center; /* 水平居中 */
}
</style>
