<template>
  <el-drawer :title="title" :visible.sync="show" size="80%" append-to-body>
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" :size="ELsize" label-width="auto">
      <el-form-item label="领取时间" prop="name">
        <el-date-picker v-model="daterangeCreateTime" size="small" value-format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="用户手机号" prop="mobile">
        <el-input v-model="queryParams.mobile" placeholder="请输入用户手机号" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search"   @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh"   @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" :size="ELsize" @click="handleExport">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="list" :border="TableBorder" :size="ELTableSize">
      <el-table-column align="center" label="序号" width="80">
        <template slot-scope="{$index}">
          {{ $getTableIndex(queryParams, $index + 1) }}
        </template>
      </el-table-column>
      <el-table-column prop="threshold" header-align="center" align="center" label="用户">
        <template slot-scope="{ row }">
          {{ row.nickname }}({{ row.mobile }})
        </template>
      </el-table-column>
      <el-table-column prop="receiveTime" header-align="center" align="center" label="领券时间">
      </el-table-column>
      <el-table-column prop="expireTime" header-align="center" align="center" label="有效期">
      </el-table-column>
      <el-table-column prop="orderCodes" header-align="center" align="center" label="订单号"></el-table-column>
      <el-table-column prop="useTime" width="180px" header-align="center" align="center" label="用券时间">
      </el-table-column>
      <el-table-column prop="useStatus" header-align="center" align="center" label="状态">
        <template slot-scope="{ row }">
          <el-tag v-if="row.useStatus">已使用</el-tag>
          <el-tag v-else type="success">未使用</el-tag>
        </template>
      </el-table-column>
    </el-table>
  </el-drawer>
</template>

<script>
import { couponReceiveRecordPage } from '@/api/marketing'
export default {
  data() {
    return {
      //按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 测试单表表格数据
      list: [],
      daterangeCreateTime: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        mobile: undefined
      },
      timeArr: [],
      dataListLoading: false,
      dataList: [],
      total: 0,
      title: null,
      show: false
    }
  },
  methods: {
    open(item) {
      this.title = item.name;
      this.show = true;
      if (item && item.id) {
        this.queryParams.couponId = item.id
        this.getList()
      }
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('/coupon/couponReceiveRecord/export', {
        ...this.queryParams
      }, `${this.title}_${new Date().getTime()}.xlsx`)
    },
    getList() {
      this.loading = true;
      this.queryParams["receiveTimeStart"] = undefined;
      this.queryParams["receiveTimeEnd"] = undefined;
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams["receiveTimeStart"] = this.daterangeCreateTime[0];
        this.queryParams["receiveTimeEnd"] = this.daterangeCreateTime[1];
      }
      couponReceiveRecordPage(this.queryParams).then(response => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
}
</script>

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