<template>
<div class="app-container calendar-list-container">
  <!-- 筛选条件 -->
  <div class="filter-container">
      <el-select v-model="params.search_eq_status" style="width: 120px" class="filter-item" clearable placeholder="状态">
      <el-option v-for="item in options.status"
        :key="item.value"
        :label="item.label"
        :value="item.value">
      </el-option>
    </el-select>

    <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="/venue/lesson/tickets" :request-params="params" ref="pagination">

      <!-- 场馆类型 -->
      <el-table-column align="center" label="场馆类型">
        <template scope="scope">
          <span>{{scope.row.veneuType}}</span>
        </template>
      </el-table-column>

      <!-- 场馆ID -->
      <el-table-column align="center" label="场馆ID">
        <template scope="scope">
          <span>{{scope.row.venueId}}</span>
        </template>
      </el-table-column>

      <!-- 课程票号 -->
      <el-table-column align="center" label="课程票号">
        <template scope="scope">
          <span>{{scope.row.ticket}}</span>
        </template>
      </el-table-column>

      <!-- 课程ID -->
      <el-table-column align="center" label="课程ID">
        <template scope="scope">
          <span>{{scope.row.lessonId}}</span>
        </template>
      </el-table-column>

      <!-- 状态 -->
      <el-table-column align="center" label="状态">
        <template scope="scope">
          <Status :status="scope.row.status"></Status>
        </template>
      </el-table-column>

      <!-- 平台来源ID -->
      <el-table-column align="center" label="平台来源ID">
        <template scope="scope">
          <span>{{scope.row.platformId}}</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 v-if="scope.row.status === 1" size="small" type="text" @click="handleUpdateStatus(scope.row, 0)">禁用</el-button>
        <el-button v-if="scope.row.status === 0" size="small" type="text" @click="handleUpdateStatus(scope.row, 1)">启用</el-button>
        <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, updateStatus } from '@/api//venue/lesson/ticket'
import waves from '@/directive/waves.js'// 水波纹指令
import Pagination from '@/components/Pagination'
import Status from '@/components/Status'
import statusOptions from '@/utils/constants.js'

export default {
  name: 'venueLessonTicket_list',
  components: { Pagination, Status },
  directives: {
    waves
  },
  data() {
    return {
      params: {
        search_eq_status: undefined
      },
      options: {
        status: statusOptions
      }
    }
  },
  created() {
  },
  methods: {
    /**
     * 搜索课程票据
     */
    handleSearch() {
      this.$refs.pagination.handleSearch()
    },

    /**
     * 编辑课程票据
     */
    handleEdit(id) {
      this.$router.push({ path: '/venue/lesson/ticket/edit', query: { id: id }})
    },

    /**
     * 创建课程票据
     */
    handleCreate() {
      this.$router.push({ path: '/venue/lesson/ticket/edit' })
    },

    /**
     * 更新课程票据状态
     */
    handleUpdateStatus(row, status) {
      updateStatus(row.id, status).then(response => {
        this.$refs.pagination.pageRequest()
      })
    },

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

