123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- 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,
- 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 '<input type="checkbox" value="'+d.id+'" name="'+d.is_show+'" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
- } else {
- return '<input type="checkbox" checked value="'+d.id+'" name="'+d.is_show+'" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
- }
- }}
- ,{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 += '<option value="' + areaData[i].id +'">' + areaData[i].name + '</option>';
- }
- //初始化省数据
- $('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 = '<option value="">请选择子栏目</option>';
- if(data.code == 200){
- var areaData = data.data;
- for (var i = 0; i < areaData.length; i++) {
- proHtml += '<option value="' + areaData[i].id +'">' + areaData[i].name + '</option>';
- }
- //初始化省数据
- $('select[name=city]').append(proHtml);
- }
- form.render();
- })
- })
- });
|