index.js 4.04 KB
'use strict';
var $ = require('jquery'),
    common=require('../common/common');

exports.init = function() {
	 new common.dropDown({el: '#filter-dep'});
	 var g = new common.grid({
        el: '#basicTable',
        parms:function(){
        	return {
                batchNo:common.util.__input("batchNo"),
                name:common.util.__input("name"),
                reqDepartment:common.util.__input("reqDepartment")
            };
        },
        columns:[
        	{display:"批次号",name:"batchNo"},
        	{display:"基本信息",render:function(item){
        		var arr=[];
        		arr.push("<p>名称:"+item.name+"</p>");
        		arr.push("<p>次数:"+item.limitTimes+"</p>");
        		arr.push("<p>数量:"+item.userUseLimit+"</p>");
        		arr.push("<p>部门:"+item.reqDepartment+"</p>");
        		return arr.join('');
        	}},
        	{display:"使用日期",render:function(item){
        		return item.limitDateFrom+"</br> 至 "+item.limitDateTo;
        	}},
        	{display:"限购码使用说明",name:"describe"},
        	{display:"申请人",name:"creatorName"},
        	{display:"操作",render:function(item){
        		var HtmArr=[];
                //限购码状态0:待审核 1:审核通过 2:驳回 3:过期 4:作废
        		HtmArr.push('<a href="/limit/code/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>');
                }else if(item.status==1){
                    HtmArr.push('<a class="btn btn-danger btn-xs apply-cancel" data-index="'+ item.__index+'" href="javascript:;">作废</a>');
                }else if(item.status==2){
                    HtmArr.push('<a class="btn btn-info btn-xs apply-modify" href="/limit/code/update/'+ item.id+'">修改</a>');
                }
                return HtmArr.join('');
        	}}
        ]
    });
	g.init($("#gridurl").val());

    $("#btn-search").click(function(){
        g.reload();
    });
    $("#btn-reset").click(function(){
        $("#batchNo").add("#name").val('');
        $("#reqDepartment").val(-1);
        g.reload();
    });

    var tool={
        toast:function(content,fn){
            common.dialog.confirm("温馨提示",content,function(){
                common.util.__ajax({
                    url:'/limit/code/auditLimitCode',
                    data:fn()
                },function(){
                    g.reload();
                });
            });
        }
    }
     //审核通过
     $('#basicTable').on('click', '.apply-success', function() {
        var item=g.rows[$(this).data("index")];
        var data=function(){
            return {
                    id:item.id,
                    status:1,
                    reason:"预算不够"
                };
        }
        tool.toast("确定要通过该申请吗?",data);
     });
     //驳回
     $('#basicTable').on('click', '.apply-back', function() {
        var item=g.rows[$(this).data("index")];
        var data=function(){
            return {
                id:item.id,
                status:2,
                reason:$("#reason").val()
            };
        };
        tool.toast(common.util.__template($("#template").html(),{title:"你确定要驳回该申请吗?"}),data);
     });
     //作废
     $('#basicTable').on('click', '.apply-cancel', function() {
        var item=g.rows[$(this).data("index")];
        var data=function(){
            return {
                id:item.id,
                status: 3,
                reason:$("#reason").val()
            };
        }
        tool.toast(common.util.__template($("#template").html(),{title:"你确定要作废此限购码吗?"}),data);
     });
}