<template>
<div class="app-container calendar-list-container">
  <!-- 筛选条件 -->
  <div class="filter-container" style="margin-bottom: 50px;">
    <el-button class="filter-item pull-right " type="success" icon="edit" @click="handleCreate">添加</el-button>
  </div>


  <!-- 列表数据 -->
  <Pagination uri="/faqs" :request-params="params" ref="pagination">

      <!-- 问题 -->
      <el-table-column align="center" label="问题">
        <template scope="scope">
          <span>{{scope.row.problem}}</span>
        </template>
      </el-table-column>

      <!-- 答案 -->
      <el-table-column align="center" label="答案">
        <template scope="scope">
          <span>{{scope.row.answer}}</span>
        </template>
      </el-table-column>

      <!-- 创建时间 -->
      <el-table-column align="center" label="创建时间">
        <template scope="scope">
          <span>{{scope.row.createdTime | parseTime('{y}-{m}-{d} {h}:{i}')}}</span>
        </template>
      </el-table-column>

    <el-table-column label="操作" align="center" width="150">
      <template scope="scope">
        <el-button size="small" type="text" @click="handleEdit(scope.row.id)">编辑</el-button>
        <el-button size="small" type="text" class="danger" @click="handleDelete(scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </Pagination>
</div>
</template>

<script>
import { remove } from '@/api//faq'
import waves from '@/directive/waves.js'// 水波纹指令
import Pagination from '@/components/Pagination'

export default {
  name: 'faq_list',
  components: { Pagination },
  directives: {
    waves
  },
  data() {
    return {
      params: {
      }
    }
  },
  created() {
  },
  methods: {
    /**
     * 搜索常见问题
     */
    handleSearch() {
      this.$refs.pagination.handleSearch()
    },

    /**
     * 编辑常见问题
     */
    handleEdit(id) {
      this.$router.push({ path: '/faq/edit', query: { id: id }})
    },

    /**
     * 创建常见问题
     */
    handleCreate() {
      this.$router.push({ path: '/faq/edit' })
    },

    /**
     * 删除常见问题
     */
    handleDelete(row) {
      this.$confirm('确认删除该常见问题？').then(_ => {
        remove(row.id).then(response => {
          this.$refs.pagination.removeItem(row)
        })
      }).catch(_ => {})
    }
  }
}
</script>

