<template>
  <div class="app-container">
    <div class="app-container">
        <div class="block">
            <span class="demonstration">時間篩選</span>
            <el-date-picker
            v-model="date"
            type="datetimerange"
            :picker-options="pickerOptions"
            range-separator="至"
            start-placeholder="開始日期"
            end-placeholder="结束日期"
            align="right">
            </el-date-picker>
            <el-button class="filter-item" type="primary" v-waves icon="el-icon-search" @click="handleFilter">搜尋</el-button>
        </div>
    </div>
    <el-table :data="list" v-loading.body="listLoading" element-loading-text="Loading" border fit highlight-current-row>
      <el-table-column label="場" align="center">
        <template slot-scope="scope">
          {{scope.row.game}}
        </template>
      </el-table-column>
      <el-table-column label="總押注" align="center">
        <template slot-scope="scope">
          <span>{{scope.row.wager}}</span>
        </template>
      </el-table-column>
      <el-table-column label="總輸贏" align="center">
        <template slot-scope="scope">
          <span>{{scope.row.earned}}</span>
        </template>
      </el-table-column>
      <el-table-column label="時間" align="center">
        <template slot-scope="scope">
          <span>{{scope.row['GambleGame-Bucket'].createdAt}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
            <el-button type="primary" size="mini" icon="el-icon-tickets" @click="handleDetail(scope.row)">詳細紀錄</el-button>  
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>

import { mapActions } from 'vuex'
import { fetchHistory } from '@/api/gambleMember'
import waves from '@/directive/waves' // 水波纹指令
import moment from 'moment-timezone'

export default {
  directives: {
    waves
  },
  data() {
    return {
      list: null,
      listLoading: true,
      pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一個月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三個月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },
      date: ''
    }
  },
  created() {
    this.fetchData()
  },
  props: ['member'],
  methods: {
    ...mapActions([
      'SetVisble'
    ]),
    fetchData() {
      this.listLoading = true
      fetchHistory(this.member).then(response => {
        this.list = response.data
        this.listLoading = false
      })
    },
    handleFilter() {
      console.log(moment.utc(this.date[0]).format())
      console.log(moment.utc(this.date[1]).format())      
    },
    handleDetail() {
      
    }
  },
  destroyed() {
    this.SetVisble(true)
  }
}
</script>
