marketing.CouponSend.Send.js 2.67 KB
webpackJsonp([81],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	/**
	 * Created by ty on 2016/5/23.
	 */

	'use strict';
	var $ = __webpack_require__(1),
	    common=__webpack_require__(2);

	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 (res) {
	            var msg1=[],msg2=[];
	            res.data.forEach(function (result) {
	                if(result.flag==false){
	                    msg1.push('<p>'+result.uid+':'+result.errMsg + '。</p>');
	                }else{
	                    msg2.push('<p>'+result.uid+':发放成功。</p>');
	                }
	            });
	            if(msg1.length>0){
	                common.util.__tip(msg1.join(""), 'warning');
	            }
	            if(msg2.length>0){
	                common.util.__tip(msg2.join(""), 'success');
	            }
	        },true);
	    } else {
	        common.util.__tip("请输入UID", "warning");
	    }
	});

	//批量导入
	$(document).on("click", "#batch-import", function() {
	    $("#picfile").click();
	    common.edit.ajaxfileupload(".picfile", {
	        params: {
	            __type: "import-txt",
	            couponId:parseInt(couponId)
	        },
	        valid_extensions: ['txt'],
	        onComplete: function (response) {
	            if (response.status && response.code == 200) {
	                //todo
	                Bll.getListByCouponId();
	            }
	            else {
	                common.util.__tip(response.message, 'warning');
	            }
	        }
	    });
	});

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


/***/ }
]);