<template>
  <div class="form-wrap">
    <el-form
      class="search-box"
      ref="form"
      :model="form"
      :inline="true">
      <div class="block-title">
        查询条件
      </div>
      <el-form-item
        label="起始时间"
        prop="timeBegin">
        <el-date-picker
          v-model="form.timeBegin"
          type="datetime"
          placeholder="选择日期时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item
        label="截止时间"
        prop="timeEnd">
        <el-date-picker
          default-time="23:59:59"
          v-model="form.timeEnd"
          type="datetime"
          placeholder="选择日期时间">
        </el-date-picker>
      </el-form-item>
      <div
        class="btn-wrap"
        style="margin-bottom:20px">
        <el-button
          @click="reset">
          重置
        </el-button>
        <el-button
          :disabled="loading"
          type="primary"
          @click="getList">
          搜索
        </el-button>
      </div>
    </el-form>

    <div class="table-box">
      <el-table
        border
        stripe
        highlight-current-row
        v-loading="loading"
        :data="tableData"
        @row-click="handleRowClick">
        <el-table-column
          prop="checkDate"
          label="核销时间"
          align="center">
        </el-table-column>
        <el-table-column
          prop="count"
          label="人数"
          align="center">
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { getWlkDataStat } from '@/api/wlkData'
import moment from 'moment'

export default {
  name: 'WlkStat',
  data () {
    return {
      form: {
        timeBegin: new Date(moment().startOf('day').subtract(1, 'month').format('YYYY-MM-DD HH:mm:ss')),
        timeEnd: new Date(moment().endOf('day').format('YYYY-MM-DD HH:mm:ss'))
      },
      tableData: [],
      loading: false
    }
  },
  methods: {
    reset () {
      this.$refs.form.resetFields()
    },
    handleRowClick (row) {
      this.$emit('select', row)
    },
    getList () {
      this.loading = true
      const params = { ...this.form }

      if (params.timeBegin) {
        params.timeBegin = moment(params.timeBegin).format('YYYY-MM-DD HH:mm:ss')
      } else {
        params.timeBegin = ''
      }

      if (params.timeEnd) {
        params.timeEnd = moment(params.timeEnd).format('YYYY-MM-DD HH:mm:ss')
      } else {
        params.timeEnd = ''
      }

      getWlkDataStat(params).then(res => {
        this.tableData = res.data || []
      }).finally(() => {
        this.loading = false
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
