<?php 
$this->display(tpl('head',true)); 
?>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
	<legend>专题"<?php echo $special[name] ?>"的评论</legend>
</fieldset>
<style>
	.table {
		background-color: #f8f8f8;
		padding: 20px;
	}
	
	.layui-table thead tr {
		background-color: #fff;
	}
	
	.layui-table thead tr th {
		font-weight: bold;
		text-align: center;
	}
	
	.layui-row {
		margin-bottom: 10px;
		margin-left: 20px;
	}
</style>
<div class="layui-row">
	<a class="layui-btn layui-btn-sm  layui-btn-warm" href="<?php echo admin_module_url  ?>special/comment/id_<?php echo $_GET[id] ?>/state_0">未审</a>
	<a class="layui-btn layui-btn-sm  layui-btn-danger" href="<?php echo  admin_module_url  ?>special/comment/id_<?php echo $_GET[id] ?>/state_1">已审</a>
	<a class="layui-btn layui-btn-sm" href="<?php echo  admin_module_url  ?>special/comment/id_<?php echo $_GET[id] ?>/">全部</a>
</div>
<form class="layui-form" id="from" method="post" action="">
	<table class="layui-table">
		<thead>
			<tr>
				<th width="20" align="right"></th>
				<th width="50">Id</th>
				<th>评论内容</th>
				<th width="50">发布人</th>
				<th width="60">发布时间</th>
				<th width="60">状态</th>
				<th width="40">操作</th>
			</tr>
		</thead>
		<tbody id="tbody">
			<?php foreach($data AS $row){ ?>
			<?php	$state="";if($row[state]===1){$state="checked";}?>
				<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 echo $row[username] ?>
					</td>
					<td align="center">
						<?php echo date('Y-m-d H:i:s',$row[posttime])  ?>
					</td>
					<td>
						<div class="layui-form-item">
							<div class="layui-input-block">
								<input <?php echo $state ?> lay-skin="switch" lay-filter="state" id="<?php echo $row[id] ?>" lay-text="已审|待审" type="checkbox" value="1">
							</div>
						</div>
					</td>
					<td class="dr_option">
						<button class="layui-btn layui-btn-sm"  onclick="return del('<?php echo $row[id] ?>')">删除</button>
					</td>
				</tr>
				<?php } ?>
				<?php if(!$data){ ?>
					<tr>
						<td colspan="5" align="center">暂无评论......</td>
					</tr>
				<?php } ?>
		</tbody>
	</table>
	<div class="button">
		<input type="hidden" id="step" name="step"  />
		<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" name="state" value="1" onclick="return post('state')">通过审核</button>
		<button class="layui-btn layui-btn-sm layui-btn-danger" name="state" value="0" onclick="return post('state')">取消审核</button>
		<button class="layui-btn layui-btn-sm layui-btn-danger" name="step" value="del" onclick="return post('del')">批量删除</button>
	</div>
	<div class="page">
		<?php echo $Get_Page ?>
	</div>
</form>

<script>
	function del(id){
		$.ajax({
			url: "<?php echo admin_module_url  ?>special/comment_action/",
			type: 'POST',
			data: {
				'step':'del',
				'id': id
			},
			dataType: 'json',
			success: function(data) {
				if(data.code==1){
					$('#list_'+id).remove();
				}else{
					alert(data.text);
				}
			}
		});
		return false;
	}
	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;
	}

	function post(a) {
		if(a === 'state') {
			$('#step').val('state');
			$('#from').attr('action', '<?php echo  admin_module_url  ?>special/comment_action/');
		} else {
			$('#step').val('del');
			$('#from').attr('action', '<?php echo  admin_module_url  ?>special/comment_action/');
		}
	}

	layui.use(['form', 'layer'], function() {
		var form = layui.form,
			layer = layui.layer;

		form.on('switch(state)', function(obj) {
			if(obj.elem.checked == true) {
				var state = 1;
			} else {
				var state = 0;
			}
			$.ajax({
				url: "<?php echo admin_module_url ?>special/comment_action/",
				type: 'POST',
				data: {
					'step':'state',
					'state': state,
					'id': obj.elem.id
				},
				dataType: 'json',
				success: function(data) {
					if(obj.elem.checked == true) {
						layer.tips("已完成审核", obj.othis);
					} else {
						layer.tips("已取消审核", obj.othis);
					}
				}
			})
		});
	});
</script>

<?php 
$this->display(tpl('foot',true)); 
?>
