<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-select v-model="params.search_eq_type" v-show="false" style="width: 120px" class="filter-item" clearable placeholder="状态">
      </el-select>
      <el-input @keyup.enter.native="handleSearch" style="width: 200px;" class="filter-item" clearable placeholder="订单号" v-model="params.search_like_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" 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" v-waves  @click="exportChannel">导出</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="/orders" :request-params="params" ref="pagination" :showIndex="false">

      <!-- 用户ID -->
      <el-table-column align="center" label="用户昵称" width="200">
        <template scope="scope">
          <span>{{scope.row.nickname}}</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 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="价格">
        <template scope="scope">
          <span>{{scope.row.price}}</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.payTime | parseTime('{y}-{m}-{d} {h}:{i}')}}</span>
        </template>
      </el-table-column>

      <!-- 类型 -->
      <el-table-column align="center" label="类型">
        <template scope="scope">
          <span v-if="scope.row.type === 4">余额充值</span>
          <span v-if="scope.row.type === 1">课程订单</span>
          <span v-if="scope.row.type === 2">会员卡订单</span>
          <span v-if="scope.row.type === 3">篮球进场</span>
        </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//order'
import waves from '@/directive/waves.js'// 水波纹指令
import Pagination from '@/components/Pagination'
import querystring from 'querystring'
import moment from 'moment'
import PayStatus from '@/components/PayStatus'

export default {
  name: 'order_list',
  components: { Pagination, PayStatus },
  directives: {
    waves
  },
  data() {
    return {
      activeName: '4',
      params: {
        starTime: '',
        endTime: '',
        search_like_mobile: '',
        search_like_orderSn: '',
        search_like_nickname: '',
        search_eq_payStatus: 1,
        search_eq_type: 4 // 订单类型为余额充值
      },
      options: {
        statu: [
          {
            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()
    },

    handleClick(tab, event) {
      if (tab.index === '0') {
        this.params.search_eq_payStatus = undefined
        this.$refs.pagination.pageRequest()
      }
      if (tab.index === '1') {
        this.params.search_eq_payStatus = 0
        this.$refs.pagination.pageRequest()
      }
      if (tab.index === '2') {
        this.params.search_eq_payStatus = 1
        this.$refs.pagination.pageRequest()
      }
    },

    /**
     * 导出订单
     */
    exportChannel() {
      window.open('/api/orders/export?' + querystring.stringify(this.params))
    },

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

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

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

