<template>
  <ai-list class="notice">
    <template slot="title">
      <ai-title title="意见反馈" isShowBottomBorder></ai-title>
    </template>
    <template slot="content">
      <ai-search-bar class="search-bar">
        <template slot="right">
          <el-input
            v-model="search.opinion"
            class="search-input"
            size="small"
            v-throttle="() => {search.current = 1, getList()}"
            placeholder="内容描述/上报人"
            clearable
            @change="getList"
            @clear="search.current = 1, search.opinion = '', getList()"
            suffix-icon="iconfont iconSearch">
          </el-input>
        </template>
      </ai-search-bar>
      <ai-table
        :tableData="tableData"
        :col-configs="colConfigs"
        :total="total"
        style="margin-top: 6px;"
        :current.sync="search.current"
        :size.sync="search.size"
        @getList="getList">
        <el-table-column slot="tags" label="标签">
          <template slot-scope="{ row }">
            <div class="table-tags">
              <el-tag type="info" v-for="(item, index) in row.tags" size="small" :key="index">{{ item }}</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column slot="options" width="120px" fixed="right" label="操作" align="center">
          <div class="table-options" slot-scope="{ row }">
            <el-button type="text" @click="toDetail(row.id)">详情</el-button>
            <el-button type="text" @click="remove(row.id)">删除</el-button>
          </div>
        </el-table-column>
      </ai-table>
    </template>
  </ai-list>
</template>

<script>
  import { mapState } from 'vuex'
  export default {
    name: 'List',

    props: {
      instance: Function,
      dict: Object
    },

    data() {
      return {
        search: {
          current: 1,
          size: 10,
          opinion: ''
        },
        currIndex: -1,
        areaList: [],
        total: 10,
        colConfigs: [
          {prop: 'opinion', label: '内容描述', align: 'left'},
          {prop: 'contacts', label: '上报人', align: 'center' },
          {prop: 'phone', label: '联系方式', align: 'center'},
          {prop: 'sourceHost', label: '平台', align: 'center' },
          {prop: 'createTime', label: '发布时间', align: 'center' },
          {slot: 'options', label: '操作'}
        ],
        tableData: []
      }
    },

    computed: {
      ...mapState(['user'])
    },

    mounted() {
      this.getList()
    },

    methods: {
      getList() {
        this.instance.post(`/appfeedback/list`, null, {
          params: {
            ...this.search
          }
        }).then(res => {
          if (res.code == 0) {
            this.tableData = res.data.records
            this.total = res.data.total
          }
        })
      },

      remove(id) {
        this.$confirm('确定删除该数据？').then(() => {
          this.instance.post(`/appfeedback/delete?ids=${id}`).then(res => {
            if (res.code == 0) {
              this.$message.success('删除成功！')
              this.getList()
            }
          })
        })
      },

      toDetail (id) {
        this.$emit('change', {
          type: 'Detail',
          params: {
            id: id || ''
          }
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
</style>
