<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="封号对象" prop="member">
        <el-input
            v-model="queryParams.member"
            placeholder="请输入封号对象"
            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 label="封号时长" prop="forbidTime">
        <el-select v-model="queryParams.forbidTime" clearable size="small">
          <el-option
              v-for="dict in forbidTimeList"
              :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="userForbidLogList" @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.nickname}}【{{scope.row.member}}】<image-avatar :src="scope.row.avatar"/>
          </div>
          <span v-if="scope.row.type !== 1">
            {{scope.row.member}}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="封号时长" align="center" prop="forbidTime">
        <template v-slot="scope">
          <cai-dict-tag :options="forbidTimeList" :value="scope.row.forbidTime" />
        </template>
      </el-table-column>
      <el-table-column label="理由" align="center" prop="reason"/>
      <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 {listUserForbidLog} from "@/api/cai/userForbidLog";
import {forbidStatusList, forbidTimeList, forbidTypeList} from "@/constant/statusMap";

export default {
  name: "UserForbidLog",
  data() {
    return {
      forbidTimeList,forbidTypeList,forbidStatusList,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 封禁记录表格数据
      userForbidLogList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        type: undefined,
        member: undefined,
        forbidTime: undefined,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询封禁记录列表 */
    getList() {
      this.loading = true;
      listUserForbidLog(this.queryParams).then(response => {
        this.userForbidLogList = 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
    },
  }
};
</script>
<style lang="scss" scoped>
  .context-avatar-center {
    display: flex;
    align-items: center; /* 垂直居中 */
    justify-content: center; /* 水平居中 */
  }
</style>
