<?php $this->display(tpl('head',true)); ?>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
	<legend>类型管理</legend>
</fieldset>
<style>
	.my-tabel tbody tr td:first-child {
	    width: 0;
	}
</style>
<form class="layui-form" method="post" action="<?php echo  admin_module_url  ?>/module/reorder/">
	<table class="layui-table my-tabel">
		<thead>
			<tr>
				<th width="30" class="center">ID</th>
				<th>名称</th>
				<th width="70">类型状态</th>
				<th width="70">类型排序</th>
				<th width="70">属性管理</th>
				<th width="30">操作</th>
			</tr>
		</thead>
		<tbody>
			<?php 
				foreach($modelDB AS $row){
					$state='';
					if(!$row[close]){
						$state='checked';
					}
			?>
			<tr>
				<td class="center"><?php echo $row[id] ?></td>
				<td onclick=" return edit_input(this,'名称','name')" id="name_<?php echo $row[id] ?>" iid="<?php echo $row[id] ?>"><?php echo $row[name] ?></td>
				<td>
					<input <?php echo $state ?> lay-skin="switch" lay-filter="state" id="<?php echo $row[id] ?>" lay-text="开启|关闭" type="checkbox" value="1">
				</td>
				<td>
					<input type="text" name="reorder[<?php echo $row[id] ?>]" value="<?php echo $row[reorder] ?>" class="layui-input" />
				</td>
				<td style="text-align: center">
					<a title="字段管理" href="<?php echo  admin_module_url  ?>/module/field_list/mid_<?php echo $row[id] ?>"><img src="/public/admin/images/ziduan.png" width="20"></a>
				</td>
				<td>
					<a class="layui-btn layui-btn-sm  layui-btn-warm" href="<?php echo  admin_module_url  ?>/module/del/mid_<?php echo $row[id] ?>" onclick="return confirm('删除后无法恢复，是否继续删除');"> <i class="fa fa-edit"></i> 删除</a>
				</td>
			</tr>
			<?php } ?>
		</tbody>
	</table>
	<div class="button">
		<button class="layui-btn layui-btn-sm layui-btn-danger" name="step" value="reorder" >批量排序</button>
	</div>
</form>
<script>
	function edit_input(a,b,c){
		$('#'+a.id).removeAttr("onclick"); 
		var iid =$('#'+a.id).attr('iid');
		a.innerHTML='<input type="text"  class="layui-input"  name="name" id="name" value="'+a.innerHTML+'" />';
		$("#name").focus();
		$("#name").blur(function(){
			var value=$(this).attr("value");
			$.ajax({
				url:"<?php echo  admin_module_url  ?>/module/edit/",
				type: 'POST',
				data:{'value':value,'id':iid,'step':c},
				dataType: 'json',
				success: function(data){
					console.log(data);
					if(data.Result=='1'){
						layer.tips('当前'+b+'修改为：'+value,a);
						$('#'+a.id).attr("onclick"," return edit_input(this,'名称','name')");
						a.innerHTML=value;
					}else{
						a.innerHTML=data.value;
						$('#'+a.id).attr("onclick"," return edit_input(this,'名称','name')"); 
						layer.tips(data.content, a);
					}
				}
			});
			
			layer.tips('当前模块名称修改为：'+value,a);
		});
	}
	layui.use(['form', 'layer'], function() {
		var form=layui.form,layer = layui.layer;
		form.on('switch(state)', function(obj) {
			if(obj.elem.checked == true) {
				var state = 0;
			} else {
				var state = 1;
			}
			$.ajax({
				url: "<?php echo  admin_module_url  ?>/module/state/",
				type: 'POST',
				data: {
					'state': state,
					'id': obj.elem.id
				},
				dataType: 'json',
				success: function(data) {
					if(obj.elem.checked == true) {
						layer.tips("已开启", obj.othis);
					} else {
						layer.tips("已关闭", obj.othis);
					}
				}
			})
		});
	})
</script>
<?php $this->display(tpl('foot',true)); ?>
