rejectPromotions.js 8.04 KB
var $ = require('jquery'),
	common = require('../../../../common/common');
console.log("rejectPromotions in");
var rejectPromotions={
    batchIds:[],    
    buildCheckboxHtml:function(_class,_data_index,_checked){
        var _checkBox="<input type='checkbox'";        
        var _end="/>";
        if(_class){
            _checkBox+=" class='"+_class+"'";
        }
        if(_data_index){
            _checkBox+=" data-index='"+_data_index+"'";
        }
        if(_checked){
            _checkBox+=" checked='"+_checked+"'";
        }
        _checkBox+=_end;
        return _checkBox;
    },
    getParam:function(){
        var g=this;        
        /*
        var _buildCheckboxHtml = function (_class,_data_index,_checked) {                        
                return this.buildCheckboxHtml(_class,_data_index,_checked);
            };*/
        var param={
            el: '#basicTable_promotion',
            size: 10,
            parms: function() {
                return {          
                    startTime: common.util.__input('startTime'),
                    endTime:common.util.__input("endTime")            
                };
            },
            columns: [                
                {
                    display: '',
                    type: 'checkbox',
                    _class:"all",
                    render: function (item) {
                        var htmlContent = "";
                        var _class="promotion_checkbox";
                        if(g.batchIds.length === 0 ){
                            //htmlContent = "<input type='checkbox' class='wqt_checkbox' data-index='"+item.__index+"'>";
                            htmlContent = g.buildCheckboxHtml(_class,item.__index);
                        }else{
                            $.each(g.batchIds,function(n,value) {
                                if(item.id == value){
                                    //htmlContent = "<input type='checkbox' checked='checked'  class='wqt_checkbox' data-index='"+item.__index+"'>";
                                    htmlContent = g.buildCheckboxHtml(_class,item.__index,"checked");
                                    return false
                                }else{
                                    htmlContent = "<input type='checkbox'  class='wqt_checkbox' data-index='"+item.__index+"'>";
                                    htmlContent = g.buildCheckboxHtml(_class,item.__index);
                                }
                            })
                        }
                        return htmlContent;
                    }
                },{
                    display: "ID",
                    name: "id"
                }, {
                    display: "促销名称",
                    name: "title"        
                }, {
                    display: '优先级',
                    name: "priority"
                }, {
                    display: '开始时间',
                    name: "startTime",
                    render: function(item) {
                        var date = new Date(item.startTime * 1000);
                        return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
                    }
                }, {
                    display: '结束时间',
                    name: "endTime",
                    render: function(item) {
                        var date = new Date(item.endTime * 1000);
                        return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
                    }
                }, {
                    display: '是否启用',
                    name: "status",
                    render: function(item) {
                        if(item.status==1){
                            var name ="已启用" ;
                        }else {
                            var name ="未启用" ;
                        }
                        return name;
                    }
                },  {
                    display: '优惠券限制使用',
                    name: "status",
                    render: function(item) {
                        if(item.status==1){
                            var name ="是" ;
                        }else {
                            var name ="否" ;
                        }
                        return name;
                    }
                }]
        };
        return param;
    },
    bindGrid: function(param){
        return new common.grid(param);
    },
    grid: undefined,
    init: function(){
        var g=this,
            _param=this.getParam();
        this.grid=g.bindGrid(_param);
        this.grid.init("/promotionInfo/list");
        this.bindEvent();
    },
    reload:function(){
        var g=this,
        _grid=this.grid;
        _grid.reload(1);
    },
    bindEvent: function() {
	        var g = this.grid,
	            p = this.options,
                _batchIds=this.batchIds;

	        $(g.grid).on("change", ".all", function() {
	            var selected = $(".all").prop("checked");
	            $(".promotion_checkbox").prop("checked", selected);
	            g.selected.length = 0;
	            $(".promotion_checkbox").each(function() {
	                var checked = $(this).prop("checked");
	                var index = $(this).data("index");
	                if (checked) {
	                    /**************业务控制 特殊情况**************/        
	                    if(_batchIds){
	                        if($.inArray(g.rows[index]['id'], _batchIds) == -1 ){
	                                _batchIds.push(g.rows[index]['id']);	                                
	                            } 
	                    }
	                    /*********************************************/
	                    g.selected.push(g.rows[index]);
	                }else{
	                    /**************业务控制 特殊情况**************/

	                    var _index = $.inArray(g.rows[index]['id'], _batchIds);
	                    if(_batchIds && _index != -1 ){
	                        _batchIds.splice(_index,1);	                        	                    
                        }
	                    /********************************************/
	                }
	            });
	        }); //g.selected
	        //$(".promotion_checkbox").prop("checked",true);
	        $(g.grid).on("change", ".promotion_checkbox", function() {        
	            $(".all").prop("checked", false);
	            g.selected.length = 0;
	            var selected = true;  

	            /************业务控制 特殊情况****************/
	            if(_batchIds){
	                if($(this).prop("checked")){
	                    if($.inArray(g.rows[$(this).attr("data-index")]['id'], _batchIds) == -1 ){
	                        _batchIds.push(g.rows[$(this).attr("data-index")]['id']);	                        
	                    }     
	                }else{
	                    var _index = $.inArray(g.rows[$(this).attr("data-index")]['id'], _batchIds);
	                    if(_index != -1 ){
	                       _batchIds.splice(_index,1);	                      
	                    }                    
	                }            
	            }
	            /********************************************/

	            $(".promotion_checkbox").each(function() {
	                var checked = $(this).prop("checked");
	                var index = $(this).data("index");
	                if (checked) {                    
	                    g.selected.push(g.rows[index]);                                                
	                } else {                                      
	                    selected = false;
	                }
	            });
	            $(".all").prop("checked", selected);
	        });

	        $(g.grid).on("change",".t_size",function(){
	            p.size=$(this).val();
	            g.reload(1);
	        })
	    }
    }

module.exports = rejectPromotions;