<template>
  <!-- 会员入库统计 -->
  <div class="form-wrap">
    <el-form
      class="search-box"
      ref="form"
      :model="form"
      :inline="true"
      label-width="140px">
      <div class="block-title">
        查询条件
      </div>
      <el-form-item
        label="会员类型"
        prop="keyWords1">
        <el-select
          v-model="form.keyWords1"
          placeholder="请选择">
          <el-option
            label="全部"
            value="">
          </el-option>
          <el-option
            v-for="item in memberTypeList"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <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="keyWords2">
        <el-input v-model="form.keyWords2"></el-input>
      </el-form-item>
      <div class="btn-wrap">
        <el-button
          @click="reset">
          重置
        </el-button>
        <el-button
          type="primary"
          @click="getList">
          搜索
        </el-button>
      </div>
    </el-form>
    <div class="table-box">
      <div class="block-title">
        入库统计
      </div>
      <el-table
        border
        stripe
        v-loading="loading"
        :data="tableData">
        <el-table-column
          prop="memberTypeName"
          label="会员类型">
        </el-table-column>
        <el-table-column
          prop="number"
          label="数量">
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { getMemberType, getMemberStorageStatistics } from '@/api/member'
import moment from 'moment'
export default {
  data () {
    return {
      memberTypeList: [],
      form: {
        startDate: new Date(moment().startOf('month')), // 起始时间
        endDate: new Date(moment().endOf('month')), // 截止时间
        keyWords1: '', // 会员类型id
        keyWords2: '' // 导入人
      },
      tableData: [],
      total: 0,
      loading: false,
      currentItem: {},
      dialogVisible: false
    }
  },
  mounted () {
    this.getMemberTypeList().then(() => {
      this.getList()
    })
  },
  methods: {
    reset () {
      this.$refs.form.resetFields()
    },
    // 获取会员类型
    getMemberTypeList () {
      return getMemberType({
        pageNum: 1,
        pageSize: 10000
      }).then(res => {
        this.memberTypeList = res.list
      })
    },
    getList () {
      this.loading = true
      getMemberStorageStatistics(this.form).then(res => {
        this.total = res.total
        this.tableData = res.data
      }).finally(() => {
        this.loading = false
      })
    }
  }
}
</script>
