<template>
<div class="app-container calendar-list-container">
  <!-- 筛选条件 -->
  <div class="filter-container">
    <el-input @keyup.enter.native="handleSearch" style="width: 200px;" clearable class="filter-item" placeholder="昵称" v-model="params.search_like_nickname"></el-input>
     <el-select v-model="params.search_eq_cardType" 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-select v-model="params.veneuType" style="width: 120px" class="filter-item" clearable placeholder="场馆类型">
      <el-option v-for="item in options.statuss"
        :key="item.value"
        :label="item.label"
        :value="item.value">
      </el-option>
    </el-select>
    <el-input @keyup.enter.native="handleSearch" style="width: 200px;" clearable class="filter-item" placeholder="场馆名称" v-model="params.venueName"></el-input>
    <el-select v-model="params.status" style="width: 120px" 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>

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

      <!-- 用户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.cardType}}</span>
        </template>
      </el-table-column>

      <!-- 场馆类型 -->
      <el-table-column align="center" label="场馆类型">
        <template scope="scope">
          <span v-if="scope.row.veneuType === 1">篮球馆</span>
          <span v-if="scope.row.veneuType === 2">健身馆</span>
        </template>
      </el-table-column>

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

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

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

      <!-- 激活状态 -->
      <el-table-column align="center" label="默认状态">
        <template scope="scope">
           <MemberCardStatus :status="scope.row.status"></MemberCardStatus>
        </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>
  </Pagination>
</div>
</template>

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

export default {
  name: 'memberCard_list',
  components: { Pagination, MemberCardStatus },
  directives: {
    waves
  },
  data() {
    return {
      params: {
        status: undefined,
        veneuType: undefined,
        search_eq_card_type: undefined,
        search_like_nickname: undefined,
        venueName: undefined
      },
      options: {
        statu: [
          {
            value: 0,
            label: '未激活'
          },
          {
            value: 1,
            label: '已激活'
          }
        ],
        statuss: [
          {
            value: 1,
            label: '篮球馆'
          },
          {
            value: 2,
            label: '健身馆'
          }
        ],
        status: [
          {
            value: '年卡',
            label: '年卡'
          },
          {
            value: '半年卡',
            label: '半年卡'
          },
          {
            value: '季卡',
            label: '季卡'
          },
          {
            value: '月卡',
            label: '月卡'
          },
          {
            value: '免费卡',
            label: '免费卡'
          }
        ]
      }
    }
  },
  created() {
  },
  methods: {
    /**
     * 搜索用户会员卡
     */
    handleSearch() {
      // this.$refs.pagination.pageRequest()
      this.$refs.pagination.handleSearch()
    },

    /**
     * 编辑用户会员卡
     */
    handleEdit(id) {
      this.$router.push({ path: '/member/card/edit', query: { id: id }})
    },

    /**
     * 创建用户会员卡
     */
    handleCreate() {
      this.$router.push({ path: '/member/card/edit' })
    },

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

