$(document).ready(function(){  
  //全选
  var form = layui.form;
  form.on('checkbox(allChoose)', function(data){
    var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
    child.each(function(index, item){
      item.checked = data.elem.checked;
    });
    form.render('checkbox');
  });
  //筛选
  form.on('select(changecondition)', function(data){
    $("#search_form").submit();
  });

  //分页
  var laypage = layui.laypage;
  laypage.render({
    elem: 'pagelinkbox',
    count: allsize,
    limit: pagesize,
    layout: ['count', 'prev', 'page', 'next', 'skip'],
    jump: function(obj){
      $("#gotopage_form").find("input[name='curpage']").val(obj.curr);
      $("#gotopage_form").find("input[name='rnum']").val(Math.random());
      $("#gotopage_form").ajaxSubmit({
    		url: '/glxzclass/student/'+ xzclassid, 
    		type: 'POST',
    		dataType: 'html',
    		beforeSend: function(){
          $("#waitingtipsbox").show();
        },
    		success: function(data){
    			if(data==""){
    				//layer.msg("已经到最后一页了", {icon: 2});
    			}else{
    				$("#pagelistbox").html(data);
    				form.render('checkbox'); //重新渲染复选框
    			}
    			$("#waitingtipsbox").hide();
    		},
    		error: function(){
    			layer.msg("系统错误，请联系管理员", {icon: 2});
    		}
  	  });
      return false;
    }
  });

  //移动
  $("#moveto_button").on("click", function(){
    var checkedelem = $("#list_form").find("input[name='userid[]']:checked");
    if($(checkedelem).length==0){
      layer.msg("您还没有选择", {icon: 2});
    }else{
      var resourceids = "";
      $(checkedelem).each(function(){
        if(resourceids==""){
          resourceids = $(this).val();
        }else{
          resourceids += ","+ $(this).val();
        }
      });
      $("#moveto_form").find("input[name='resourceids']").val(resourceids);
      showResourMoveBox();
    }
    return false;
  });

});

//弹出层索引
var index11, index12, index13, index14;

//移动到其他班级
function showResourMoveBox(){
  var checkedelem = $("#list_form").find("input[name='userid[]']:checked");
  if($(checkedelem).length==0){
    layer.msg("您还没有选择", {icon: 2});
    return false;
  }
  var resourceids = "";
  $(checkedelem).each(function(){
    if(resourceids==""){
      resourceids = $(this).val();
    }else{
      resourceids += ","+ $(this).val();
    }
  });
  $("#moveto_form").find("input[name='resourceids']").val(resourceids);
  layer.load(0, {shade: [0.2, '#393D49']});
  index11 = layer.open({
    id: 'onedialog',
    type: 2,
    title: '编辑',
    area: ['900px', '570px'],
    fixed: false, //不固定
    content: '/glxzclass/moveto/index'
  });
  layer.closeAll('loading');
}

//添加学生
function showUserListBox(xzclassid){
  index12 = layer.open({
    id: 'twodialog',
    type: 2,
    title: '编辑',
    area: ['900px', '570px'],
    fixed: false, //不固定
    content: '/glxzclass/useradd/index?id='+ xzclassid
  });
}

//关闭添加学生窗口
function closeUserListBox(){
  layer.close(index12);
}