<template>
  <div>
    <el-dialog
      :title="this.ids.title"
      width="1000px"
      :visible.sync="dialogVisible"
      :before-close="close"
    >
      <div class="dialog-search">
        <div>参与用户数量：{{this.ids.realNum}}</div>
        <div class="ge"></div>
        <div>抽奖码数量：{{marketingTotal}}</div>
      </div>
      <el-table
        v-loading="loading"
        :data="marketingList"
        @selection-change="handleSelectionCoupon"
        class="el-table"
      >
        <el-table-column label="用户编号" prop="userId" min-width="80" />
        <el-table-column label="用户昵称" prop="nickName" min-width="80" />
        <el-table-column label="抽奖码" prop="code" min-width="80" />
        <el-table-column label="抽奖码获取时间" prop="createdTime" min-width="85">
          <template slot-scope="scope">
            <div>{{ parseTime(scope.row.createdTime) }}</div>
          </template>
        </el-table-column>
        <el-table-column label="奖级" prop="awardsName" min-width="50" >
          <template slot-scope="scope">
            <div v-if="scope.row.prizeName != ''">{{ scope.row.awardsName }}</div>
            <div v-else> -- </div>
          </template>
        </el-table-column>
        <el-table-column label="奖品名称" prop="prizeName" min-width="85" >
          <template slot-scope="scope">
            <div v-if="scope.row.prizeName != ''">{{ scope.row.prizeName }}</div>
            <div v-else> -- </div>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="marketingTotal > 0"
        :total="marketingTotal"
        :page.sync="pageParams.pageNum"
        :limit.sync="pageParams.pageSize"
        @pagination="getMarketingData"
      />
      <div class="dialog-btn">
        <el-button size="small" @click="close"> 关 闭 </el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { publicFileGetUrl } from "@/api/common";
import { getMarketingData } from '@/api/business/marketing'
export default {
  name: "CouponAdd",
  props: {
    dialogVisible: {
      type: Boolean,
      default: false,
    },
    ids: {
      type: Object,
      default: () => []
    }
  },
  data() {
    return {
      loading: false,
      marketingTitle: "", // 券名称
      marketingList: [], // 卡券列表
      marketingTotal: 0, // 卡券总数
      selectCouponList: [], // 选中卡券
      pageParams: {
        pageNum: 1,
        pageSize: 10,
      },
    };
  },
  created() {
    this.getMarketingData();
  },
  methods: {
    // 卡券列表
    getMarketingData() {
      this.loading = true;
      getMarketingData(this.ids.id ).then((res) => {
        this.marketingList = res.rows
        this.marketingTotal = res.total;
        this.loading = false;
      });
    },

    // 选中卡券
    handleSelectionCoupon(e) {
      this.selectCouponList = e.map((item) => {
        return {
          couponNum: 1,
          couponId: item.couponId,
          title: item.title,
          createdTime: item.createdTime,
          updatedTime: item.updatedTime,
          type: item.type,
          discount: item.discount,
          dueDays: item.dueDays
        };
      });
    },

    // 确认选中卡券
    confirmCoupon() {
      this.$emit("confirmCoupon", this.selectCouponList);
      this.close()
    },

    close() {
      this.$emit("close");
    },
  },
};
</script>
<style lang="scss" scoped>
.dialog-search {
  display: flex;
  line-height: 32px;
  margin-bottom: 20px;
  .ge {
    width: 40px;
  }
}
.dialog-btn {
  display: flex;
  align-content: center;
  justify-content: flex-end;
  padding: 40px 0 0;
  .ge {
    width: 40px;
  }
}
</style>
