<?php
$this->display(tpl('head',true)); 
?>
<style>
	.layui-row{
		margin-bottom: 10px;
		margin-left: 20px;
	}
	.my-tabel tr td:first-child {
		    width: 3%;
	}
	.layui-table th{
			text-align:center ;
	}
</style>

<form class="layui-form body" id="from" method="post" action="/user/index/modular/<?php echo M_MODULE ?>/comment/del">
	<table class="layui-table my-tabel" >
		<tr>
			<td>
				<a href="/user/index/modular/<?php echo M_MODULE ?>/comment/alllist/" class="layui-btn layui-btn-normal">全部评论</a>
					<a href="/user/index/modular/<?php echo M_MODULE ?>/comment/alllist/state/1" class="layui-btn layui-btn-warm">已审核评论</a>
					<a href="/user/index/modular/<?php echo M_MODULE ?>/comment/alllist/state/0" class="layui-btn layui-btn-danger">未审核评论</a>
			</td>
		</tr>
	</table>
	<table class="layui-table my-tabel" >
		<thead>
			<tr>
				<th width="1%"></th>
				<th width="50">Id</th>
				<th>评论内容</th>
				<th width="60">状态</th>
				<th width="60">操作</th>
			</tr>
		</thead>
		<tbody>
<?php 
foreach($data AS $row){
?>
			<tr id="list_<?php echo $row[id] ?>">
				<td align="right"><input name="iddb[]" value="<?php echo $row[id] ?>" class="dr_select"  lay-skin="primary" type="checkbox"></td>
				<td align="center"><?php echo $row[id] ?></td>
				<td><?php echo $row[content] ?></td>
				<td align="center">
					<?php if($row[state]===1){ ?>
						<span class="green">【已审】</span>
					<?php }else{ ?>
						<span class="red">【未审】</span>
					<?php } ?>
				</td>
				<td class="dr_option">
					<button class="layui-btn layui-btn-sm"  lay-submit='' lay-filter="del" id="<?php echo $row[id]?>">删除</button>
				</td>
			</tr>
<?php } ?>
		</tbody>
	</table>
	<table class="layui-table my-tabel" >
		<tr>
			<td align="center">
				<button class="layui-btn layui-btn-sm layui-btn-warm" 	onclick="return all_checkbox_check('1')">全选</button>
				<button class="layui-btn layui-btn-sm layui-btn-warm" 	onclick="return all_checkbox_check('-1')">反选</button>
				<button class="layui-btn layui-btn-sm layui-btn-warm" 	onclick="return all_checkbox_check('0')">取消选择</button>
				<button class="layui-btn layui-btn-sm layui-btn-danger" >批量删除</button>
			</td>
		</tr>
	</table>
	<?php if( $Get_Page ){ ?>
	<table class="layui-table my-tabel" >
		<tr>
		<td align="center" class="page"><?php echo $Get_Page ?></td>
		</tr>
	</table>
	<?php } ?>
</form>


<script>
	//function selectAllNullorReserve(obj,type){
function all_checkbox_check(type){
	if(document.getElementsByClassName('layui-form-checkbox')!=undefined && document.getElementsByClassName('layui-form-checkbox').length>0){  
	  var class_box = document.getElementsByClassName('layui-form-checkbox');
	  var ids = document.getElementsByName('iddb[]');
		if(type=="1"){//全选
			for(var i=0;i<class_box.length;i++){
					$(ids[i]).prop("checked", true);
			   	$(class_box[i]).addClass("layui-form-checked");
			}
		}else if(type=="0"){//全不选
			for(var i=0;i<class_box.length;i++){
					$(ids[i]).prop("checked", false);
			    $(class_box[i]).removeClass("layui-form-checked");
			}
		}else if(type=="-1"){//反选
			for(var i=0;i<class_box.length;i++){
					if(ids[i].checked==true){
						$(ids[i]).prop("checked", false);
					}else{
						$(ids[i]).prop("checked", true);
					}
			   	$(class_box[i]).toggleClass("layui-form-checked");
			}
		}
	}
	return false;
}  


layui.use(['form','layer'], function(){
  	var form = layui.form
  	,layer = layui.layer;
  	form.on('submit(del)', function(obj){
		  	$.ajax({
				url:"/user/index/modular/<?php echo M_MODULE ?>/comment/del/",
				type: 'POST',
				data:{'id':obj.elem.id,'json':true},
				dataType: 'json',
				success: function(data){
					layer.msg(data.text);
					if(data.code==0){
						$('#list_'+obj.elem.id).remove();
					}
					
				}
			})
		  return false;
  	});
});
</script>
<?php 
$this->display(tpl('foot',true)); 
?>
