<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" @submit.native.prevent>
      <el-form-item label="反馈类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择类型" @change="change" clearable>
          <el-option v-for="dict in dict.type.feedback" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
        </el-select>
      </el-form-item>
      <el-button type="primary" icon="el-icon-plus" @click="op('add')" style="float: right">提交问题</el-button>
    </el-form>
    <el-table :data="response.rows" border height="calc(100vh - 233px)">
      <el-table-column type="index" label="序号" align="center" width="80" />
      <el-table-column label="反馈标题" align="left" prop="title" />
      <el-table-column label="反馈类型" align="center" prop="type" width="180" />
      <el-table-column label="反馈状态" align="center" prop="state" width="140">
        <template slot-scope="scope">
          <el-tag type="danger" v-if="scope.row.state == 0">待处理</el-tag>
          <el-popover placement="top-start" v-if="scope.row.state == 1" title="回复内容" width="200" trigger="hover" :content="scope.row.msg">
            <div slot="reference" :title="'回复时间：' + scope.row.updateTime">
              <el-tag type="success">已处理</el-tag>
              <i class="el-icon-warning"></i>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="200" />
      <el-table-column label="操作" align="center" width="200">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="op('detail', scope.row)">详情</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="del(scope.row)">删除</el-button>
        </template>
      </el-table-column>
      <template slot="empty">
        <el-empty></el-empty>
      </template>
    </el-table>
    <pagination v-if="response.total > 0" :total="response.total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
  </div>
</template>

<script>
import edit from './edit';
export default {
  dicts: ['feedback'],
  name: 'Feedback',
  data() {
    return {
      showSearch: true,
      response: {},
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        type: null,
        orderByColumn: 'id',
        isAsc: 'desc'
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.ajax({ url: '/work/feedback/list', data: this.queryParams }).then((response) => {
        this.response = response;
      });
    },
    change() {
      this.getList();
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      this.resetForm('queryForm');
      this.handleQuery();
    },
    op(tag, row) {
      if (tag == 'add') {
        this.iframe({ obj: edit, param: {}, title: '提交问题', width: '58%', height: '67%' });
      }
      if (tag == 'detail') {
        this.iframe({ obj: edit, param: { id: row.id, detail: true }, title: '查看详情', width: '58%', height: '67%' });
      }
    },
    del(row) {
      this.$confirm('是否确认删除选中数据?', '警告', { type: 'warning' }).then(() => {
        this.get({ url: '/work/feedback/delByUser/' + row.id }).then((response) => {
          this.$modal.msgSuccess('删除成功');
          this.getList();
        });
      });
    }
  }
};
</script>
