<template>
  <div class="form-wrap">
    <el-form
      class="search-box"
      ref="form"
      :model="form"
      :inline="true"
      label-width="70px">
      <div class="block-title">
        查询条件
      </div>
      <el-form-item
        label="起始时间"
        prop="startDate">
        <el-date-picker
          v-model="form.startDate"
          type="datetime"
          placeholder="选择日期时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item
        label="截止时间"
        prop="endDate">
        <el-date-picker
          default-time="23:59:59"
          v-model="form.endDate"
          type="datetime"
          placeholder="选择日期时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item
        label="会员类型"
        prop="keyWords1">
        <el-select
          v-model="form.keyWords1"
          clearable>
          <el-option
            value=""
            label="全部"></el-option>
          <el-option
            v-for="item in memberTypeList"
            :key="item.id"
            :value="item.id"
            :label="item.name">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item
        label="检票类型"
        prop="keyWords2">
        <el-select
          v-model="form.keyWords2"
          clearable>
          <el-option
            label="全部"
            value=""></el-option>
          <el-option
            v-for="item in checkType"
            :key="item.type"
            :label="item.name"
            :value="item.type"
          >
          </el-option>
        </el-select>
      </el-form-item>

      <div
        class="btn-wrap"
        style="margin-bottom:20px">
        <el-button
          @click="reset">
          重置
        </el-button>
        <el-button
          :disabled="loading"
          type="primary"
          @click="getCheckStatistic">
          搜索
        </el-button>
        <el-button
          type="primary"
          @click="reportExport">
          导出
        </el-button>
      </div>
    </el-form>
    <div class="block-title">
      统计信息
    </div>
    <el-table
      border
      stripe
      v-loading="loading"
      :data="tableData"
      :row-class-name="totalRowClassName">
      <el-table-column
        prop="memberTypeName"
        label="会员类型">
      </el-table-column>
      <el-table-column
        prop="count"
        label="入园次数">
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { getTicketTypeList } from '@/api/ticketType'
import { totalRowClassName } from '@/utils'
import { getMemberVisitCountStatistics, getMemberType, exportMemberVisitCountStatistics } from '@/api/member'

import moment from 'moment'
export default {
  name: 'checkStatistic',
  computed: {
    scenicList () {
      return this.$store.state.app.scenicList
    }
  },
  data () {
    return {
      ticketTypeList: [],
      form: {
        startDate: new Date(moment().format('YYYY-MM-DD') + ' 00:00:00'),
        endDate: new Date(moment().format('YYYY-MM-DD') + ' 23:59:59'),
        keyWords1: '',
        keyWords2: '',
        keyWords3: ''
      },
      tableData: [],
      checkType: [{ type: 'finger', name: '指纹' }, { type: 'face', name: '人脸' }, { type: 'idcard', name: '身份证' }, { type: 'iccard', name: 'IC卡' }, { name: '人工检票', value: 'person' }],
      memberTypeList: [],
      loading: false
    }
  },
  created () {
    this.getMemberTypeList()
    this.getCheckStatistic()
  },
  methods: {
    totalRowClassName,
    // 获取会员类型
    getMemberTypeList () {
      return getMemberType({
        pageNum: 1,
        pageSize: 999
      }).then(res => {
        this.memberTypeList = res.list
      })
    },
    reset () {
      this.$refs.form.resetFields()
    },
    // 获取票种列表
    getTicketTypeList () {
      return getTicketTypeList({
        pageNum: 1,
        pageSize: 999
      }).then(res => {
        this.ticketTypeList = res.list
      })
    },
    // 获取表格数据
    getCheckStatistic () {
      this.loading = true
      getMemberVisitCountStatistics(this.form).then(res => {
        this.tableData = res?.data
      }).finally(() => {
        this.loading = false
      })
    },
    reportExport () {
      exportMemberVisitCountStatistics(this.form).then(() => {
        this.$message.success('导出成功。')
        this.goToDownload()
      }, () => {
        this.$message.success('导出失败。')
      })
    }
  }
}
</script>

<style scoped>

</style>
