<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>
      <el-form-item
        label="单价最小值"
        prop="keyWords3">
        <el-input v-model.number="form.keyWords3"></el-input>
      </el-form-item>
      <el-form-item
        label="单价最大值"
        prop="keyWords4">
        <el-input v-model.number="form.keyWords4"></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="price"
          label="出库价格">
        </el-table-column>
        <el-table-column
          prop="count"
          label="数量">
        </el-table-column>
        <el-table-column
          prop="total_money"
          label="总额">
        </el-table-column>
      </el-table>
    </div>

    <ElDialog
      title="出库详情"
      width="760px"
      v-model="dialogVisible">
      <DetailDialog
        :current-item="currentItem"
      ></DetailDialog>
    </ElDialog>
  </div>
</template>

<script>
import ElDialog from '@/components/Dialog'
import DetailDialog from './storageQuery/DetailDialog'
import { getMemberType, getMemberStorageSellStatistics } from '@/api/member'

export default {
  components: {
    ElDialog,
    DetailDialog
  },
  data () {
    return {
      memberTypeList: [],
      minPrice: 0,
      maxPrice: 0,
      form: {
        startDate: '', // 起始时间
        endDate: '', // 截止时间
        keyWords1: '', // 会员类型id
        keyWords2: '', // 操作人
        keyWords3: '', // 单价最小值
        keyWords4: '', // 单价最大值
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      total: 0,
      loading: false,
      currentItem: {},
      dialogVisible: false
    }
  },
  created () {
    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
      getMemberStorageSellStatistics(this.form).then(res => {
        this.tableData = res.data
      }).finally(() => {
        this.loading = false
      })
    },
    showDetail (item) {
      this.currentItem = item
      this.dialogVisible = true
    }
  }
}
</script>
