<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="keyWords3">
        <ReaderInput
          type="IC"
          v-model="form.keyWords3"></ReaderInput>
      </el-form-item>
      <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="keyWords4">
        <el-input v-model.number="form.keyWords4"></el-input>
      </el-form-item>
      <el-form-item
        label="单价最大值"
        prop="keyWords5">
        <el-input v-model.number="form.keyWords5"></el-input>
      </el-form-item>

      <el-form-item
        label="渠道"
        prop="keyWords7">
        <el-select
          style="width:200px"
          v-model="form.keyWords7">
          <el-option
            label="全部"
            value="">
          </el-option>
          <el-option
            label="线上"
            value="线上">
          </el-option>
          <el-option
            label="散客"
            value="散客">
          </el-option>
          <el-option
            label="团客"
            value="团客">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item
        label="线上会员票号"
        prop="keyWords6">
        <el-input
          v-model="form.keyWords6"
          clearable></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="salesperson"
          label="销售">
        </el-table-column>
        <el-table-column
          prop="number"
          label="数量">
        </el-table-column>
        <el-table-column
          prop="price"
          label="单价">
        </el-table-column>
        <el-table-column
          prop="discount"
          label="折扣">
        </el-table-column>
        <el-table-column
          prop="total_money"
          label="总计">
        </el-table-column>
        <el-table-column
          prop="payChannel"
          label="支付方式">
        </el-table-column>
        <el-table-column
          width="160"
          label="激活有效期至">
          <template slot-scope="prop">
            {{ prop.row.activate_end_time | 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="manager_name"
          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="80%"
      v-model="dialogVisible">
      <DetailDialog
        :current-item="currentItem"
      ></DetailDialog>
    </ElDialog>
  </div>
</template>

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

export default {
  components: {
    ElDialog,
    DetailDialog,
    ReaderInput
  },
  data () {
    return {
      memberTypeList: [],
      minPrice: 0,
      maxPrice: 0,
      form: {
        startDate: '', // 起始时间
        endDate: '', // 截止时间
        keyWords1: '', // 会员类型id
        keyWords2: '', // 操作人
        keyWords3: '', // ic卡号
        keyWords4: '', // 单价最小值
        keyWords5: '', // 单价最大值
        keyWords6: '', // 线上会员票号
        keyWords7: '', // 渠道
        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
      })
    },
    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)
      iccardCheckoutLog(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>
