sendCoupon.js 1.9 KB
/**
 * Created by ty on 2016/5/23.
 */

'use strict';
var $ = require('jquery'),
    common=require('../common/common');

var couponId = location.href.substring(location.href.lastIndexOf("/") + 1);
common.util.__ajax({
    url: "/coupon/querySendCouponList",
    data: {couponId:couponId},
    async: false
}, function (res) {
    $("#title").text(res.data.list[0].couponName);
},true);

var Bll = {
    getListByCouponId: function () {
        common.util.__ajax({
            url: "/couponSendInfo/getListByCouponId",
            data: {couponId:couponId},
            async: false
        }, function (res) {
            $("#list-content").html(common.util.__template2($("#template-list").html(), res));
        },true);
    }
};
Bll.getListByCouponId();
//发放优惠券事件
$(document).on("click", "#sendCoupon", function() {
    var uids = $("#handworkSend").val();
    if(uids) {
        common.util.__ajax({
            url: "/coupon/sendCoupon",
            data: {
                couponId:couponId,
                uids:uids
            }
        }, function () {
            location.href = location.href;
        });
    } else {
        common.util.__tip("请输入UID", "warning");
    }
});

//批量导入
$(document).on("click", "#batch-import", function() {
    $("#importFile").click();
});

//重新发放
$(document).on("click", ".reSend", function() {
    var id = $(this).data("id");
    common.util.__ajax({
        url: "/couponSendInfo/sendAgainById",
        data: {id: id}
    }, function () {
        Bll.getListByCouponId();
    });
});

//导入
common.edit.ajaxfileupload("#importFile",{
    params: {
        type: "drawlineUserQueue",
        __type: "batch-import"
    },
    onComplete:function(res){
        if(res.code == 200) {
            common.util.__tip(res.message, 'success');
            Bll.getListByCouponId();
        } else {
            common.util.__tip(res.message);
        }
    }
});