<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
          type="index"
          label="#">
        </el-table-column>
        <el-table-column
          prop="memberTypeName"
          label="会员类型">
        </el-table-column>
        <el-table-column
          prop="number"
          label="数量">
        </el-table-column>
        <!-- <el-table-column
          width="160"
          label="有效期至">
          <template slot-scope="prop">
            {{ prop.row.endtime | formatDate }}
          </template>
        </el-table-column> -->
        <el-table-column
          width="160"
          label="入库时间">
          <template slot-scope="prop">
            {{ prop.row.createTime | formatTime }}
          </template>
        </el-table-column>
        <el-table-column
          prop="creator"
          label="导入人">
        </el-table-column>
        <el-table-column
          label="操作">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click="showDetail(scope.row)">
              详情
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        :current-page.sync="form.pageNum"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="form.pageSize"
        @size-change="handleSizeChange"
        @current-change="getList()"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>

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

<script>
import { getMemberType, getMemberStorageLogList } from '@/api/member'
import ElDialog from '@/components/Dialog'
import DetailDialog from './storageQuery/DetailDialog'
export default {
  components: {
    ElDialog,
    DetailDialog
  },
  data () {
    return {
      memberTypeList: [],
      form: {
        startDate: '', // 起始时间
        endDate: '', // 截止时间
        keyWords1: '', // 会员类型id
        keyWords2: '', // 导入人
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      total: 0,
      loading: false,
      currentItem: {},
      dialogVisible: false
    }
  },
  mounted () {
    this.init()
  },
  methods: {
    init () {
      this.getMemberTypeList().then(() => {
        this.getList()
      })
    },
    reset () {
      this.$refs.form.resetFields()
    },
    // 获取会员类型
    getMemberTypeList () {
      return getMemberType({
        pageNum: 1,
        pageSize: 10000
      }).then(res => {
        this.memberTypeList = res.list
      })
    },
    handleSizeChange (size) {
      this.form.pageSize = size
      this.getList()
    },
    // 获取列表
    getList () {
      this.loading = true
      // this.form.startDate = new Date(this.form.startDate)
      // this.form.endDate = new Date(this.form.endDate)
      getMemberStorageLogList(this.form).then(res => {
        this.total = res.total
        this.tableData = res.list
      }).finally(() => {
        this.loading = false
      })
    },
    showDetail (item) {
      this.currentItem = item
      this.dialogVisible = true
    }
  }
}
</script>
