queryCoupon.js 3.4 KB
/**
 * Created by ty on 2016/5/24.
 */
'use strict';
var $ = require('jquery'),
    common=require('../common/common');

var couponId = location.href.substring(location.href.lastIndexOf("/") + 1);
$("#filter-couponId").val(couponId);

//grid
var g = new common.grid({
    el: '#content-list',
    async:false,
    parms:function(){
        return {
            couponName: common.util.__input("filter-couponName"),
            couponCode: common.util.__input("filter-couponCode"),
            orderCode: common.util.__input("filter-orderCode"),
            uid: common.util.__input("filter-uid")
        };
    },
    columns:[
        {display:"UID", name:"uid"},
        {display:"优惠券ID",name:"couponId"},
        {display:"单券号",name:"couponCode"},
        {display:"订单号",name:"orderCode"},
        {display:"优惠券名称",name:"couponName"},
        {display:"有效期",name:"endTimeStr"},
        {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('');
        }}
    ]
});
/**
 * 通用对象
 * @type {{toast: Bll.toast}}
 */
var Bll = {
    toast:function(item, url, title) {
        common.dialog.confirm(title,common.util.__template2($("#template-delay").html(), item),function(){
            var time = parseInt(new Date($("#delayTime").val()).getTime() / 1000);
            common.util.__ajax({
                url:'/couponLogs/delayUserCoupon',
                data:{id:item.id,endTime:time}
            },function(){
                g.reload();
            });
        });
        $("#delayTime").fdatepicker({
            format: 'yyyy-mm-dd hh:ii:ss',
            pickTime: true
        }).data("datepicker").setStartDate(item.endTimeStr);
    }
};

$(document).on("click", "#filter-btn", function() {
    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}
    },function() {
        g.reload();
    });
});

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