<template>
<div class="app-container calendar-list-container">
  <!-- 筛选条件 -->
  <div class="filter-container">
    <el-input @keyup.enter.native="handleSearch" style="width: 120px;" class="filter-item" placeholder="昵称" v-model="params.search_like_nickname"></el-input>

    <el-button class="filter-item" type="primary" v-waves icon="search" @click="handleSearch">搜索</el-button>
    <el-button class="filter-item pull-right" type="success" icon="edit" @click="handleCreate">添加</el-button>
  </div>

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

      <!-- 昵称 -->
      <el-table-column align="center" label="昵称">
        <template scope="scope">
          <span>{{scope.row.nickname}}</span>
        </template>
      </el-table-column>

      <!-- 图像 -->
      <el-table-column align="center" label="图像">
        <template scope="scope">
          <img :src="scope.row.avatar" style="width:100px;height:100px">          
        </template>
      </el-table-column>

      <!-- 二维码 -->
      <el-table-column align="center" label="签到二维码">
        <template scope="scope">
          <img :src="scope.row.qrCode" style="width:100px;height:100px">          
        </template>
      </el-table-column>

      <el-table-column align="center" label="微信二维码">
        <template scope="scope">
          <img :src="scope.row.wechatCode" style="width:100px;height:100px">          
        </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//coach'
import waves from '@/directive/waves.js'// 水波纹指令
import Pagination from '@/components/Pagination'

export default {
  name: 'coach_list',
  components: { Pagination },
  directives: {
    waves
  },
  data() {
    return {
      params: {
        search_like_nickname: undefined
      }
    }
  },
  created() {
  },
  methods: {
    /**
     * 搜索教练
     */
    handleSearch() {
      this.$refs.pagination.handleSearch()
    },

    /**
     * 编辑教练
     */
    handleEdit(id) {
      this.$router.push({ path: '/coach/edit', query: { id: id }})
    },

    /**
     * 创建教练
     */
    handleCreate() {
      this.$router.push({ path: '/coach/edit' })
    },

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

