layui.use([ 'laypage', 'layer', 'table', 'element','form','treetable'], function(){ var laypage = layui.laypage //分页 ,$ = layui.jquery ,layer = layui.layer //弹层 ,table = layui.table //表格 ,form = layui.form ,treetable = layui.treetable; if($('#menulist').attr('lay-filter') == 'menulist'){ var renderTable = function (wheres = {}) { treetable.render({ treeColIndex: 1, treeSpid:0, treeIdName: 'id', treePidName: 'pid', treeDefaultClose: true, treeLinkage: false, elem: '#menulist', url: '/dictionarynews/labelform', page: false, height:600, where:wheres, id:'tablerReload', cols: [[ {type:'numbers'} // {field: 'id', title: 'ID', width:80, sort: true,align:'center'} ,{field: 'name', title: '栏目名称',align:'center'}, {field: 'sort', title: '排序',width:80, edit: 'text',align:'center',sort: true,templet:"#sortBox"}, // ,{field: 'sort', title: '排序',align:'center',sort: true}, {field: 'is_show', title: '审核',width:100, align:'center', templet:"#Toexamine",templet:function(d){ if(d.is_show == 2){ return '' } else { return '' } }} ,{field: 'create_at', title: '添加时间', width:200,align:'center'} ,{fixed: 'right',title:'操作', width: 165, align:'center', toolbar: '#operate'} ]], done: function () { layer.closeAll('loading'); } }); }; renderTable(); } //列表操作 table.on('tool(menulist)', function(obj){ var layEvent = obj.event, data = obj.data; if(layEvent === 'edit'){ layer.open({ type: 2, title: '编辑', closeBtn: 1, //不显示关闭按钮 shade: [0], area: ['600px', '500px'], anim: 2, content: '/dictionarynews/editlabel?id='+data.id, //iframe的url,no代表不显示滚动条 end:function () { renderTable(); } }); } else if(layEvent === 'del') { layer.confirm('您确定要删除吗?',{btn:['确认','取消']},function(){ $.post('/dictionarynews/editlabelform',{data:{id:data.id,del:2}},function (data) { if(data.data != null){ layer.msg(ReturnInfo(data.data),{icon:5}); return false; } layer.msg(data.msg); renderTable(); }) }) } }); var $ = layui.$, active = { addDatas: function(){ //获取选中数据 layer.open({ type: 2, title: '新增栏目', closeBtn: 1, //不显示关闭按钮 shade: [0], area: ['600px', '500px'], anim: 2, content: '/dictionarynews/labelcreate', end: function(){ renderTable(); } }); }, reload:function () { var form = pfgs_serialize($('form')); var city = ''; if(form.province != ''){ city = form.province; } if(form.city != ''){ city = form.city; } renderTable({id:city}); } }; $('.demoTable .layui-btn').on('click', function(){ var type = $(this).data('type'); active[type] ? active[type].call(this) : ''; }); //修改排序 table.on('edit(menulist)', function(obj){ var data = obj.data; $.post('/dictionarynews/editlabelform',{data:{id:data.id,sort:data.sort}},function (data) { if(data.data != null){ layer.msg(ReturnInfo(data.data),{icon:5}); return false; } layer.msg(data.msg); renderTable(); }) }) //显示或隐藏 form.on('switch(switchTest)', function(data){ var state = ''; if(data.elem.name == 1){ state = 2; }else if(data.elem.name == 2){ state = 1; } layer.confirm('确定要修改此操作吗?',{btn: ['确定', '取消']},function () { $.post('/dictionarynews/editlabelform',{data:{id:data.value,is_show:state}},function (data) { if(data.data != null){ layer.msg(ReturnInfo(data.data),{icon:5}); return false; } layer.msg(data.msg); renderTable(); }) },function (aa) { renderTable(); }) }); //修改 form.on('submit(editlabel)', function(data){ $.post('/dictionarynews/editlabelform',{'data':data.field},function (data) { layer.msg(data.msg); }) return false; }); //添加 form.on('submit(addlabel)', function(data){ $.post('/dictionarynews/labelcreateform',{'data':data.field},function (data) { if(data.data != null){ layer.msg(ReturnInfo(data.data),{icon:5}); return ; } layer.msg(data.msg); }) return false; }); //加载省数据 function loadProvince() { $.ajax({ url : '/dictionarynews/pidlist', type : 'post', async: false,//使用同步的方式,true为异步方式 data : {'pid':0},//这里使用json对象 success : function(data){ var areaData = data.data; var proHtml = ''; for (var i = 0; i < areaData.length; i++) { proHtml += ''; } //初始化省数据 $('select[name=province]').append(proHtml); form.render(); }, fail:function(){ } }); } loadProvince(); form.on('select(province)',function (data) { $.post('/dictionarynews/pidlist',{'pid':data.value},function (data) { $('select[name=city]').html(''); var proHtml = ''; if(data.code == 200){ var areaData = data.data; for (var i = 0; i < areaData.length; i++) { proHtml += ''; } //初始化省数据 $('select[name=city]').append(proHtml); } form.render(); }) }) });