marketing.CouponSend.SendHistory.js 4.17 KB
webpackJsonp([82],[
/* 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);
	var isSent = 1;

	//下拉框
	new common.dropDown({el: '#isSent'});
	var Bll = {
	    getTime: function (time) {
	        var t = new Date(time * 1000);
	        return common.util.__dateFormat(t, "yyyy-MM-dd hh:mm:ss");

	    },
	    toast:function(){
	        return common.dialog.open({title:"温馨提示",content:"导出中,请稍后....请不要关闭本窗口"});
	        }
	};
	//grid
	var g = new common.grid({
	    el: '#content-list',
	    hash: false,
	    async: false,
	    parms: function () {
	        return {
	            couponId: couponId
	            //status:common.util.__input("filter-status")
	        };
	    },
	    columns: [
	        {display: "单券号", name: "couponCode"},
	        {display: "用户ID", name: "uid"},
	        {
	            display: '发放时间', render: function (item) {
	            return Bll.getTime(item.createTime);
	        }
	        }
	    ]
	});
	var g1 = new common.grid({
	    el: '#content-list',
	    hash: false,
	    async: false,
	    parms: function () {
	        return {
	            couponId: couponId
	            //status:common.util.__input("filter-status")
	        };
	    },
	    columns: [
	        {display: "用户ID", name: "uid"},
	        {display: "异常原因", name: "errMsg"},
	        {display: "操作", render: function (item) {
	            return '<a class="btn btn-primary btn-xs reSend" data-index="'+ item.__index+'" href="javascript:;">重发</a>';
	        }},
	    ]
	});
	g.init("/couponLogs/queryUserCouponLogsList");
	$("#count").html(g.total);

	$(document).on("click", "#filter-btn", function () {
	    isSent = $("#isSent").val();
	    if(isSent == 2) {
	        g1.init("/couponSendError/query");
	        $("#count").html(g1.total);
	    } else {
	        g.init("/couponLogs/queryUserCouponLogsList");
	        $("#count").html(g.total);
	    }
	});


	var t;
	var path;
	var api; 
	var f={
	    check:function(){ 
	        common.util.__ajax({
	        url: '/checkCouponExportFileIsExist',
	        data: {
	            queryConf: path     
	        },async:false
	        },function(res) {
	            if(res.data===0){
	                console.log("go on");
	            }else{
	                console.log("over");
	                clearInterval(t);
	                var a = document.createElement("a");
	                a.setAttribute("href", "/ajax/download?path="+path);
	                a.setAttribute("id", "openwin");
	                document.body.appendChild(a);
	                a.click();
	                api.close();              
	            }
	            
	        },true);  
	    }
	} 

	//导出
	$(document).on('click', '#export-btn', function () {
	    var type=isSent==1?"couponLogsExport":"couponSendErrorExport";     
	    var total = isSent==1?g.total:g1.total;
	    if (total <= 0) {
	        common.util.__tip("当前0条数据,无需导出!", "warning")
	    } else {    
	        var queryConf = JSON.stringify({couponId: couponId});
	        common.util.__ajax({
	        url: '/couponExport',
	        data: {
	            queryConf: queryConf,
	            type:type
	        }
	        },function(res) {
	             api=Bll.toast();
	            if(res&&res.data){
	                $(document).ready(function(){  
	                path=res.data;
	                 t=window.setInterval(f.check,2000);   
	                });
	            }
	        });       
	    }
	});

	//输入限制
	$(document).on("keyup", ".number", function () {
	    $(this).val($(this).val().replace(/\D/g, ''));
	});

	//重发
	$(document).on("click", ".reSend", function () {
	    var item = g1.rows[$(this).data("index")];
	    common.dialog.confirm("重发确认","是否确认重发?",function() {
	        common.util.__ajax({
	            url: '/couponSendError/retrySend',
	            data: {
	                id: item.id
	            },

	        },function() {
	            g1.reload();
	        });
	    });
	});




/***/ }
]);