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

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>栏目管理</legend>
</fieldset>
<div class="layui-row">
	<a class="layui-btn layui-btn-sm layui-btn-warm" href="<?php echo  admin_module_url  ?>/category/add">添加栏目</a>
</div>
<style>
.layui-input {
    padding-left: 0;
}
.layui-form-checkbox {
    height: 20px;
    line-height: 20px;
    padding-right: 20px;
}
.layui-form-checkbox i {
    width: 25px;
    font-size: 18px;
}
</style>
<form class="layui-form" id="from" method="post" action="<?php echo  admin_module_url  ?>/category/batch_action">
	<table class="layui-table">
		<thead>
			<tr>
				<th width="20"></th>
				<th width="50">排序</th>
				<th width="50">Id</th>
				<th>名称</th>
				<th>目录</th>
				<th style="text-align: center" width="70">类型</th>
				<th style="text-align: center" width="70">模型</th>
				<th style="text-align: center" width="70">记录集</th>
				<th width="260" style="text-align: center">操作</th>
			</tr>
		</thead>
		<tbody>
			<?php foreach ($Return AS $row){ ?>
			<?php
				if($row[type]==0){
					$type="栏目";
				}elseif($row[type]==1){
					$type="分类";
				}else{
					$type="单页";
				}
				$curl=U(['cid'=>$row[cid]],M_MODULE);
			?>	
			<tr>
				<td>
					<input name="iddb[]" value="<?php echo $row[cid] ?>" type="checkbox">
				</td>
				<td>
					<input class="layui-input center" name="reorder[<?php echo $row[cid] ?>]" value="<?php echo $row[reorder] ?>" type="text">
				</td>
				<td><?php echo $row[cid] ?></td>
				<td>
					<?php echo $row[levels] ?><a class="onloading" target="_blank" href=" <?php echo  $curl  ?>"><?php echo $row[name] ?></a>
				</td>
				<td><?php echo $row[dir_name] ?></td>
				<td style="text-align: center"><span class="badge badge-success"><?php echo  $type ?></span></td>
				<td style="text-align: center"><?php echo $row[modulenbname] ?></td>
				<td style="text-align: center"><a class="onloading" href="<?php echo  admin_module_url  ?>/articles/index/cid_<?php echo $row[cid] ?>"><?php echo $row[num] ?></a></td>
				<td class="center">
					<a class="layui-btn layui-btn-sm " href="<?php echo $curl ?>" target="_blank"> <i class="fa fa-send"></i> 访问</a>
					<?php if($row[type]===0){ ?>
					<a class="layui-btn layui-btn-sm layui-btn-normal" href="<?php echo  admin_module_url  ?>/articles/add/cid_<?php echo $row[cid] ?>"> <i class="fa fa-plus"></i> 添加内容</a>
					<?php } if($row[type]===1){?>
					<a class="layui-btn layui-btn-sm bIndigo" href="<?php echo  admin_module_url  ?>/category/add/cid_<?php echo $row[cid] ?>"> <i class="fa fa-plus"></i> 添加子类</a>
					<?php } ?>								
					<a class="layui-btn layui-btn-sm layui-btn-warm" href="<?php echo  admin_module_url  ?>/category/edit/cid_<?php echo $row[cid] ?>"> <i class="fa fa-edit"></i> 修改</a>
					<a class="layui-btn layui-btn-sm layui-btn-danger" href="<?php echo  admin_module_url  ?>/category/del/cid_<?php echo $row[cid] ?>"> <i class="fa fa-edit"></i> 删除</a>
				</td>
			</tr>
			<?php } ?>			
		</tbody>
	</table>
	<div class="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('-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="step" value="reorder" >批量排序</button>
		<button class="layui-btn layui-btn-sm layui-btn-danger" name="step" value="power" >批量设置栏目</button>
	</div>
</form>
<script>
	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('switch(state)', function(obj) {
			if(obj.elem.checked == true) {
				var state = 1;
			} else {
				var state = 0;
			}
			$.ajax({
				url: "<?php echo  admin_module_url  ?>/comment/state/",
				type: 'POST',
				data: {
					'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)); ?>   
