<template>
  <div class="subPage">
    <div class="system-table-search">
      <div class="flex-h">
        <div class="flex-item flex-h"></div>
        <ul>
          <li>
            <el-input
              placeholder="请输入推荐人"
              v-model="postData.referrer"
              clearable>
            </el-input>
          </li>
          <li>
            <el-date-picker
              value-format="yyyy-MM-dd"
              v-model="postData.startDate"
              type="date"
              placeholder="选择起始日期">
            </el-date-picker>
            <span>至</span>
            <el-date-picker
              value-format="yyyy-MM-dd"
              v-model="postData.endDate"
              type="date"
              placeholder="选择截止日期">
            </el-date-picker>
          </li>
        </ul>
        <el-button
          size="mini"
          type="primary" @click="search">搜索</el-button>
      </div>
      <div class="moreFilter"></div>
    </div>
    <div class="system-table-box">
      <el-table
        :data="currentList"
        stripe
        style="width: 100%">
        <el-table-column
          prop="GiftName"
          label="卡券名称">
        </el-table-column>
        <el-table-column
          prop="ToName"
          label="姓名">
        </el-table-column>
        <el-table-column
          prop="CustomerName"
          label="微信昵称">
        </el-table-column>
        <el-table-column
          prop="Phone"
          label="手机号">
        </el-table-column>
        <el-table-column
          prop="RecommendName"
          label="推荐人">
        </el-table-column>
        <el-table-column
          prop="CreateDate"
          label="赠送时间">
          <template slot-scope="scope">
            <span v-if="scope.row.CreateDate !== '0001-01-01T00:00:00Z'">{{toolClass.dateFormat(scope.row.CreateDate, 'yyyy-MM-dd')}}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="FromName"
          label="操作人">
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      @current-change="handleCurrentChange"
      :current-page.sync="postData.page"
      :page-size="postData.pagesize"
      layout="prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
  name: '',
  data () {
    return {
      customerList: [],
      centerDialogVisible: false,
      total: 0,
      postData: { // 表格搜索条件
        page: 1, // 当前页码
        pagesize: 10, // 请求数据量
        startDate: '',
        endDate: '',
        referrer: '', // 搜索框
      },
      currentList: []
    }
  },
  mounted () {
    this.$nextTick(function () {
      this.getList()
    })
  },
  computed: {
    ...mapState({
      cases: x => x.app.cases.list,
      defaultCaseId: x => x.app.cases.default
    }),
    CaseId: {
      get () {
        return this.postData.caseid || this.defaultCaseId
      },
      set (val) {
        this.postData.caseid = val
      }
    }
  },
  methods: {
    search () { // 搜索
      this.postData.page = 1
      this.currentList = []
      this.getList()
    },
    getList () { // 获取列表
      this.$ajax(this.$api.record.getRecordList.url, {
        method: this.$api.record.getRecordList.method,
        queryData: { ...this.postData, caseid: this.CaseId }
      }).then(res => {
        // console.log(JSON.stringify(res))
        this.currentList = res.list
        this.postData.page = res.page
        this.total = res.pagenum
      })
    },
    handleCurrentChange (val) { // 跳转到分页
      this.getList()
    },
    FormatDate (date) {
      return this.toolClass.dateFormat(date, 'yyyy-MM-dd hh:mm:ss')
    },
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
</style>
