<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="usercode">
        <el-input
          v-model="queryParams.usercode"
          placeholder="请输入用户号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="留言手机" prop="feedbackMobile">
        <el-input
          v-model="queryParams.feedbackMobile"
          placeholder="请输入留言手机"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="reportStatus">
        <el-select v-model="queryParams.reportStatus" placeholder="处理状态" clearable size="small">
          <el-option
            v-for="dict in feedbackStatusList"
            :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="feedbackList" @selection-change="handleSelectionChange">
      <el-table-column label="用户号" align="center" prop="usercode" />
      <el-table-column label="留言标题" align="center" prop="title" />
      <el-table-column label="留言内容" align="center" prop="content" />
      <el-table-column label="留言手机" align="center" prop="feedbackMobile" />
      <el-table-column label="状态" align="center" prop="reportStatus" >
        <template v-slot="scope">
          <cai-dict-tag :options="feedbackStatusList" :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"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['xq:feedback:edit']"
          >确认处理</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['xq:feedback:remove']"
          >删除</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 { delFeedback, listFeedback, updateFeedback } from '@/api/xq/feedback'
import { feedbackStatusList } from '@/constant/statusMap'

export default {
  name: "Feedback",
  data() {
    return {
      feedbackStatusList,
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 留言举报表格数据
      feedbackList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        usercode: undefined,
        feedbackMobile: undefined,
        reportStatus: 0,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询留言举报列表 */
    getList() {
      this.loading = true;
      listFeedback(this.queryParams).then(response => {
        this.feedbackList = 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.$modal.confirm('是否确认处理该举报留言的数据项？').then(() => {
        this.loading = true;
        return updateFeedback({
          id: row.id,
          reportStatus: 1,
        });
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("操作成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除留言举报编号为"' + ids + '"的数据项？').then(() => {
        this.loading = true;
        return delFeedback(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
  }
};
</script>
