<!DOCTYPE html>
<html>
    <head>
	<meta charset="UTF-8">
        {include="style"}
    </head>
    <body>
        <div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>{fun JZLANG('首页')}</cite></a>
              <a><cite>{fun JZLANG('系统扩展')}</cite></a>
              <a><cite>{fun JZLANG('模块管理')}</cite></a>
              <a><cite>{fun JZLANG('字段管理')}</cite></a>
              
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"  href="javascript:location.replace(location.href);" title="{fun JZLANG('刷新')}"><i class="iconfont" style="line-height:30px">&#xe6aa;</i></a>
        </div>
        <div class="x-body">
        <div class="layui-card">
			<div class="layui-card-body">
			<xblock>
		    <form class="layui-form " method="get" id="myform"> 
			   <div class="layui-input-inline" >
			   <select class="layui-btn-sm" id="change_tid" lay-search=""  lay-filter="change_tid" >
			   <option value="0">{fun JZLANG('批量绑定栏目')}</option>
			   {foreach $classtypetree as $v}
			   {if($molds['biaoshi']==$v['molds'])}
			   <option   value="{$v['id']}">{fun str_repeat('--', $v['level'])}{$v['classname']}</option>
			   {/if}
			   {/foreach}
			   </select>
			   </div>
			   {if(checkAction('Fields/addFields'))}	
			   <a class="layui-btn layui-btn-sm" onclick="x_admin_show('{$molds['name']}-{fun JZLANG('新增字段')}','{fun U('Fields/addFields',array('molds'=>$molds['biaoshi']))}')">{fun JZLANG('新增字段')}</a>
			   {/if}
		    </form>	
			

		  </xblock>
		    <table id="fieldtable" lay-filter="fieldtable"></table>
			<input id="select_data" type="hidden" value="" />

			</div>
		</div>
          
        </div>
		<script type="text/html" id="adminbar">
			<input type="checkbox" name="isadmin" data-id="{{d.id}}" lay-filter="sw" {{#if(d.isadmin=='{fun JZLANG('显示')}'){ }}checked value="0" {{# }else{ }} value="1" {{# } }}  lay-skin="switch">
		</script>
		<script type="text/html" id="homebar">
			<input type="checkbox" name="isshow" data-id="{{d.id}}"  lay-filter="sw"  {{#if(d.isshow=='{fun JZLANG('显示')}'){ }}checked value="0" {{# }else{ }} value="1"{{# } }} value="1" lay-skin="switch">
		</script>
		<script type="text/html" id="ishome">
			<input type="checkbox" name="ishome" data-id="{{d.id}}"  lay-filter="sw"  {{#if(d.ishome=='{fun JZLANG('显示')}'){ }}checked value="0" {{# }else{ }} value="1"{{# } }} value="1" lay-skin="switch">
		</script>
		<script type="text/html" id="searchbar">
			<input type="checkbox" name="issearch" data-id="{{d.id}}" lay-filter="sw"  {{#if(d.issearch=='{fun JZLANG('显示')}'){ }}checked value="0" {{# }else{ }} value="1"{{# } }} value="1" lay-skin="switch">
		</script>
		<script type="text/html" id="listbar">
			<input type="checkbox" name="islist" data-id="{{d.id}}"  lay-filter="sw"  {{#if(d.islist=='{fun JZLANG('显示')}'){ }}checked value="0" {{# }else{ }} value="1"{{# } }} value="1" lay-skin="switch">
		</script>
		<script type="text/html" id="mustbar">
			<input type="checkbox" name="ismust" data-id="{{d.id}}"  lay-filter="sw"  {{#if(d.ismust=='{fun JZLANG('是')}'){ }}checked value="0" {{# }else{ }} value="1"{{# } }} value="1" lay-skin="switch">
		</script>
		<script type="text/html" id="extbar">
			<input type="checkbox" name="isext" data-id="{{d.id}}" lay-filter="sw"  {{#if(d.isext=='{fun JZLANG('是')}'){ }}checked value="0" {{# }else{ }} value="1"{{# } }} value="1" lay-skin="switch">
		</script>
		<script type="text/html" id="rightbar">
		 
		 {if(checkAction('Fields/editFields'))}	
			<a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="edit">{fun JZLANG('设置')}</a>
		 {/if}
		 {if(checkAction('Fields/deleteFields'))}	
			<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">{fun JZLANG('删除')}</a>
		 {/if}
		 
		</script>
       <script>
	   $(document).ready(function(){
			
	   
	   });
	   
	    layui.use(['laydate','element','table','form','laypage','layer'], function(){
                $ = layui.jquery;//jquery
             var  laydate = layui.laydate;//日期插件
             var  lement = layui.element;//面包导航
             var  layer = layui.layer;//弹出层
			 var  form = layui.form;
			 var  table = layui.table;
			
			
			  table.render({
				elem: '#fieldtable'
				,height: 500
				,url: '{fun U('fields/index')}?molds={$molds['biaoshi']}&ajax=1' //数据接口
				,page: false //开启分页
				,cols: [[ //表头
				  {type:'checkbox',fixed: 'left'}
				  ,{field: 'field', title: '{fun JZLANG('字段')}', width:150}
				  ,{field: 'orders', title: '{fun JZLANG('排序')}', width:80,edit:'text'}
				  ,{field: 'fieldname', title: '{fun JZLANG('名称')}',width:150,edit:'text'}
				  ,{field: 'isadmin', title: '{fun JZLANG('后台')}', toolbar: '#adminbar'}
				  ,{field: 'isshow', title: '{fun JZLANG('前台显示')}', toolbar: '#homebar'}
				  ,{field: 'ishome', title: '{fun JZLANG('前台表单')}', toolbar: '#ishome'}
				  ,{field: 'issearch', title: '{fun JZLANG('搜索')}', toolbar: '#searchbar'}
				  ,{field: 'islist', title: '{fun JZLANG('列表')}' , toolbar: '#listbar'}
				  ,{field: 'ismust', title: '{fun JZLANG('必填')}' , toolbar: '#mustbar'}
				  ,{field: 'isext', title: '{fun JZLANG('扩展')}' , toolbar: '#extbar'}
				  ,{field: 'fieldtypename', title: '{fun JZLANG('类型')}'}
				  ,{field: '', title: '{fun JZLANG('操作')}',width:200, toolbar: '#rightbar', fixed:'right'}
				]]
			  });
			  
			  table.on('tool(fieldtable)', function(obj){
					var data = obj.data; //获得当前行数据
					var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
					var tr = obj.tr; //获得当前行 tr 的DOM对象
					 
					switch(layEvent){
					  case 'edit':
						 x_admin_show('{fun JZLANG('设置')}',data.edit_url);
					  break;
	
					  break;
					  case 'delete':
							layer.confirm('{fun JZLANG('确认要删除吗？')}',function(index){
				
								$.post("{fun U('Fields/deleteFields')}",{id:data.id},function(r){
										var r = JSON.parse(r);
										if(r.code==0){
										 //发异步删除数据
											$(tr).remove();
											layer.msg(r.msg,{icon: 1,time:1000},function(){
												table.reload('fieldtable', {
												  url: '{fun U('fields/index')}?molds={$molds['biaoshi']}&ajax=1'
												  ,where: {} //设定异步数据接口的额外参数
												 
												});
											
											});
											
											
											
										}else{
											
											layer.msg(r.msg,{icon: 5,time:1000});
										}
								})
								
							
							   
							});
					  break;
					  
					 
					}
				});
			  
			  table.on('edit(fieldtable)', function(obj){ 
				  var id = obj.data.id;
				  var value = obj.value;
				  var field = obj.field;
				  $.post("{fun U('Fields/editFieldsValue')}",{'id':id,'value':value,'field':field},function(r){
						var r = JSON.parse(r);
						if(r.code==0){
							$("#select_data").val('');
							table.reload('fieldtable', {
							  url: '{fun U('Fields/index')}?molds={$molds['biaoshi']}&ajax=1'
							  ,where: {} //设定异步数据接口的额外参数
							 
							});
						}else{
							layer.msg(r.info,{icon: 5,time:1000});
						}
						
					});
				  
				  
				});
						
              form.on('select(change_tid)', function(data){
				var checkStatus = table.checkStatus('fieldtable'); 
				var datas = checkStatus.data;
				var ids = [];
				for(var i=0;i<datas.length;i++){
					ids.push(datas[i].id);
				}
				if(ids.length==0){
					alert('{fun JZLANG('请选择对象！')}');return false;
				}
				$.post("{fun U('changeTid')}",{data:ids.join(','),tid:data.value},function(r){
						if(r.code==0){
							layer.msg(r.msg,{icon: 1,time:1000},function(){
								location.reload();
							});
							
						}else{
							layer.msg(r.msg,{icon: 5,time:1000});
						}
				},'json')
		
				});

			  form.on('switch(sw)', function(data){
				console.log(data.value)
				var field = $(data.elem).attr('name');
				var id = $(data.elem).attr('data-id');
					$.post('{fun U('editFieldsValue')}',{id:id,field:field,value:data.value},function(res){
					console.log(res);
					
					},'json')
					return false;
			  });
		});
		 /*删除*/
            function molds_del(obj,id){
                layer.confirm('{fun JZLANG('确认要删除吗？删除的同时将删除对应的表内容！')}',function(index){
				
					$.get("{fun U('deleteFields')}?id="+id,{},function(s){
						
							var r = JSON.parse(s);
							if(r.code==0){
							 //发异步删除数据
								$(obj).parents("tr").remove();
								
								layer.msg(r.msg,{icon: 1,time:1000});
								window.location.reload();
								
							}else{
								
								layer.msg(r.msg,{icon: 5,time:1000});
							}
					})
					
				
                   
                });
            }
			
			$(document).ready(function(){
			$(".orderchange").bind('input propertychange',function(){
				if($(this).val()!=''){
					var orders = $(this).val();
					var id = $(this).attr('data-id');
					$.get("{fun U('changeOrders')}",{id:id,orders:orders},function(r){
							if(r.code==0){
								window.location.reload();
							}else{
								
								layer.msg(r.msg,{icon: 5,time:1000});
							}
					},'json')
					
				}
			
			})
		
		})	
			
			
       </script>
    </body>
</html>