<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="reportNickname">
        <el-input
          v-model="queryParams.reportNickname"
          placeholder="请输入举报对象昵称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="举报对象手机" prop="reportMobile">
        <el-input
            v-model="queryParams.reportMobile"
            placeholder="请输入举报对象手机"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="举报对象编号" prop="reportUsercode">
        <el-input
            v-model="queryParams.reportUsercode"
            placeholder="请输入举报对象编号"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </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="reportList" @selection-change="handleSelectionChange">
      <el-table-column label="举报人" align="center" prop="user" >
        <el-table-column label="用户编号" align="center" prop="usercode"/>
        <el-table-column label="昵称" align="center" prop="nickname" show-overflow-tooltip/>
        <el-table-column label="手机号" align="center" prop="mobile" width="100"/>
        <el-table-column label="头像" align="center" prop="avatar">
          <template v-slot="scope">
            <image-avatar :src="scope.row.avatar"/>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="举报对象" align="center" prop="reportUser" >
        <el-table-column label="用户编号" align="center" prop="reportUsercode"/>
        <el-table-column label="昵称" align="center" prop="reportNickname" show-overflow-tooltip/>
        <el-table-column label="手机号" align="center" prop="reportMobile" width="100"/>
        <el-table-column label="头像" align="center" prop="reportAvatar">
          <template v-slot="scope">
            <image-avatar :src="scope.row.reportAvatar"/>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="举报分类" align="center" prop="cateName" />
      <el-table-column label="举报内容" align="center" prop="content" />
      <el-table-column label="举报照片" align="center" prop="contentImage">
        <template v-slot="scope">
            <span v-for='val in scope.row.contentImageArray'>
              <image-preview :src="val" height="40px" width="40px"  /> &nbsp;
            </span>
        </template>
      </el-table-column>
      <el-table-column label="状态 " align="center" prop="reportStatus" >
        <template v-slot="scope">
          <cai-dict-tag :options="reportStatusList" :value="scope.row.reportStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template v-slot="scope">
          <el-button
            size="mini"
            type="text"
            v-if="scope.row.reportStatus === 0"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['xq:report:edit']"
          >已处理</el-button>
        </template>
      </el-table-column>
    </el-table>

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

<script>
import { closeReport, listReport } from '@/api/xq/report'
import { reportStatusList } from '@/constant/statusMap'

export default {
  name: "Report",
  data() {
    return {
      reportStatusList,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 举报表格数据
      reportList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        reportNickname: undefined,
        reportUsercode: undefined,
        reportMobile: undefined,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询举报列表 */
    getList() {
      this.loading = true;
      listReport(this.queryParams).then(response => {
        let rows = response.rows
        for (let index in rows){
          rows[index].contentImageArray = rows[index].contentImage ? rows[index].contentImage.split(",") : [];
        }
        this.reportList = 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
    },
    handleUpdate(row) {
      this.loading = true;
      closeReport({ "id":row.id }).then(response => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("处理成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });;
    },
  }
};
</script>
