<template>
  <div class="app-container">
    <!-- 搜索区域 -->
    <div class="filter-container">
      <div class="filter-control">
        <span>机构名称:</span>
        <el-input v-model="listQuery.clubName" placeholder="机构名称" @keyup.enter.native="getList" />
      </div>
      <div class="filter-control">
        <span>手机号:</span>
        <el-input v-model="listQuery.mobile" placeholder="手机号" @keyup.enter.native="handleFilter" />
      </div>
      <div class="filter-control">
        <span>处理状态:</span>
        <el-select v-model="listQuery.handleStatus" placeholder="处理状态" clearable @change="getList">
          <el-option label="全部" value="" />
          <el-option label="已处理" :value="1" />
          <el-option label="未处理" :value="0" />
        </el-select>
      </div>
      <div class="filter-control">
        <permission-button type="primary" @click="getList">查询</permission-button>
      </div>
    </div>
    <!-- 搜索区域END -->
    <!-- 表格区域 -->
    <el-table
      v-loading="listLoading"
      :data="list"
      style="width: 100%"
      border
      fit
      highlight-current-row
      cell-class-name="table-cell"
      header-row-class-name="tableHeader"
    >
      <el-table-column type="expand" width="50">
        <template slot-scope="{ row }">
          <el-form label-position="left" class="table-expand" label-width="110px">
            <el-form-item label="机构名称：">
              <span>{{ row.clubName }}</span>
            </el-form-item>
            <el-form-item label="手机号：">
              <span>{{ row.mobile }}</span>
            </el-form-item>
            <el-form-item label="提交时间：" width="160px">
              <span>{{ row.commitTime | formatTime }}</span>
            </el-form-item>
            <el-form-item label="处理状态：">
              <span v-if="row.handleStatus === 0" class="status warning">未处理</span>
              <span v-if="row.handleStatus === 1" class="status success">已处理</span>
            </el-form-item>
            <el-form-item label="反馈内容：">
              <span style="overflow-wrap: anywhere; text-align: justify">{{ row.content }}</span>
            </el-form-item>
            <el-form-item label="处理结果：">
              <span>{{ row.handleResult }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column label="序号" :index="indexMethod" type="index" width="80" align="center" />
      <el-table-column label="机构名称" prop="clubName" align="center" />
      <el-table-column label="手机号" prop="mobile" width="120" align="center" />
      <el-table-column label="反馈内容" prop="content" align="center">
        <template slot-scope="{ row }">
          <span class="content">{{ row.content }}</span>
        </template>
      </el-table-column>
      <el-table-column label="提交时间" width="160px" align="center">
        <template slot-scope="{ row }">
          <span v-if="row.auditStatus !== 2">{{ row.commitTime | formatTime }}</span>
          <span v-else>—</span>
        </template>
      </el-table-column>
      <el-table-column label="处理状态" width="100px" align="center">
        <template slot-scope="{ row }">
          <span v-if="row.handleStatus === 0" class="status warning">未处理</span>
          <span v-if="row.handleStatus === 1" class="status success">已处理</span>
        </template>
      </el-table-column>
      <el-table-column label="处理结果" prop="handleResult" align="center">
        <template slot-scope="{ row }">
          <span v-if="row.handleStatus === 1" class="content">{{ row.handleResult }}</span>
          <span v-else>—</span>
        </template>
      </el-table-column>
      <el-table-column label="处理时间" width="160px" align="center">
        <template slot-scope="{ row }">
          <span v-if="row.handleStatus === 1">{{ row.handleTime | formatTime }}</span>
          <span v-else>—</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="120px" align="center">
        <template slot-scope="{ row }">
          <permission-button
            type="primary"
            size="mini"
            style="margin-right: 12px"
            @click="navigationTo(`/feedback/detail?feedbackId=${row.feedbackId}`)"
          >处理</permission-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 表格区域END -->
    <!-- 页码 -->
    <pagination
      :total="total"
      :page.sync="listQuery.pageNum"
      :limit.sync="listQuery.pageSize"
      @pagination="getList(listQuery)"
    />
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { getFeedbackList } from '@/api/auth'
export default {
  name: 'FeedbackList',
  data() {
    return {
      listLoading: false,
      listQuery: {
        authUserId: '',
        clubName: '',
        handleStatus: '',
        mobile: '',
        pageNum: 1, // 页码
        pageSize: 10 // 分页大小
      },
      total: 0,
      list: []
    }
  },
  computed: {
    ...mapGetters(['authUserId', 'userIdentity'])
  },
  created() {
    this.getList()
  },
  activated() {
    this.getList()
  },
  methods: {
    // 获取列表数据
    getList() {
      this.listQuery.authUserId = this.authUserId
      console.log(this.listQuery)
      getFeedbackList(this.listQuery)
        .then((res) => {
          console.log(res)
          if (res.code !== 0) return
          this.list = res.data.list
          this.total = res.data.total
        })
        .catch((err) => {
          console.log(err)
        })
    },
    // 初始化预览图片列表
    initPreviewList(list) {
      list.forEach((item) => this.srcList.push(item.articleCover))
    },
    indexMethod(index) {
      return index + this.listQuery.pageSize * (this.listQuery.pageNum - 1) + 1
    }
  }
}
</script>

<style lang="scss" scoped>
.content {
  display: block;
  overflow: hidden !important;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.el-table .cell {
  overflow: visible;
}
.el-badge {
  margin: 0 6px;
}
</style>
