<div class="layui-form" style="margin-top: 15px; padding-right: 15px;">
<div style="float: left;"><a class="layui-btn" href="/glnotice/basic/index.html"><i class="layui-icon layui-icon-add-circle"></i> 添加公告</a></div>
<div style="float: right;">
<form class="layui-form" id="search_form" method="post" action="/glnotice/default/index.html">
  <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">公告标题</label>
      <div class="layui-input-inline">
        <input type="text" class="layui-input" name="se_title" value="<?php echo $search["se_title"]; ?>">
      </div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label">状态</label>
      <div class="layui-input-inline">
        <select name="se_isexpiry">
        <option value=""></option>
        <option value="1"<?php if($search["se_isexpiry"]==1){echo ' selected';} ?>>正常</option>
        <option value="2"<?php if($search["se_isexpiry"]==2){echo ' selected';} ?>>已过期</option>
        </select>
      </div>
    </div>
    <div class="layui-inline">
    	<button class="layui-btn" lay-submit>搜索</button>
    </div>
  </div>
</form>
</div>
<div style="clear: both;"></div>
</div>

<div class="layui-form" style="margin-top: 15px; padding-right: 15px;">
<form id="list_form" method="post">
<table class="layui-table" lay-skin="line">
  <thead>
    <tr>
      <th><input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose"></th>
      <th>标题</th>
      <th>有效期起始</th>
      <th>有效期截止</th>
      <th>状态</th>
      <th>操作</th>
    </tr> 
  </thead>
  <tbody id="pagelistbox">
    
  </tbody>
  <tfoot>
  	<tr id="waitingtipsbox" style="display: none;"><td colspan="6" align="center"><i class="layui-icon layui-anim layui-anim-rotate layui-anim-loop">&#xe63d;</i> 努力加载中......</td></tr>
    <tr>
      <td><input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose"></td>
      <td colspan="5"><button class="layui-btn" title="删除" id="delete_button">删除</button></td>
    </tr> 
  </tfoot>
</table>
</form>
</div>

<div class="layui-form">
	<div style="float: left;"><div class="layui-box layui-laypage layui-laypage-default"><span class="layui-laypage-total">共 <?php echo $pager->allsize; ?> 条</span></div></div>
	<div id="pagelinkbox" style="float: right;"></div>
  <div style="clear: both;"></div>
</div>

<form id="gotopage_form" style="display: none;">
	<input type="hidden" name="curpage">
	<input type="hidden" name="rnum">
	<input type="hidden" name="listmore" value="yes">
  <input type="hidden" name="se_title" value="<?php echo $search["se_title"]; ?>">
	<input type="hidden" name="se_isexpiry" value="<?php echo $search["se_isexpiry"]; ?>">
</form>

<script type="text/javascript">
$(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');
  });

  //分页
  var laypage = layui.laypage;
  laypage({
    cont: 'pagelinkbox',
    pages: <?php echo $pager->allpage; ?>,
    skip: true,
    jump: function(obj, first){
      $("#gotopage_form").find("input[name='curpage']").val(obj.curr);
      $("#gotopage_form").find("input[name='rnum']").val(Math.random());
      $("#gotopage_form").ajaxSubmit({
    		url: '/glnotice/default/index.html', 
    		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;
    }
  });

  //删除
  $("#delete_button").on("click", function(){
    var checkednum = $("#list_form").find("input[name='noticeid[]']:checked").length;
    if(checkednum==0){
      layer.msg("您还没有选择", {icon: 2});
      return false;
    }
    var layerbox = layer.confirm('确认要移动到回收站吗？', {
      area: ['400px', '230px'],
      icon: 0,
      btn: ['确定','取消'] //按钮
    }, function(){
      $("#list_form").ajaxSubmit({
        url: '/glnotice/default/delete.html', 
        type: 'POST',
        dataType: "json", 
        beforeSend: function(){
          layer.load(0, {shade: [0.2, '#393D49']});
        },
        success: function(data){
          if(data.code=="success"){
            layer.msg("成功", {icon:1}, function(){window.location.reload();});
          }else{
            layer.msg(data.msg, {icon:2});
          }
        },
        error: function(){
          layer.msg("系统错误，请联系管理员", {icon:2});
        },
        complete: function(){
          layer.closeAll('loading');
        }
      });
    }, function(){
      //do nothing
    });
    return false;
  });

});
</script>