layui.use(['layer', 'table','form'], function(){
var layer = layui.layer //弹层
,table = layui.table //表格
,form = layui.form;
//第一个实例
table.render({
elem: '#frontmenulist'
,url: '/menu/fronthomeform' //数据接口
,where:{token:csrfToken}
,method:'post'
,id:'tablerReload'
,page: true //开启分页
,text:'数据加载中'
,cols: [[ //表头
{type:'numbers',title:'序号'}
,{field: 'name', title: '菜单名称', align:'center'}
,{field: 'url', title: '地址', width:300,align:'center'}
,{field: 'sort', title: '排序', width:100,align:'center'}
,{field: 'status', title: '状态', width:80,align:'center',templet:function (d) {
if(d.status === '2'){
return ''
} else {
return ''
}
}}
,{fixed: 'right',title:'操作', width: 165, align:'center', toolbar: '#operate'}
]]
});
//列表操作
table.on('tool(frontmenulist)', 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:'/menu/frontedit?id='+data.id,
end:function(){
table.reload('tablerReload'); //重新加载
}
});
} else if(layEvent === 'del') {
layer.confirm('确定要删除该菜单吗?',{btn: ['确定', '取消']},function () {
$.post('/menu/frontstateform',{id:data.id,type:1},function (data) {
if(data.code == 200)
{
layer.msg(data.msg);
table.reload('tablerReload');
} else if(data.code == 300 ) {
layer.msg(data.msg);
}
})
})
}
});
//监听指定开关
form.on('switch(switchTest)', function(data){
layer.confirm('确定要修改此操作吗?',{btn: ['确定', '取消']},function () {
$.post('/menu/frontstateform',{id:data.value,type:2},function (data) {
if(data.code == 200)
{
layer.msg(data.msg);
table.reload('tablerReload');
} else if(data.code == 300 ) {
layer.msg(data.msg);
}
})
},function (aa) {
table.reload('tablerReload'); //重新加载
})
});
var $ = layui.$, active = {
addData: function(){ //获取选中数据
layer.open({
type: 2,
title: '添加前台菜单',
closeBtn: 1, //不显示关闭按钮
shade: [0],
area: ['600px', '500px'],
anim: 2,
content: '/menu/frontadd',
end: function(){ //此处用于演示
table.reload('tablerReload'); //重新加载
}
});
}
};
$('.demoTable .layui-btn').on('click', function(){
var type = $(this).data('type');
active[type] ? active[type].call(this) : '';
});
form.on('submit(editmenu)', function(data){
$.post('/menu/fronteditform',{'data':data.field},function (data) {
if(data.data != null){
layer.msg(ReturnInfo(data.data),{icon:5});
return ;
}
layer.msg(data.msg)
})
return false;
});
form.on('submit(addmenu)', function(data){
$.post('/menu/frontaddform',{'data':data.field},function (data) {
if(data.data != null){
layer.msg(ReturnInfo(data.data),{icon:5});
return ;
}
layer.msg(data.msg)
})
return false;
});
});