<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" @submit.native.prevent v-show="showSearch">
      <el-form-item label="反馈标题" prop="title">
        <el-input v-model="queryParams.title" placeholder="请输入反馈标题" @keyup.enter.native="handleQuery" clearable />
      </el-form-item>
      <el-form-item label="反馈类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择类型">
          <el-option v-for="dict in dict.type.feedback" :key="dict.value" :label="dict.label" :value="dict.value" clearable></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="反馈状态" prop="state">
        <el-select v-model="queryParams.state" placeholder="请选择状态" clearable class="inp">
          <el-option value="0" label="待处理"></el-option>
          <el-option value="1" label="已处理"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-button type="success" icon="el-icon-edit" :disabled="ids.length != 1" @click="op('edit', ids)" v-hasPermi="['work:feedback:edit']">回复</el-button>
      <el-button type="danger" icon="el-icon-delete" :disabled="ids.length == 0" @click="del" v-hasPermi="['work:feedback:remove']">删除{{ ids.length > 0 ? '(' + ids.length + ')' : '' }}</el-button>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table :data="response.rows" border @selection-change="selects" height="calc(100vh - 270px)">
      <el-table-column type="selection" width="55" align="center" />
      <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)" v-hasPermi="['work:feedback:edit']">详情</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="op('edit', scope.row)" v-hasPermi="['work:feedback:edit']" v-if="scope.row.state == 0">回复</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="del(scope.row)" v-hasPermi="['work:feedback:remove']">删除</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 {
      ids: [],
      showSearch: true,
      response: {},
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        title: null,
        type: null,
        state: null,
        orderByColumn: 'id',
        isAsc: 'desc'
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.ajax({ url: '/work/feedback/list', data: this.queryParams }).then((response) => {
        this.response = response;
      });
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      this.resetForm('queryForm');
      this.handleQuery();
    },
    selects(rows) {
      this.ids = rows.map((item) => item.id);
    },
    op(tag, row) {
      if (tag == 'detail') {
        this.iframe({ obj: edit, param: { id: row.id, detail: true }, title: '查看详情', width: '58%', height: '67%' });
      }
      if (tag == 'edit') {
        this.$prompt('确定处理', {
          type: 'warning',
          showInput: true,
          inputType: 'textarea',
          inputPlaceholder: '回复消息',
          inputValidator: (value) => {}
        }).then(({ value }) => {
          this.ajax({ method: 'post', url: '/work/feedback/edit', data: { id: row.id, msg: value } }).then((response) => {
            this.$modal.msgSuccess('处理成功');
            this.getList();
          });
        });
      }
    },
    del(row) {
      this.$confirm('是否确认删除选中数据?', '警告', { type: 'warning' }).then(() => {
        this.get({ url: '/work/feedback/remove/' + (row.id || this.ids) }).then((response) => {
          this.$modal.msgSuccess('删除成功');
          this.getList();
        });
      });
    }
  }
};
</script>
