<?php $this->display(tpl('head',true)); ?>
<style>
	.layui-table td, .layui-table th {
	    position: relative;
	    padding: 9px 5px;
	    min-height: 20px;
	    line-height: 20px;
	    font-size: 14px;
	    text-align: center;
	}

	.layui-form-checkbox {
	    height: 20px;
	    line-height: 20px;
	    padding-right: 20px;
	}
	.layui-form-checkbox i {
	    width: 25px;
	    font-size: 18px;
	}
	#add_category{
		margin-left: 30px;
	}
	#add_category span{
		float: left;
		line-height: 40px;
		color: #666;
	}
	.add_category{
		width: 160px;
		float: left;
		margin-right: 10px;
	}
	.add_category_button{
		float: left;
		height: 35px;
		margin-left: 10px;
	}
	#add_category .layui-form-select{
		width: 20%;
		float: left;
	}
</style>
<fieldset class="layui-elem-field layui-field-title">
  	<legend>专题管理</legend>
</fieldset>
<div class="layui-row">
	<form class="layui-form" id="add_category" method="post" action="/admin/special/add">
		<span>专题名称：</span>
		<input type="text" class="layui-input add_category" placeholder="请输入需要创建的专题名称" name="name" />
		<span>所属分类：</span>
		<select name="sid">
			<option>请选择一个分类</option>
			<?php echo $special_category ?>
		</select>
		<input type='hidden' name="step" value="add" />
		<button  class="layui-btn layui-btn-sm layui-btn-warm add_category_button">创建专题</button>
	</form>
</div>

<form class="layui-form" method="post" action="/admin/articles/batch_edit/">
	<table class="layui-table">
		<thead>
			<tr>
				
				<th width="80">ID</th>
				<th>专题名称</th>
				<th width="100">所属分类</th>
				<th width="100">浏览量</th>
				<th width="100">入库文章</th>
				<th width="100">评论</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
	<?php foreach($data AS $row) {
		$url=U(['special'=>'content','id'=>$row[id],'sid'=>$row[sid]]);
		$curl=U(['special'=>'category','sid'=>$row[sid]]);
	?>
			<tr>
				<td><?php echo $row[id] ?></td>
				<td title="<?php echo $row[name] ?>">
					<a href="<?php echo $url ?>" target="_blank"><?php echo $row[name] ?></a>
				</td>
				<td><a href="<?php echo $curl ?>"><?php echo C('home|Special_category_setting.'.$row[sid])[name] ?></a></td>
				<td><?php echo $row[clicks] ?></td>
				<td><a href="/admin/special/articles/id_<?php echo $row[id] ?>"><?php echo $row[article_num] ?></a></td>
				<td><a href="/admin/special/comment/id_<?php echo $row[id] ?>"><?php echo $row[comment_num] ?></a></td>

				<td width="80">
					<div class="layui-table-cell ">
						<a class="layui-btn layui-btn-sm layui-btn-warm" href="/admin/special/edit/id_<?php echo $row[id] ?>">编辑</a>
						<a class="layui-btn layui-btn-sm layui-btn-danger" href="/admin/special/del/id_<?php echo $row[id] ?>">删除</a>
					</div>
				</td>
			</tr>
	<?php } ?>
		</tbody>
	</table>
</form>
<div class="page">
	<?php echo $Get_Page ?>
</div>
<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(['table','form', 'layer'], function() {
		var table = layui.table,form=layui.form,layer = layui.layer;
		form.on('switch(state)', function(obj) {
			if(obj.elem.checked == true) {
				var state = 1;
			} else {
				var state = 0;
			}
			set({'state': state,'aid': obj.elem.id});

			if(obj.elem.checked == true) {
				layer.tips("已完成审核", obj.othis);
			} else {
				layer.tips("已取消审核", obj.othis);
			}
		});
		form.on('switch(is_recommend)', function(obj) {
			if(obj.elem.checked == true) {
				var state = 1;
			} else {
				var state = 0;
			}
			set({'is_recommend': state,'aid': obj.elem.id});
			if(obj.elem.checked == true) {
				layer.tips("已完成推荐", obj.othis);
			} else {
				layer.tips("已取消推荐", obj.othis);
			}
		});
		function set(data){
			$.ajax({
				url: "/admin/articles/batch_edit/",
				type: 'POST',
				data:data,
				dataType: 'json',
				success: function(data) {
					return data;
				}
			})
		}
	});
</script>
<?php $this->display(tpl('foot',true)); ?>
