marketing.QueryCoupon.Index.js 4.64 KB
webpackJsonp([90],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	/**
	 * Created by ty on 2016/5/24.
	 */
	'use strict';
	var $ = __webpack_require__(1),
	    common=__webpack_require__(2);

	//grid
	var g = new common.grid({
	    el: '#content-list',
	    async:false,
	    parms:function(){
	        return {
	            couponCode: common.util.__input("filter-couponCode"),
	            uid: common.util.__input("filter-uid"),
	            orderCode: common.util.__input("filter-orderCode")
	        };
	    },
	    columns:[
	        {display:"UID", name:"uid"},
	        {display:"优惠券ID",name:"couponId"},
	        {display:"单券号",name:"couponCode"},
	        {display:"订单号",name:"orderCode"},
	        {display:"优惠券名称",name:"couponName"},
	        {display:"有效期", render: function(item) {
	            return '<p>' + date_fuction(item.startTime) + '--' + item.endTimeStr + '</p>';
	        }},
	        {display:"状态",render: function(item) {
	            var status = "";
	            if(item.status == 0) {
	                status = "未使用";
	            } else if(item.status == 1) {
	                status = "已使用";
	            }
	            return '<p class="audit-time">' + status + '</p>';
	        }},
	        {display:"是否取消过",render: function (item) {
	            var isCancel = "";
	            if(item.isCancel == "Y") {
	                isCancel = "已取消";
	            } else if(item.isCancel == "N") {
	                isCancel = "未取消";
	            }
	            return '<p class="audit-time">' + isCancel + '</p>';
	        }},
	        {display: '操作', render: function(item) {
	            var HtmArr=[];
	            if(item.status == 0) {
	                HtmArr.push('<a class="btn btn-primary btn-xs delayTime" data-index="' + item.__index + '" href="javascript:;">延长有效期</a>');
	            } else if(item.status == 1) {
	                HtmArr.push('<a class="btn btn-primary btn-xs cancelCoupon" data-index="' + item.__index + '" href="javascript:;">手工退券</a>');
	            }
	            return HtmArr.join('');
	        }}
	    ]
	});
	g.init([]);
	/**
	 * 通用对象
	 * @type {{toast: Bll.toast}}
	 */
	/*验证*/
	var edit = new common.edit2(".modal-body");
	var Bll = {
	    toast:function(item, url, title) {
	        var d= common.dialog.confirm(title,common.util.__template2($("#template-delay").html(), item),function(){
	            var time = parseInt(new Date($("#delayTime").val()).getTime() / 1000);
	            if(edit.validate()){
	                common.util.__ajax({
	                    url:'/couponLogs/delayUserCoupon',
	                    data:{id:item.id,uid:item.uid,endTime:time}
	                },function(){
	                    d.close();
	                    g.reload();
	                });
	            }
	            return false;
	        });
	        edit.init();
	        $("#delayTime").datetimepicker({
	            timeFormat: 'HH:mm:ss',
	            showSecond: true
	        }).data("datepicker");

	    }
	};

	$(document).on("click", "#filter-btn", function() {
	    var couponCode = common.util.__input("filter-couponCode");
	    var uid = common.util.__input("filter-uid");
	    var orderCode = common.util.__input("filter-orderCode");

	    if(uid=="" && couponCode=="" && orderCode==""){
	        common.util.__tip("优惠券ID,单券号,订单号,不能全为空!");
	    }else if(orderCode<=0 && uid=="" && couponCode==""){
	        common.util.__tip("单订单号不可以小于等于0!");
	    }else{
	        g.init("/couponLogs/queryUserCouponLogsList");
	    }
	});

	//延长有效期
	$(document).on("click", ".delayTime", function() {
	    var item = g.rows[$(this).data("index")];
	    Bll.toast(item, "/couponLogs/delayUserCoupon", "延长有效期");
	});

	//手工退券
	$(document).on("click", ".cancelCoupon", function() {
	    var item = g.rows[$(this).data("index")];
	    common.util.__ajax({
	        url: "/couponLogs/cancelCouponUse",
	        data:{id:item.id,uid:item.uid}
	    },function() {
	        g.reload();
	    });
	});

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



	function date_fuction(shijianchuo)
	{
	    //shijianchuo是整数,否则要parseInt转换
	    var time = new Date(shijianchuo * 1000);
	    var y = time.getFullYear();
	    var m = time.getMonth()+1;
	    var d = time.getDate();
	    var h = time.getHours();
	    var mm = time.getMinutes();
	    var s = time.getSeconds();
	    return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
	}

	function add0(m){return m<10?'0'+m:m }

/***/ }
]);