<!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 ?>/filed/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="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'], function() {
				var table = layui.table,
					admin = layui.admin;

				table.render({
					elem: '#test-table-operate',
					url: '/<?= ADMIN_NAME ?>/filed/getfiledlist?table_id=<?=$table_id?>',
					height: 'full-100',
				    cellMinWidth: 80,
				    page: true,
				    limit: 20,
					cols: [
						[{
								field: 'id',
								width: 80,
								title: 'ID',
								sort: true,
								fixed: 'left'
							}, {
								field: 'u1',
								width: 160,
								title: '数据库字段名',
								sort: true,
							}, {
								field: 'u2',
								width: 120,
								title: '字段名称',
								sort: true,

							}, {
								field: 'u4',
								width: 80,
								title: '必填',
								sort: true,
							}, {
								field: 'u5',
								width: 80,
								title: '显示',
								sort: true,
							}, {
								field: 'u6',
								width: 80,
								title: '检索',
								sort: true
							}, {
								field: 'u7',
								width: 120,
								title: '字段类型',
								sort: true
							}, {
								field: 'u10',
								width: 80,
								title: '排序',
								sort: true
							} , {
								field: 'u15',
								width: 120,
								title: '字段显示分类',
								sort: true
							} ,{
								field: 'u18',
								width: 120,
								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 === 'del') {
						layer.confirm('真的删除行么', function(index) {
							layer.close(index);
							var id = data.id;
							window.location.href="/<?= ADMIN_NAME ?>/filed/delete?id="+id+"&table_id=<?=$table_id?>";
						});
					} else if(obj.event === 'edit') {
						var id = data.id; 
						layOpen("修改"+data.u2+"字段","/<?= ADMIN_NAME ?>/filed/edit?id="+id+"&table_id=<?=$table_id?>","100%","100%");
						
					}
				});
			});
		</script>

	</body>

</html>