coupon.js 7.32 KB
/**
 * 优惠码列表页
 */
'use strict';
var $ = require('jquery'),
    common=require('../common/common');

var ENUM={
    status:{0:'待审核',1:'审核通过',2:'驳回',3:'过期',4:'作废'},//全部
    tips:{"0":0,"1":0,"2":0,"3":0,"4":0,"all":0}
}

//下拉框
new common.dropDown({el: '#filter-dep'});

var t = new common.tab({
    el:"#basicTab",
    click:function(){
        g.reload(1);
    },
    columns:[
        {name:"0",display:"待审核({0})"},
        {name:"1",display:"审核通过({1})"},
        {name:"2",display:"驳回({2})"},
        {name:"3",display:"过期({3})"},
        {name:"4",display:"作废({4})"},
        {name:"all",display:"全部({all})"}
    ]
}).init(ENUM.tips);

//grid
var g = new common.grid({
    el: '#basicTable',
    // tabUrl: $('#tabUrl').val(),
    // tabConvert: statusConvert,
    // size: 10,
    parms:function(){
        return {
            batchNo: common.util.__input("filter-id"),
            name: common.util.__input("filter-name"),
            reqDepartment:common.util.__input("filter-dep"),
            status:t.active
        };
    },
    columns:[
        {display:"批次号", name:"batchNo", render: function(item) {
            return '<a href="/market/coupon/info/' + item.id + '">' + item.batchNo + '</a>';
        }},
        {display:"基本信息",name:"name", render: function(item) {
            return '<p>名称:' + item.name + '</p><p>次数' + item.limitTimes + '</p><p>部门:' + item.reqDepartment + '</p>';
        }},
        {display: '使用期限', name: "limit", render: function(item) {
            return '<p class="audit-time">' + item.limitDateFrom + '</p><p>' + item.limitDateTo + '</p>'
        }},
        {display: '优惠码说明',name: "describe"},
        {display: '申请记录', name: "staff"},
        {display: '状态', name: "status", render: function(item) {
            var html = ENUM.status[item.status]||'全部';
            if (item.reason) {
                html += '<p style="color:red;">(' + item.reason + ')</p>';
            }
            return html;
        }},
        {display:"操作",name:"operate",render:function(item){
            var HtmArr=[];
            HtmArr.push('<a href="/market/coupon/info/'+ item.id+'" class="btn btn-info btn-xs">查看详情</a>');
            if(item.status == 0){
                HtmArr.push('<a class="btn btn-primary btn-xs apply-success" data-index="'+ item.__index+'" href="javascript:;">通过</a>');
                HtmArr.push('<a class="btn btn-warning btn-xs apply-back" data-index="'+ item.__index+'" href="javascript:;">驳回</a>');
                HtmArr.push('<a class="btn btn-danger btn-xs apply-cancel" data-index="'+ item.__index+'" href="javascript:;">作废</a>');
            }
            if(item.status == 1){
                HtmArr.push('<a class="btn btn-danger btn-xs apply-cancel" data-index="'+ item.__index+'" href="javascript:;">作废</a>');
            }
            if(item.status == 2){
                HtmArr.push('<a class="btn btn-info btn-xs apply-modify"  href="/market/coupon/update/'+ item.id+'">修改</a>');
            }
            return HtmArr.join('');
        }}
    ]
});

//tab
var loadtab=function(){
    t.active=undefined;
    setTimeout(function(){
        common.util.__ajax({
            url:'/market/coupon/getCodeCount',
            data:g.options.parms()

        },function(res){
            var __dt=$.extend({},ENUM.tips,res.data);
            t.init(__dt);
        },true);
    },400);
}
loadtab();
g.init($("#gridurl").val());
 


$("#filter-btn").click(function(){
    loadtab();
    g.reload(1);
    
});
$("#all-btn").click(function(){
    $("#filter-id").add("#filter-name").val('');
    $('#filter-dep').val("-1").trigger("change");
    loadtab();
    g.reload();
});

var Bll={
    toast:function(content,fn){
        common.dialog.confirm("温馨提示",content,function(){
            common.util.__ajax({
                url:'/market/coupon/auditPromotion',
                data:fn()
            },function(){
                g.reload();
            });
        });
    },
    definetoast:function(content,fn,fn1){
        common.dialog({
            title:"温馨提示",
            content:content,
            button:[
                {value:"取消"},
                {value:"确定" ,callback: function(){
                    common.util.__ajax({
                        url:'/market/coupon/auditPromotion',
                        data:fn()
                    },function(){
                        g.reload();
                    });
                }},
                {value:"发放列表" ,callback: function(){
                     common.dialog({
                        title:"发放列表",
                        content:'<div id="faGrid"></div>'
                     });
                     new common.grid({
                        el:"#faGrid",
                        parms:fn1(),
                        columns:[
                            {display:"批次号", name:"batchNo", render: function(item) {
                                return '<a href="/market/coupon/info/' + item.id + '">' + item.batchNo + '</a>';
                            }},
                            {display:"基本信息",name:"name", render: function(item) {
                                return '<p>名称:' + item.name + '</p><p>次数' + item.limitTimes + '</p><p>部门:' + item.reqDepartment + '</p>';
                            }},
                            {display: '使用期限', name: "limit", render: function(item) {
                                return '<p class="audit-time">' + item.limitDateFrom + '</p><p>' + item.limitDateTo + '</p>'
                            }},
                            {display: '优惠码说明',name: "describe"},
                            {display: '申请记录', name: "staff"}
                        ]
                     }).init('/market/coupon/sendPromotion');
                }}
            ]
        });
    }
}

//作废事件
$('#basicTable').on('click', '.apply-cancel', function() {
    var item=g.rows[$(this).data("index")];
    var data=function(){
        var reason = $('#reason').val();
        if (reason === '' || $.trim(reason) === '') {
            return "请填写作废原因";
        }
        return {
                id:item.id,
                status:4,
                operations:reason
            };
    }
    Bll.toast(common.util.__template($("#template").html(),{name:"您确定要作废此优惠码吗?"}),data);
});

//驳回事件
$('#basicTable').on('click', '.apply-back', function() {
    var item=g.rows[$(this).data("index")];
    var data=function(){
        var reason = $('#reason').val();
        if (reason === '' || $.trim(reason) === '') {
            return "请填写驳回原因";
        }
        return {
                id:item.id,
                status:2,
                operations:reason
            };
    }
    Bll.toast(common.util.__template($("#template").html(),{name:"您确定要驳回该申请吗?"}),data);
});
//通过事件
$('#basicTable').on('click', '.apply-success', function() {
    var item=g.rows[$(this).data("index")];
    var data=function(){
        return {
            id:item.id,
            status:1,
            operations:"申请通过"
        };
    }
    Bll.definetoast("您确定要通过该申请吗?",data,function(){
        return {auditTime:item.limitDateFrom};
    });
});