<!DOCTYPE html>

<html>

	<head>
		<meta charset="utf-8">
		<title>数据管理</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="<?= RESOURCES ?>/layuiadmin/layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="<?= RESOURCES ?>/layuiadmin/layuiadmin/style/admin.css" media="all">
		 
	</head>

	<body>
		<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card">

						<!--<div class="layui-card-header">内容管理</div>-->
						<div class="layui-card-body">
							<div class="layui-btn-group test-table-operate-btn" style="margin-bottom: 10px;">
								<a onclick="layOpen('添加内容', '/<?= ADMIN_NAME ?>/collection/add?table_id=<?=$table_id?>','100%','100%')" href="javascript:;" class="layui-btn"><i class="layui-icon"></i>添加数据</a>
							</div>

							<table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate"></table>

							<script type="text/html" id="test-table-operate-barDemo">
								<a class="layui-btn layui-btn-xs" lay-event="docollection">开始采集</a>
								<a class="layui-btn layui-btn-xs" lay-event="filed_edit">字段采集规则</a>
								<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
								<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
 							</script>
						</div>
					</div>
				</div>
			</div>
		</div>

		<script src="<?= RESOURCES ?>/layuiadmin/layuiadmin/layui/layui.js"></script>
		<script>
			layui.config({
				base: '<?= RESOURCES ?>/layuiadmin/layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'table', 'form', 'laydate', 'contlist'], function() {
				var $ = layui.$,
				    table = layui.table,
					admin = layui.admin,
					laydate = layui.laydate,
					form = layui.form;

				table.render({
					elem: '#test-table-operate',
					url: '/<?= ADMIN_NAME ?>/collection/gettablelist',
					height: 'full-100',
				    cellMinWidth: 80,
				    page: true,
				    limit: 20,
					cols: [
							[{"type":"checkbox"},
							 {"field":"id","width":"80","title":"ID","sort":"true"},
							 {"field":"collectionname","width":"350","title":"采集名称"},
							 {"field":"srcurl","width":"200","title":"采集网址","sort":true},
							 {"field":"table_id","width":"100","title":"系统表","sort":true},
							 {"align":"center","fixed":"right","toolbar":"#test-table-operate-barDemo"}
							]					
						   ],
				});

				//监听表格复选框选择
				table.on('checkbox(test-table-operate)', function(obj) {
					console.log(obj)
				});
				//监听工具条
				table.on('tool(test-table-operate)', function(obj) {
					var data = obj.data;
					if(obj.event === 'get_table_list') {
						var id = data.id;
						newTab(data.u2+'内容管理', '/<?= ADMIN_NAME ?>/'+data.u8+'/index?table_id='+data.id);
						
						
					} else if(obj.event === 'del') {
						layer.confirm('真的删除行么', function(index) {
							layer.close(index);
							var id = data.id;
							$.ajax({          
								  url: "/<?= ADMIN_NAME ?>/collection/delete?"+"id="+id ,
						          type: "get",
						          data: "",
						          dataType: 'JSON',
						          success: function(data) {            
										if(data.status) {              
											var index = parent.layer.getFrameIndex(window.name);              
											parent.layer.msg(data.msg, {
												icon: 6
											}); //添加成功后提示
										} else {              
											parent.layer.msg(data.msg, {
												icon: 5,
												time: 1000
											});            
										}  
										//更新行数据
										obj.del(); //删除对应行（tr）的DOM结构，并更新缓存        
									}
								})
						});
					} else if(obj.event === 'edit') {
						var id = data.id;
						layOpen("修改内容","/<?= ADMIN_NAME ?>/collection/edit?id="+id,"100%","100%");
						
					} else if(obj.event === 'filed_edit') {
						var id = data.id;
						 newTab(data.collectionname+'字段采集规则', "/<?= ADMIN_NAME ?>/collection/filededit?id="+id);
						
					} 
					else if(obj.event === 'docollection') {
						var id = data.id;
						//打开新的窗口
						    window.open("/<?= ADMIN_NAME ?>/collection/docollection?id="+id);
					} 
				
				});
				
				laydate.render({
					elem:'.ghy-date',//制定元素
					    type:'date',
					    range:true,//开启左右面板
					    trigger:'click',//定义鼠标悬停时弹出控件
					    show:false,//默认显示
					    calendar:true,//是否显示公历节日
					});
				
			//监听搜索
		    form.on('submit(LAY-app-contlist-search)', function(data){
		      var field = data.field;
		      //alert(field);
		      //执行重载
		      table.reload('test-table-operate', {
		        where: field
		      });
		    });
		});
		</script>

	</body>
 
</html>

  
	 	

  
	 	

  
	 	

 
