index.vue 6.87 KB
<template>
  <LayoutContent :breads="[{url: parentUrl, title: '优惠券列表'}, {title: '优惠券发放'}]">
    <i-form>

      <i-card class="manual-send-wrapper">
        <p slot="title">手动发放</p>
        <div>
          <i-row class="manual-send-container">
            <i-col span="4" class="title">
              UID<span class="red">*</span>
            </i-col>
            <i-col span="14" class="content">
              <textarea rows="5" id="txt_uids" placeholder="请输入UID,多个UID用英文逗号分隔,单次限制输入50个UID" v-model="uidValue"></textarea>
            </i-col>
            <i-col span="5" class="button">
              <i-button type="success" @click="manualSend">发送</i-button>
            </i-col>
          </i-row>
        </div>
      </i-card>
      <i-card class="import-send-wrapper">
        <p slot="title">批量发放</p>
        <div>
          <i-row class="import-send-container">
            <i-col span="3">&nbsp;</i-col>
            <i-col span="4">
              <div class="button-upload">
                上传文件
                <form id="formUpload">
                  <input type="file" id="upload" @change="fileChange" accept=".csv, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
                </form>

              </div>
              <span class="file-name">{{fileName}}</span>
            </i-col>
            <i-col span="2">&nbsp;</i-col>
            <i-col span="8">&nbsp;</i-col>
          </i-row>
          <i-row style="margin-top: 20px;">
            <i-col span="3">&nbsp;</i-col>
            <i-col span="4">
              <a href="..\..\common/uid_import.xlsx" class="btn-download" target="_blank">下载样例</a>
              <p>1.表头:UID</p>
              <p>2.同一张券可以给同一个用户发多张?</p>
            </i-col>
            <i-col span="2">&nbsp;</i-col>
            <i-col span="8">
              <a href="javascript:void(0)" style="color: red;">校验场景</a>
              <p>1.优惠券数量</p>
              <p>2.优惠券状态是否为未生效,或生效中</p>
            </i-col>
          </i-row>
          <i-row>
            <p style="color: red;text-align: center;margin-top: 30px; font-size: 30px;">{{uploadMessage}}</p>
          </i-row>
        </div>
      </i-card>
      <div class="bottom">
        <i-button type="success" id="btn_import_send" @click="importSend">批量发送</i-button>
      </div>
    </i-form>
  </LayoutContent>
</template>

<script>
import Api from '@/api/api';
import dayjs from 'dayjs';
import BlobUtil from 'libs/blob';
import qs from 'qs';

const api = new Api();

export default {
  components: {},
  name: 'SendCouponPage',
  data() {
    return {
      parentUrl: '',
      couponId: 0,
      couponToken: '',
      uidValue: '',
      fileName: '',
      showModal: false,
      message: '',
      uploadMessage: '',
      isSending: false
    };
  },
  created() {
    this.$nextTick(() => {
      const queryString = qs.parse(location.search ? location.search.slice(1) : '');

      this.parentUrl = `coupon.html?${qs.stringify(queryString.param)}`;
      this.couponId = queryString.id;
      this.couponToken = queryString.token;

    });
  },
  methods: {
    manualSend() { // 手动发放优惠券
      if(this.uidValue && !this.isSending) {
        let uidArr = this.uidValue.replace(/,/g, ',').split(',');
        if (uidArr.length > 50) {
          uidArr.length = 50;
        }
        if (uidArr.length > 0) {
          this.isSending = true;
          api._get('/ufoPlatform/coupon/couponSend', {
            couponToken: this.couponToken,
            uids: uidArr.join(',')
          }).then(result => {
            this.showModal = true;
            this.message = result.message;
            this.isSending = false;
            this.$Modal.info({
              title: '提示' + 'code:' + result.code,
              content: result.message,
              onOK: this.ok
            });
          }).catch(() => {
            this.isSending = false;
            this.$Modal.info({
              title: '提示',
              content: '发送失败',
              onOK: this.ok
            });
          });
        }
      }
    },
    fileChange() {
      let fileUpload = document.getElementById('upload');
      if (fileUpload.files.length > 0) {
        this.fileName = fileUpload.files[0].name;
      }

    },
    importSend() {
      if (this.fileName && !this.isSending) {
        let formData = new FormData();
        let file = document.getElementById('upload').files[0];
        let config = {
          headers: {
            'Content-Type': 'multipart/form-data'
          }
        };

        formData.append('file', file);
        formData.append('couponToken', this.couponToken);
        this.isSending = true;
        this.uploadMessage = '文件上传中...';
        api._postForm('/ufoPlatform/coupon/couponSendByImport', formData, false, config).then(result => {
          this.isSending = false;
          this.uploadMessage = '';
          this.$Modal.info({
            title: '提示' + 'code:' + result.code,
            content: result.message,
            onOK: this.ok
          });
        }).catch(() => {
          this.isSending = false;
          this.uploadMessage = '';
          this.$Modal.info({
            title: '提示',
            content: '上传失败',
            onOK: this.ok
          });
        });
      }
    },
    ok() {
      this.showModal = false;
    }
  },
};
</script>

<style>

  .manual-send-wrapper {
    height: 205px;
  }

  .import-send-wrapper {
    height: 100%;
  }

  .ivu-card-body {
    padding: 0;
    margin: 0;
  }

  .ivu-card-bordered {
    /*border: none;*/
    border-bottom: none;
  }

  .ivu-card-head {
    background-color: #f7f7f7;
  }

  .manual-send-container {
    margin-top: 20px;
    height: 130px;
  }

  .import-send-container {
    margin-top: 40px;
    /*margin-bottom: 200px;*/
  }
  
  .manual-send-container .title {
    text-align: right;
    margin-right: 20px;
  }

  .manual-send-container .content {

  }

  #txt_uids {
    width: 98%;
    height: 100%;
  }

  #upload {
    width: 100%;
    height: 100%;
    opacity: 0;
    position: absolute;
    left: 0;
    top: 0;
  }

  .button-upload {
    position: relative;
    display: inline-block;
    background-color: #17b566;
    -webkit-border-radius: 5px;
    border-radius: 5px;
    color: #fff;
    width: 80px;
    height: 32px;
    line-height: 32px;
    text-align: center;
    overflow: hidden;
  }

  .file-name {
    height: 32px;
    line-height: 32px;
    margin-left: 20px;
    color: #2b85e4;
    display: inline-table;
    vertical-align: middle;
  }

  .red {
    color: #ff0000;
  }

  .bottom {
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 80px;
    background-color: #f7f7f7;
    line-height: 80px;
    text-align: center;
  }

  a {
    text-decoration: none;
  }
</style>