<template>
  <div class="app-container">
    <!-- 表单筛选 -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      inline
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="卡券编号">
        <el-input
          v-model="queryParams.couponNumber"
          placeholder="请输入卡券编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="卡券名称">
        <el-input
          v-model="queryParams.couponTitle"
          placeholder="请输入卡券名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="卡密卡号">
        <el-input
          v-model="queryParams.cardNumber"
          placeholder="请输入卡密卡号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户昵称">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入用户昵称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户手机号">
        <el-input
          v-model="queryParams.userTel"
          placeholder="请输入用户手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="兑换时间">
        <el-date-picker
          v-model="dateRange"
          style="width: 100%"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <!-- 按钮组 -->
    <el-row :gutter="10" class="mb8">
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getTableList"
      ></right-toolbar>
    </el-row>
    <!-- 表格 -->
    <el-table v-loading="loading" :data="tableList">
      <el-table-column label="卡券编号" align="center" prop="couponNumber" />
      <el-table-column label="卡券名称" align="center" prop="couponTitle" />
      <el-table-column label="卡密卡号" align="center" prop="cardNumber" />
      <el-table-column label="用户名" align="center" prop="userName" />
      <el-table-column label="用户手机号" align="center" prop="userTel" />
      <el-table-column label="兑换时间" align="center" prop="createTime" />
    </el-table>
    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getTableList"
    />
  </div>
</template>

<script>
import { getList } from "@/api/coupon/exchangeRecord";
export default {
  name: "ExchangeRecord",
  components: {},
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        couponNumber: "",
        couponTitle: "",
        cardNumber: "",
        userName: "",
        userTel: "",
      },
      // 时间
      dateRange: [],
      // 表格相关
      loading: false,
      tableList: [],
      total: 0,
    };
  },
  created() {
    this.getTableList();
  },
  methods: {
    // 搜索
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getTableList();
    },
    // 重置
    resetQuery() {
      this.dateRange = [];
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        couponNumber: "",
        couponTitle: "",
        cardNumber: "",
        userName: "",
        userTel: "",
      };
      this.getTableList();
    },
    // 查询列表
    getTableList() {
      let params = this.addDateRange(this.queryParams, this.dateRange);
      this.loading = true;
      getList(params)
        .then((res) => {
          if (res.code === 200) {
            this.tableList = res.rows;
            this.total = res.total;
          }
        })
        .finally(() => (this.loading = false));
    },
  },
};
</script>

<style lang="scss" scoped></style>
