<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      label-width="80px"
    >
      <el-form-item label="" prop="key">
        <el-input
          v-model="queryParams.key"
          placeholder="请输入代金券ID/代金券名称搜索"
          clearable
          style="width: 180px"
        />
      </el-form-item>

      <el-form-item label="类型" prop="type">
        <el-select
          v-model="queryParams.type"
          placeholder="请选择券类型"
          style="width: 180px"
        >
          <el-option label="全部" value=""> </el-option>
          <el-option label="独立券" value="1"> </el-option>
          <el-option label="连锁券" value="2"> </el-option>
          <el-option label="联合券" value="3"> </el-option>
        </el-select>
      </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-table v-loading="loading" :data="list">
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="名称" align="center" prop="title" />
      <el-table-column label="类型" align="center">
        <template slot-scope="scope">
          {{
            scope.row.type == 1
              ? "独立券"
              : scope.row.type == 2
              ? "连锁券"
              : scope.row.type == 3
              ? "联合券"
              : ""
          }}
        </template>
      </el-table-column>

      <el-table-column label="推广方式" align="center">
        <template slot-scope="scope">
          {{
            scope.row.showType == 0
              ? "全网自动推出"
              : scope.row.showType == 1
              ? "定向渠道推广"
              : ""
          }}
        </template>
      </el-table-column>
      <el-table-column
        label="邀请加入店铺数量"
        align="center"
        prop="inviteStoreNum"
      />
      <el-table-column
        label="已同意加入店铺数量"
        align="center"
        prop="agreeStoreNum"
      />
      <el-table-column label="面额(元)" align="center" prop="sendAmount" />
      <el-table-column label="总发放数量" align="center" prop="sendNum" />
      <el-table-column label="已领取数量" align="center" prop="receiveNum" />

      <el-table-column label="操作" align="center" width="200">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            style="color: #00b529"
            @click="handleChoose(scope.row)"
            >选择</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import moment from "moment";
import { queryPage, voucherRemove } from "@/api/marketing/voucher";
export default {
  data() {
    return {
      loading: true,
      total: 0,
      title: "",
      list: [],
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        dateRange: [],
        type: 1,
        key: "",
        showType: "",
      },
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleChoose(record) {
      this.$emit("voucherChoose", record);
    },

    getList() {
      this.loading = true;
      queryPage(this.queryParams).then((res) => {
        this.list = res.data.records;
        this.total = res.data.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.queryParams.endTime = "";
      this.queryParams.startTime = "";
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
<style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 138px;
  height: 138px;
  line-height: 138px;
  text-align: center;
}
</style>
<style scoped lang="scss">
.avatar {
  width: 138px;
  height: 138px;
  display: block;
}
</style>
