<?php $this->display(tpl('head')); ?>
<fieldset class="layui-elem-field layui-field-title">
  	<legend>钩子预埋点管理</legend>
  	<div class="layui-row mt10">
  		<a class="layui-btn  layui-btn-normal" href="javascript:" onclick="add('0')">添加钩子预埋点</a>
  		<a class="layui-btn  layui-btn-normal" href="/admin/hook/hook_list/" >钩子接口管理</a>
  	</div>
</fieldset>
<style>
	.my-tabel tbody tr td:first-child {
    	width: 0;
	}
	.my-tabel thead tr th{
		text-align: center;
	}
	.mt10{
		margin-left: 20px;
		margin-top: 10px;
	}
</style>
 <table class="layui-table my-tabel layui-form">
 	<thead>
		<tr>
		  	<th width="10">id</th>
		    <th width="100">方法名</th>
		    <th>钩子描述</th>
		   	<th width="100">记录集</th>
		   	<th width="100">操作</th>
		</tr>
	</thead>
	<tbody>
		<?php foreach((array)$data as $row){ ?>
		<tr id="list_<?php echo $row[id] ?>">
			<td align="center"><?php echo $row[id] ?></td>
			<td align="center" id="name_<?php echo $row[id] ?>"><?php echo $row[name] ?></td>
 			<td id="content_<?php echo $row[id] ?>"><?php echo $row[content] ?></td>
   			<td align="center"><a href="/admin/hook/hook_list/method_<?php echo str_replace("_","+++",$row[name]); ?>"><?php echo $row[num] ?></a></td>
			<td align="center">
				<a class="layui-btn layui-btn-xs layui-btn-normal" href="javascript:" onclick="add(<?php echo $row[id] ?>)">编辑</a>
				<a class="layui-btn layui-btn-xs layui-btn-danger"  onclick="return confirm('您是否确定要卸载本模块？此方法不可逆')"  href="/admin/hook/index/step_del/id_<?php echo $row[id] ?>">删除</a>
			</td>
		</tr>
		<?php } ?>
	</tbody>
</table>
<div class="page"><?php echo $Get_Page ?></div>
<div class="post" style="display: none;">
	<form class="layui-form" action="" method="post">
		<table class="layui-table">
			<tbody>
				<tr>
					<td style="width: 20px;">方法名：</td>
					<td>
						<input type="text" name="name" class="layui-input" id="name"/>
					</td>
				</tr>
				<tr>
					<td style="width: 20px;">钩子描述：</td>
					<td>
						<textarea class="layui-textarea" id="content" name="content"></textarea>
					</td>
				</tr>
				<tr>
					<td colspan="2" style="text-align: center; width: 100%;">
						<input type="hidden" name="id" id="id" value="0" />
						<input type="hidden" name="step" id="step" value="post" />
						<input type="hidden" name="json" id="json" value="true" />
    					<button class="layui-btn" lay-submit lay-filter="post">提交</button>
    					<button type="reset" id="reset" class="layui-btn layui-btn-primary">重置</button>
					</td>
				</tr>
			</tbody>
		</table>
	</form>
</div>
<script type="text/javascript">
function add(id){
	$('#id').val(id);
	if(id){
		$('#name').val($('#name_'+id).html());
		$('#content').val($('#content_'+id).html());
	}
	
	layer.open({
		type: 1,
		title: '添加&修改预埋钩子',
		area: ['80%', '300px'],
		shadeClose:false,
		hade: [0.8, '#393D49'],
		content: $('.post') //这里content是一个普通的String
	});
	return false;
}

layui.use(['form','table'], function(){
	var form = layui.form;
	var table = layui.table;
	form.on('submit(post)', function(data){
		$.ajax({
			url: "",
			type: 'POST',
			data: data.field,
			dataType: 'json',
			success: function(res) {
				if(res.code==0){
					if(data.field.id > 0){
						$('#name_'+data.field.id).html(data.field.name);
						$('#content_'+data.field.id).html(data.field.content);
					}else{
						 window.location.reload();
					}
					layer.closeAll();
				}else{
					layer.msg(res.text);
				}
			}
		});
		return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
	});
});
</script>
<?php $this->display(tpl('foot')); ?>
