{include file="common/top"/}
<div class="body_top">
	<ul class="title">
    	<li class="active"><a href="{:url('index',array('pid'=>$info['pid']))}">{$info['typename']}管理</a></li>
    </ul>
</div>

<div class="body_content_list">

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

<script type="text/html" id="is_effect">
<span class="tq_table_bar">
	<input type="checkbox" name="is_effect" value="{{d.id}}" lay-skin="switch" lay-text="停用|启用" lay-filter="is_effect" {{ d.is_effect ==2 ? 'checked' : '' }}>
</span>
</script>

<script type="text/html" id="is_new">
<span class="tq_table_bar">
	<input type="checkbox" name="is_new" value="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="is_new" {{ d.is_new ==2 ? 'checked' : '' }}>
</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_pic">
<span class="tq_table_bar">
	{{#  if(d.pic != '' && d.pic !=null ){ }}
		<a class="layui-btn layui-btn-normal layui-btn-xs tq_img_look" data-file="{{d.pic}}">预览</a>
	{{#  } }}
</span>
</script>

<script type="text/html" id="tq_btn">
  	<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>
</script>
<table class="layui-hide" id="list" lay-filter="list"></table>

</div>

{include file="common/bottom"/}
<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:'{:url("Images/list_data",array("pid"=>$info["pid"]))}'
    ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
	,even: true
	,toolbar: '#tq_btn'
	,defaultToolbar: ['filter']
	,height: 'full-71'
	,cols: [[
      {field:'id', width:80, title: '编号', sort: true}
      ,{field:'id', width:222, title: '排序',templet:'#sort'}
      ,{field:'title', title: '标题'}
      ,{field:'pic', width:80, title: '图片', align:'center', templet:'#tq_pic'}
      ,{field:'url', title: '链接地址'}
      ,{field:'is_new', width:110, align:'center', title:'跳新窗口',templet:'#is_new', sort: true}
      ,{field:'is_effect', width:110, align:'center', title:'信息状态',templet:'#is_effect', sort: true}
      ,{field:'id', width:130,align:'center',toolbar:'#barDemo', title: '操作'}
    ]]
  });
  
  
//监听工具条
table.on('tool(list)', function(obj){
	var data = obj.data;
	//删除
	if(obj.event === 'del'){
		window.top.delete_c(obj,iname);
	}
		
	if(obj.event==='edit'){
		var title='修改{$info["typename"]}';
		var url="{:url('edit')}?id="+data.id+"&pid={$info.pid}";
		var area=["560px", "400px"];
		window.top.openiframe(title,url,area,iname);
	}
	
	if(obj.event==='sort_t'){
		is_sort('t',data['id'],'images',data['sort'],data['pid']);
	}
	if(obj.event==='sort_p'){
		is_sort('p',data['id'],'images',data['sort'],data['pid']);
	}
	if(obj.event==='sort_n'){
		is_sort('n',data['id'],'images',data['sort'],data['pid']);
	}	

});

//表头操作
table.on('toolbar(list)', function(obj){

	//添加
	if(obj.event==='add'){
		var title='添加{$info["typename"]}';
		var url="{:url('add',array('pid'=>$info['pid']))}";
		var area=["560px", "400px"];
		window.top.openiframe(title,url,area,iname);
	}	
	
	//input排序
	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:'images'},function(data){
			table.reload('list', { where: {} });
			console.log(data);
		});
	}
		
	if(obj.event==='tq_help'){
		alert(2);
	}	

});

//监听状态操作
form.on('switch(is_effect)', function(obj){
	var is_effect=obj.elem.checked==true?2:1;
	$.post('/admin/Common/is_edit',{id:this.value,is_effect:is_effect,dbname:'images'},function(data){ });
});

form.on('switch(is_new)', function(obj){
	var is_new=obj.elem.checked==true?2:1;

	console.log(this.value);
	$.post('/admin/Common/is_edit',{id:this.value,is_new:is_new,dbname:'images'},function(data){ });
});

  
});
//layui end;

//删除-父级返回
function delete_id(info){
	//info.del();
	$.post('/admin/Common/delete_id',{id:info.data.id,table:'cate'},function(data){ 
		if(data.ok==2){
			window.top.tq_alert(data.msg,'',4);
		}else{
			info.del();
		}
	});
}

//排序
function is_sort(type,id,dbname,sort,pid){
	$.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: {} });
			});
		}
	});
}
</script>