<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="100px">
      <el-form-item label="优惠券类别" >
        <el-input v-model="queryParams.name" clearable @keyup.enter.native="handleQuery"></el-input>        
      </el-form-item>
      <el-form-item label="状态">
        <el-select v-model="queryParams.state" placeholder="请选择状态" clearable @keyup.enter.native="handleQuery">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" v-hasPermi="['coupon:category:query']">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>   

    <el-table v-loading="loading" :data="couponInfoList">     
      <el-table-column label="用户名" align="center" prop="custName">       
        <template slot-scope="scope">
          <a @click="handleUpdate(scope.row)" style="color: blue">{{ scope.row.custName }}</a>
        </template>     
      </el-table-column>
      <el-table-column label="订单号" align="center" prop="orderNo" />
      <el-table-column label="用户手机号" align="center" prop="custPhone" />
      <el-table-column label="领取优惠券名称" align="center" prop="couponName" />
      <el-table-column label="领取入口" align="center" prop="source"/>     
      <el-table-column label="触发事件" align="center" prop="typeDesc"/> 
      <el-table-column label="领取时间" align="center" prop="receiveTime"/> 
      <el-table-column label="优惠券适用时间" align="center" >
        <template slot-scope="scope">
          {{formateTime(scope.row.startTime)}}~{{formateTime(scope.row.expiredTime)}}
        </template>
      </el-table-column> 
      <el-table-column label="优惠券状态" align="center" prop="stateDesc"/> 
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import {getCouponInfoList} from "@/api/coupon/coupon";
export default {
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 表格数据
      couponInfoList: [],
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        state: null
      },
      options: [{
        value: null,
        label: '全部'
      },{
        value: '1',
        label: '生效中'
      },{
        value: '2',
        label: '未生效'
      }],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    formateTime(val){
      let index =val.indexOf(":");
      val=val.substring(0, index-3);
      console.log("val",val);
      return val;
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      getCouponInfoList(this.queryParams).then((response) => {
        this.couponInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.name=null;
      this.queryParams.state=null;
      this.handleQuery();
    },






  },
};
</script>