<template>
<div class="app-container calendar-list-container">
  <div class="filter-container">
    <!-- 筛选条件 -->
    <div class="filter-container">
      <el-date-picker class="filter-item"
          v-model="params.date" style="display: inline-flex;width:230px" 
          type="daterange" 
          placeholder="请选择订单日期范围"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>      
      <el-input @keyup.enter.native="handleSearch" style="width: 138px;" class="filter-item" clearable placeholder="用户手机号" v-model="params.search_eq_mobile"></el-input>
      <el-input @keyup.enter.native="handleSearch" style="width: 200px;" class="filter-item" clearable placeholder="订单号" v-model="params.orderSn"></el-input>
      <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>
    </div>
  </div>

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

      <!-- 用户ID -->
      <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">
          <span>{{scope.row.mobile}}</span>
        </template>
      </el-table-column>

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

      <!-- 预约课程支付订单号 -->
      <el-table-column align="center" label="订单号">
        <template scope="scope">
          <span>{{scope.row.orderSn}}</span>
        </template>
      </el-table-column>

      <!-- 预约数量 -->
      <el-table-column align="center" label="预约数量">
        <template scope="scope">
          <span>{{scope.row.counts}}</span>
        </template>
      </el-table-column>

      <!-- 支付方式 -->
      <el-table-column align="center" label="支付方式">
        <template scope="scope">
          <span v-if="scope.row.payType === 1">现金支付</span>
          <span v-if="scope.row.payType === 2">会员卡</span>
        </template>
      </el-table-column>

      <!-- 用户会员卡 -->
      <el-table-column align="center" label="会员卡类型">
        <template scope="scope">
          <span>{{scope.row.cardType}}</span>
        </template>
      </el-table-column>

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

      <!-- 使用状态 -->
      <el-table-column align="center" label="使用状态">
        <template scope="scope">
          <TicketStatus :status="scope.row.status"></TicketStatus>
          <!-- <span v-if="scope.row.status === 1">已使用</span>
          <span v-if="scope.row.status === 2">已取消</span>
          <span v-if="scope.row.status === 3">已过期未签到</span>
          <span v-if="scope.row.status === 0">未使用</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>
      </template>
    </el-table-column>
  </Pagination>
</div>
</template>

<script>
import { remove, updateStatus } from '@/api//member/lesson/ticket'
import waves from '@/directive/waves.js'// 水波纹指令
import Pagination from '@/components/Pagination'
import Status from '@/components/Status'
import moment from 'moment'
import PayStatus from '@/components/PayStatus'
import TicketStatus from '@/components/TicketStatus'

export default {
  name: 'memberLessonTicket_list',
  components: { Pagination, Status, PayStatus, TicketStatus },
  directives: {
    waves
  },
  data() {
    return {
      params: {
        search_eq_mobile: '',
        payStatus: 1,
        orderSn: undefined,
        search_like_nickname: '',
        starTime: '',
        endTime: '',
        lessonId: undefined,
        inStock: 1
      }
    }
  },
  created() {
    this.params.lessonId = this.$route.query.id
  },
  methods: {
    /**
     * 搜索预约场馆课程订单
     */
    handleSearch() {
      if (this.params.date != null) {
        this.params.endTime = moment(this.params.date[1]).format('YYYY-M-D HH:mm:ss')
        this.params.starTime = moment(this.params.date[0]).format('YYYY-M-D HH:mm:ss')
      } else {
        this.params.starTime = ''
        this.params.endTime = ''
      }
      this.$refs.pagination.handleSearch()
    },

    /**
     * 编辑预约场馆课程订单
     */
    handleEdit(id) {
      this.$router.push({ path: '/member/lesson/ticket/edit', query: { id: id }})
    },

    /**
     * 创建预约场馆课程订单
     */
    handleCreate() {
      this.$router.push({ path: '/member/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>

