<?php /*a:3:{s:66:"/www/wwwroot/btn.millet-mirth.com/view/admin/tablefield/index.html";i:1665541670;s:60:"/www/wwwroot/btn.millet-mirth.com/view/admin/common/top.html";i:1625466448;s:63:"/www/wwwroot/btn.millet-mirth.com/view/admin/common/bottom.html";i:1629163316;}*/ ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<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, maximum-scale=1">
<title><?php echo config('common.CMS_NAME'); ?></title>
<link rel="stylesheet" href="/static/tqcms/css/common.css">
<link rel="stylesheet" href="/static/tqcms/layui/css/layui.css"><!--layui css-->
<link rel="stylesheet" href="/static/tqcms/css/skin.css">
<script src="/static/tqcms/js/jquery.js"></script>
</head>
<body>
<div class="body_top">
	<ul class="title">
    	<li class="active"><a href="<?php echo url('index'); ?>">扩展字段管理</a></li>
    </ul>
</div>

<div class="table_select_box layui-form">
    <select id="table_name" lay-filter="table_field_add">
		 <?php if(is_array($table_list) || $table_list instanceof \think\Collection || $table_list instanceof \think\Paginator): $i = 0; $__LIST__ = $table_list;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$v): $mod = ($i % 2 );++$i;?>
		 <option value="<?php echo htmlentities($v['table']); ?>" data-pid="<?php echo htmlentities($v['pid']); ?>"><?php echo htmlentities($v['name']); ?></option>
		 <?php endforeach; endif; else: echo "" ;endif; ?>
	</select>
</div>

<div class="body_content_list">

<script type="text/html" id="barDemo">
<span class="tq_table_bar">
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</span>
</script>

<script type="text/html" id="sort">
<span class="tq_table_bar">
	<a class="layui-btn layui-btn-xs tq_sort"><input type="text" name="{{d.id}}" autocomplete="off" value="{{d.sort}}"></a>
  	<a class="layui-btn layui-btn-xs" lay-event="sort_t">置顶</a>
  	<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="sort_p">上移</a>
  	<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="sort_n">下移</a>
</span>
</script>

<script type="text/html" id="tq_btn">
<span class="table_field_p">
  	<a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="add">添加</a>
  	<a class="layui-btn layui-btn-sm" lay-event="sort_all">排序</a>
</span>
</script>

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

</div>


<script src="/static/tqcms/layui/layui.js"></script><!--layui js-->
<script src="/static/tqcms/layui/laytq.js"></script><!--layui js-->
<script src="/static/tqcms/js/common.js"></script>
<script src="/static/tqcms/js/md5.js"></script>
<script src="/static/tqcms/js/url.js"></script>
</body>
</html>
<input name="" id="add_type" type="hidden" value="0" />
<script>
iname=self.frameElement.name;
layui.use('table', function(){
  var table = layui.table,form = layui.form;
  var mpage=1;

  table.render({
    elem: '#list'
	,title:'管理员列表信息'
    ,url:'<?php echo url("admin/Tablefield/list_data"); ?>'
    ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
	,even: true
	,toolbar: '#tq_btn'
	,defaultToolbar: ['filter']
	,height: 'full-70'
	,where: {table:"<?php echo htmlentities($table_list[0]['table']); ?>"}
	,cols: [[
      {field:'id', width:80, title: '编号', sort: true}
      ,{field:'id', width:222, title: '排序',templet:'#sort'}
      ,{field:'field_cn_name', title: '字段中文名称'}
      ,{field:'field_name', title: '字段名称'}
      ,{field:'field_mk', title: '字段模块'}
      ,{field:'field_type', title: '字段类型'}
      ,{field:'field_num', title: '字段长度'}
      ,{field:'id', width:130,align:'center',toolbar:'#barDemo', title: '操作'}
    ]]
  });
  
//table列表内工具条操作
table.on('tool(list)', function(obj){
	var data = obj.data;
	if(obj.event==='del'){
		window.top.delete_c(obj,iname);
	}

	if(obj.event==='sort_t'){
		is_sort('t',data['id'],'table_field',data['sort'],data['pid']);
	}
	if(obj.event==='sort_p'){
		is_sort('p',data['id'],'table_field',data['sort'],data['pid']);
	}
	if(obj.event==='sort_n'){
		is_sort('n',data['id'],'table_field',data['sort'],data['pid']);
	}
});

//表头按钮操作
table.on('toolbar(list)', function(obj){
    var table_name= $("#table_name option:selected").val();
    var pid= $("#table_name option:selected").attr('data-pid');
	var text=$("#table_name option:selected").text();
	//添加
	if(obj.event==='add'){
		var title='添加-'+text+'字段';
		var url="<?php echo url('tablefield/add'); ?>?table_name="+table_name+"&pid="+pid+"";
		var area=["500px", "455px"];
		window.top.openiframe(title,url,area,iname,table_name);
	}	

	if(obj.event==='sort_all'){
		var idArray = new Array();
		var sortArray = new Array();
		$('.tq_sort input').each(function(){
            idArray.push($(this).attr('name'));
            sortArray.push($(this).val());
		});
		$.post('/admin/Common/sort_all',{id:idArray,sort:sortArray,dbname:'table_field'},function(data){
			table.reload('list', { where: { table:table_name } });
		});
	}
		
});

form.on('select(table_field_add)', function(data){
	var table_name=$(data.elem).find("option:selected").val();
	table.reload('list', { where:{ table:table_name } },true);
});

});


//删除
function delete_id(info){
	$.post('/admin/Tablefield/is_delete',{id:info.data.id,pid:info.data.pid,name:info.data.field_name},function(data){ console.log(data); info.del(); });
}

//排序
function is_sort(type,id,dbname,sort,pid){
    var table_name= $("#table_name option:selected").val();
	$.post('/admin/Common/is_sort',{type:type,id:id,dbname:dbname,sort:sort,pid:pid},function(data){
		if(data['type']==1){
			layui.use('table', function(){
				var table = layui.table;
				table.reload('list', { where: { table:table_name } });
			});
		}
	});
}
</script>