<template>
<div class="app-container calendar-list-container">
  <div class="filter-container">
    <!-- 筛选条件 -->
    <div class="filter-container">
      <el-input @keyup.enter.native="handleSearch" style="width: 170px;" class="filter-item" placeholder="用户昵称" v-model="params.search_like_nickname"></el-input>
      <el-input @keyup.enter.native="handleSearch" style="width: 200px;" class="filter-item" clearable placeholder="课程" v-model="params.lessonname"></el-input>
      <el-input @keyup.enter.native="handleSearch" style="width: 200px;" class="filter-item" clearable placeholder="订单号" v-model="params.orderSn"></el-input>
     <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-select v-model="params.search_eq_smlt$status"  style="width: 150px" class="filter-item" clearable placeholder="使用状态">
        <el-option v-for="item in options.statu"
          :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>
    </div>
  </div>

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

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

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

      <el-table-column align="center" label="上课时间" width="185">
        <template scope="scope">
          <span>{{scope.row.venueLesson.date}} {{scope.row.venueLesson.startTime}}-{{scope.row.venueLesson.endTime}}</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="课程数量" width="50">
        <template scope="scope">
          <span>{{scope.row.counts}}</span>
        </template>
      </el-table-column>

      <!-- 手机号 -->
      <el-table-column align="center" label="手机号" width="120">
        <template scope="scope">
          <span>{{scope.row.mobile}}</span>
        </template>
      </el-table-column>

      <!-- 预约课程支付订单号 -->
      <!-- <el-table-column align="center" label="订单号" width="180">
        <template scope="scope">
          <span>{{scope.row.orderSn}}</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="会员卡类型" width="100">
        <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="完成状态" width="120">
        <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 === 0">未使用</span>
          <span v-if="scope.row.status === 3">已过期未签到</span> -->
        </template>
      </el-table-column>

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

    <el-table-column label="操作" align="center" width="50">
      <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 TicketStatus from '@/components/TicketStatus'
import moment from 'moment'
import PayStatus from '@/components/PayStatus'

export default {
  name: 'memberLessonTicket_list',
  components: { Pagination, PayStatus, TicketStatus },
  directives: {
    waves
  },
  data() {
    return {
      activeName: '1',
      params: {
        search_eq_mobile: '',
        orderSn: undefined,
        search_like_nickname: '',
        lessonname: undefined,
        starTime: '',
        endTime: '',
        payStatus: 1,
        lessonId: '',
        search_eq_smlt$status: undefined
      },
      options: {
        statu: [
          {
            value: 0,
            label: '未使用'
          },
          {
            value: 1,
            label: '已使用'
          },
          {
            value: 2,
            label: '已取消'
          },
          {
            value: 3,
            label: '已过期'
          }
        ]
      }
    }
  },
  created() {
  },
  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 = ''
      }
      if (this.params.orderSn === '') {
        this.params.orderSn = undefined
      }
      if (this.params.lessonname === '') {
        this.params.lessonname = undefined
      }
      this.$refs.pagination.pageRequest()
    },

    handleClick(tab, event) {
      if (tab.index === '0') {
        this.params.payStatus = undefined
        this.handleSearch()
      }
      if (tab.index === '1') {
        this.params.payStatus = -1
        this.handleSearch()
      }
      if (tab.index === '2') {
        this.params.payStatus = 0
        this.handleSearch()
      }
      if (tab.index === '3') {
        this.params.payStatus = 1
        this.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.handleSearch()
      })
    },

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

