<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-select v-model="params.search_eq_payStatus" v-show="false" 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-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: 138px;" class="filter-item" clearable placeholder="用户手机号" v-model="params.search_like_mobile"></el-input>
      <el-input @keyup.enter.native="handleSearch" style="width: 170px;" class="filter-item" clearable 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>

    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="全部" name="1">
      </el-tab-pane>
      <el-tab-pane label="未支付" name="3"></el-tab-pane>
      <el-tab-pane label="已支付" name="4"></el-tab-pane>
    </el-tabs>
  </div>

  <!-- 列表数据 -->
  <Pagination uri="/member/card/orders" :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">
          <span>{{scope.row.cardType}}</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="300">
        <template scope="scope">
          <span>{{scope.row.orderSn}}</span>
        </template>
      </el-table-column>

      <!-- 手机号 -->
      <el-table-column align="center" label="手机号">
        <template scope="scope">
          <span>{{scope.row.mobile}}</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 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">
          <PayStatus :status="scope.row.payStatus"></PayStatus>
        </template>
      </el-table-column>

      <!-- 下单时间 -->
      <el-table-column align="center" label="下单时间" width="150">
        <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 } from '@/api//member/card/order'
import waves from '@/directive/waves.js'// 水波纹指令
import Pagination from '@/components/Pagination'
import moment from 'moment'
import PayStatus from '@/components/PayStatus'

export default {
  name: 'memberCardOrder_list',
  components: { Pagination, PayStatus },
  directives: {
    waves
  },
  data() {
    return {
      activeName: '1',
      params: {
        search_like_mobile: '',
        orderSn: '',
        starTime: '',
        search_like_nickname: '',
        endTime: '',
        payStatus: undefined
      },
      options: {
        statu: [
          {
            value: -1,
            label: '已关闭'
          },
          {
            value: 0,
            label: '待支付'
          },
          {
            value: 1,
            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 = ''
      }
      this.$refs.pagination.handleSearch()
    },

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

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

    /**
     * tabl切换
     */
    handleClick(tab, event) {
      if (tab.index === '0') {
        this.params.payStatus = undefined
        this.$refs.pagination.pageRequest()
      }
      if (tab.index === '1') {
        this.params.payStatus = 0
        this.$refs.pagination.pageRequest()
      }
      if (tab.index === '2') {
        this.params.payStatus = 1
        this.$refs.pagination.pageRequest()
      }
    },

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

