<?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;
	}
</style>
<fieldset class="layui-elem-field layui-field-title">
  	<legend>文章管理</legend>
</fieldset>
<div class="layui-row">
	<a class="layui-btn layui-btn-sm  layui-btn-warm" href="<?php echo  admin_module_url  ?>/articles/alllist/">全部</a>
	<a class="layui-btn layui-btn-sm  layui-btn-warm" href="<?php echo  admin_module_url  ?>/articles/alllist/state_0">未审</a>
	<a class="layui-btn layui-btn-sm  layui-btn-danger" href="<?php echo  admin_module_url  ?>/articles/alllist/state_1">已审</a>
	<a class="layui-btn layui-btn-sm" href="<?php echo  admin_module_url  ?>/articles/alllist/is+++recommend_1">已推</a>
</div>
<form class="layui-form" method="post" action="<?php echo  admin_module_url  ?>/articles/batch_edit/">
	<table class="layui-table">
		<thead>
			<tr>
				<th width="20"></th>
				<th>AID</th>
				<th>标题</th>
				<th>所在栏目</th>
				<th>发布人</th>
				<th>浏览量</th>
				<th>评论</th>
				<th>发布时间</th>
				<th>审核</th>
				<th>推荐</th>
				<th>页数</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
	<?php foreach($data AS $row) { ?>
		
	<?php 
		extract(\\temmoku\\db::from(M_jab.'content')->select('count(*) AS NUM')->where("aid= '$row[aid]' ")->row());
		$row['posttime']=date('Y-m-d H:i:s',$row['posttime']);
		$state="";
		if($row[state]){
			$state="checked";
		}
		$is_recommend="";
		if($row[is_recommend]){
			$is_recommend="checked";
		}
		$row[all_title]=$row[title];
		$row[title]=Get_word_strpos($row[title],'15');
		$url=U(['aid'=>$row[aid],'cid'=>$row[cid]],M_MODULE);
		$curl=U(['cid'=>$row[cid]],M_MODULE);
	?>
			<tr>
				<td><input type="checkbox" name="iddb[]" value="<?php echo $row[aid] ?>" /></td>
				<td><?php echo $row[aid] ?></td>
				<td title="<?php echo $row[all_title] ?>">
					<a href="<?php echo $url ?>" target="_blank"><?php echo $row[title] ?></a>
				</td>
				<td><a href="<?php echo $curl ?>"><?php echo $row[name] ?></a></td>
				<td><?php echo $row[username] ?></td>
				<td><?php echo $row[clicks] ?></td>
				<td><?php echo $row[comment_num] ?></td>
				<td><?php echo $row[posttime] ?></td>
				<td>
					<input <?php echo $state ?> lay-skin="switch" lay-filter="state" id="<?php echo $row[aid] ?>" lay-text="已审|待审" type="checkbox" value="1">
				</td>
				<td>
					<input <?php echo $is_recommend ?> lay-skin="switch" lay-filter="is_recommend" id="<?php echo $row[aid] ?>" lay-text="已推|未推" type="checkbox" value="1">
				</td>
				<td><?php echo $NUM ?></td>
				<td width="80">
					<div class="layui-table-cell ">
						<a class="layui-btn layui-btn-sm layui-btn-warm" href="<?php echo  admin_module_url  ?>/articles/edit/aid_<?php echo $row[aid] ?>">编辑</a>
						<a class="layui-btn layui-btn-sm layui-btn-danger" href="<?php echo  admin_module_url  ?>/articles/del/aid_<?php echo $row[aid] ?>">删除</a>
					</div>
				</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="state" value="1">批量审核</button>
		<button class="layui-btn layui-btn-sm layui-btn-danger" name="state" value="0">取消审核</button>
		<button class="layui-btn layui-btn-sm layui-btn-danger" name="is_recommend" value="1">批量推荐</button>
		<button class="layui-btn layui-btn-sm layui-btn-danger" name="is_recommend" value="0">取消推荐</button>
		<button class="layui-btn layui-btn-sm layui-btn-danger" name="step" value="del">批量删除</button>
	</div>
</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: "<?php echo  admin_module_url  ?>/articles/batch_edit/",
				type: 'POST',
				data:data,
				dataType: 'json',
				success: function(data) {
					return data;
				}
			})
		}
	});
</script>
<?php $this->display(tpl('foot',true)); ?>
