<template>
  <div class='app-container'>
    <!-- 搜索 -->
    <el-form inline size="mini">
      <el-form-item label="用户Id：">
        <el-input v-model="form.uid" placeholder="请输入用户Id" clearable />
      </el-form-item>
      <el-form-item label="手机号：">
        <el-input v-model="form.phone" placeholder="请输入用户手机号" clearable />
      </el-form-item>
      <el-form-item label="反馈类型：">
        <el-select v-model="form.type" placeholder="请选择反馈类型" clearable>
          <el-option v-for="item in typeOptions" :key="item.value" :value="item.value" :label="item.label" />
        </el-select>
      </el-form-item>
      <el-form-item label="反馈时间：">
        <el-date-picker v-model="form.listDate" type="datetimerange" start-placeholder="开始日期" end-placeholder="结束日期"
          value-format="yyyy-MM-dd HH:mm:ss" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="getSearch">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="getRefresh">重置</el-button>
        <el-button type="primary" icon="el-icon-download" @click="getDownload">导出</el-button>
      </el-form-item>
    </el-form>
    <!-- 列表 -->
    <el-table :data="tableData" v-loading="loading">
      <el-table-column label="序号" type="index" align="center" />
      <el-table-column label="用户Id" prop="uid" align="center" show-overflow-tooltip />
      <el-table-column label="手机号" prop="phone" align="center" />
      <el-table-column label="图片" align="center" width="100px">
        <template slot-scope="scope">
          <el-image :src="scope.row.url.split(',')[0]">
            <span slot="error">-</span>
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="反馈类型" prop="type" align="center" />
      <el-table-column label="反馈内容" prop="content" align="center" show-overflow-tooltip />
      <el-table-column label="回复" prop="reply" align="center" show-overflow-tooltip />
      <el-table-column label="反馈时间" prop="updateTime" align="center" />
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="text" @click="getDetail(scope.row.id, true)">查看</el-button>
          <el-button type="text" @click="getDetail(scope.row.id)">回复</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="form.pageNum" :limit.sync="form.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { list, typeList } from '@/api/operation/feedbacklist'
export default {
  data() {
    return {
      // 遮罩层
      loading: false,
      // 表单
      form: {
        pageNum: 1,
        pageSize: 10
      },
      // 总数据
      total: 0,
      // 列表
      tableData: [],
      // 反馈类型
      typeOptions: []
    }
  },
  mounted() {
    this.getList()
    this.getTypeList()
  },
  methods: {
    // 列表
    getList() {
      this.loading = true
      list(this.form).then(res => {
        if (res.code === 0) {
          this.tableData = res.data.records
          this.total = res.data.total
          this.loading = false
        }
      })
    },

    // 反馈类型
    getTypeList() {
      typeList().then(res => {
        if (res.code === 0) {
          res.data.map(i => {
            this.typeOptions.push({
              value: i.id,
              label: i.name
            })
          })
        }
      })
    },

    // 搜索
    getSearch() {
      this.form.pageNum = 1
      this.getList()
    },

    // 重置
    getRefresh() {
      this.form = {
        pageNum: 1,
        pageSize: 10
      }
      this.getList()
    },

    // 导出
    getDownload() {
      this.download('/admin/opinions/excelDownload', this.form, '反馈列表.xlsx')
    },

    // 查看 回复
    getDetail(id, boolean) {
      this.$router.push({
        path: `/operation/feedback/feedbacklist/detail`,
        query: {
          id: id,
          boolean: boolean
        }
      })
    }
  }
}
</script>