    var user = $.zui.store.get("user") ;  // 缓存用户信息，取出dept_id
    var dept_id = user.organid;
    var team_id;
    var type = 2;
    var idUpdate;
    var organid = user.organid;
    function queryTable(){
        var data = {
            "dept_id":dept_id
        }
        data.type = type;
        var name = $("#select_name").val();
        if(name!=''){
            data.name = name ;
        }
        var cols = [
                        {width: 30, text: '序号', flex: false, colClass: 'text-center',field:'num'},
                        {width: 70, text: '班组名称', flex: false,colClass: '',field:'name'},
                        {width: 80, text: '所属人员分类',  flex: false, colClass: '',field:'type',func:function(obj){
                            if(obj==1){
                                return "收费人员";
                            }else if(obj == 2){
                                return "稽查人员";
                            }
                        }},
                        {width: 40, text: '班长', type: 'string', flex: false, sort: 'down',field:'monitor_name'},
                        {width: 40, text: '副班长', type: 'string', flex: false, colClass: '',field:'sub_monitor_name'},
                        {width: 200, text: '人员',  flex: false, colClass: '',field:'user_ids_name'},
                        {width: 50, text: '操作',  flex: false, colClass: '',field:'id',oper:[
                            {func:'updateCheckTeam',text:'修改',icon_class:'icon-edit'},{func:'deleteCheckTeam',text:'删除',icon_class:'icon-remove-circle'}
                        ]},
                    ] ;
        
        $('.datatable').mytable({'cols':cols,
                                'url':"team/getTeamByName",
                                'param':data}
                                );
    }
    function deleteCheckTeam(id){
        deleteItem4Common(id,"team/delete",queryTable);
    }
     $(document).ready(function() {
         queryTable();
         getUser();
    })
    function getUser(){
        data ={
            "organid":organid
        }
        post_common_service("user/getUserList", data, function(data){
            $("#team_name").val("");
            $("#monitor").empty();
            $("#second-monitor").empty();
            $("#member").empty();
            $("#monitor").append('<option value="0">请选择班长</option>');
            $("#second-monitor").append('<option value="0">请选择副班长</option>');
            for(i=0;i<data.length;i++){
                $("#monitor").append('<option value="'+data[i].id+'">'+data[i].truename+'</option>');
                $("#second-monitor").append('<option value="'+data[i].id+'">'+data[i].truename+'</option>');
                $("#member").append('<div style="width:78px;float:left;">\
                                         <input type="checkbox" value="'+data[i].id+'" name="chkItem"><span>'+data[i].truename+'</span>\
                                     </div>');
            }
        }, function(){

        });
    }
    function updateCheckTeam(id){
        team_id = id;
        data = {
            "id":id
        }
        post_common_service("team/getTeamById", data, function(data){
            $("#team_name").val(data.name);
            $("#monitor").val(data.monitor);
            $("#second-monitor").val(data.sub_monitor);
            var ids = data.user_ids.split(",");
            for(i=0;i<ids.length;i++){
                console.log(ids[i])
                $("input[name='chkItem']:checkbox").each(function(){ 
                    if($(this).attr('value') == ids[i]){
                        $(this).prop("checked", true);
                    }
                });
            }
            idUpdate = true;
            layerUpdateTeam('form-div','班组修改','550px');
        }, function(){

        });
        
    }
    function layerUpdateTeam(domId,title,area){
        layer.open({
            type: 1,
            title: false,
            closeBtn: 1,
            title:title,
            shadeClose: true,
            skin: 'yourclass',
            area:area,
            content: $("#"+domId)
        });
        
    }
    //关闭弹窗
    $("#close-layer").click(function(){
        layer.closeAll();
    })
    //保存修改或添加
    $("#save-team").click(function(){
        var user_ids = "";
         $.each($('input:checkbox'),function(){
                if(this.checked){
                    user_ids = user_ids +　$(this).val() + ",";
                }
        });
        if(user_ids != ""){
            user_ids = user_ids.substring(0,user_ids.length-1);
        }else{
            layer.msg('请选择人员');
            return;
        }
        data = {
            "id":team_id,
            "dept_id":dept_id,
            "name":$("#team_name").val(),
            "user_ids":user_ids,
            "type":type,
            "monitor":$("#monitor").val(),
            "sub_monitor":$("#second-monitor").val()
        }
        if(idUpdate){
            post_common_service("team/update", data, function(data){
                layer.closeAll();
                queryTable();
            }, function(){

            });
        }else{
            post_common_service("team/add", data, function(data){
                layer.closeAll();
                queryTable();
            }, function(){

            });
        }
    })

    //条件查询
    $("#conditional_query").click(function(){
        queryTable();
    })

    //添加班组
    $("#addTeam").click(function(){
        idUpdate = false;
        $("#team_name").val("");
        $("#monitor").val(0);
        $("#second-monitor").val(0);
        $("[name = chkItem]:checkbox").attr("checked", false);
        layerUpdateTeam('form-div','班组新增','550px');
    })
