2021-11-15 23:51:08 +08:00
{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}
2021-11-29 16:04:07 +08:00
< div class = "body-table" style = "margin-bottom:0" >
< div class = "layui-form-bar" >
2021-11-23 23:09:15 +08:00
< button class = "layui-btn layui-btn-normal layui-btn-sm add-menu" > + 添加分类< / button >
2021-11-15 23:51:08 +08:00
< / div >
2021-11-29 16:04:07 +08:00
< div >
2021-11-15 23:51:08 +08:00
< table class = "layui-hide" id = "treeTable" lay-filter = "treeTable" > < / table >
< / div >
< / div >
< script type = "text/html" id = "switchStatus" >
< input type = "checkbox" name = "status" value = "{{d.id}}" lay-skin = "switch" lay-text = "是|否" lay-filter = "status" { { d . status = = 1 ? ' checked ' : ' ' } } >
< / script >
{/block}
<!-- /主体 -->
<!-- 脚本 -->
{block name="script"}
2021-11-23 23:09:15 +08:00
< script >
function init(layui) {
var treeGrid = layui.treeGrid,
layer = layui.layer,
rightpage = layui.rightpage,
ptable = treeGrid.render({
id:'treeTable'
,elem: '#treeTable'
,idField:'id'
2021-12-05 00:23:33 +08:00
,url: "/home/note/cate"
2021-11-23 23:09:15 +08:00
,cellMinWidth: 100
,treeId:'id'//树形id字段名称
,treeUpId:'pid'//树形父id字段名称
,treeShowName:'title'//以树形式显示的字段
,isOpenDefault:true
,cols: [[
{field:'id',width:80, title: 'ID号', align:'center'}
,{field: 'sort', title: '排序', align:'center', style:'cursor: pointer;', width:80}
,{field:'title', title: '分类名称'}
,{field:'pid', title: '父级ID', width:80, align:'center'}
,{width:160,title: '操作', align:'center',templet: function(d){
var html = '< span class = "layui-btn-group" > < button class = "layui-btn layui-btn-normal layui-btn-xs" lay-event = "add" > 添加子分类< / button > < button class = "layui-btn layui-btn-xs" lay-event = "edit" > 编辑< / button > < button class = "layui-btn layui-btn-danger layui-btn-xs" lay-event = "del" > 删除< / button > < / span > ';
return html;
}
}
]]
,page:false
//,skin:'line'
});
//表头工具栏事件
2021-11-29 16:04:07 +08:00
$('.add-menu').on('click', function(){
2021-12-05 00:23:33 +08:00
rightpage.open("/home/note/cate_add");
2021-11-23 23:09:15 +08:00
return;
});
//操作按钮
treeGrid.on('tool(treeTable)', function (obj) {
if (obj.event === 'add') {
rightpage.open('/home/note/cate_add?pid='+obj.data.id);
return;
}
if (obj.event === 'edit') {
rightpage.open('/home/note/cate_add?id='+obj.data.id);
return;
}
if (obj.event === 'del') {
layer.confirm('确定要删除吗?', { icon: 3, title: '提示' }, function (index) {
2021-11-15 23:51:08 +08:00
$.ajax({
2021-12-05 00:23:33 +08:00
url: "/home/note/cate_delete",
2021-11-23 23:09:15 +08:00
type: 'post',
data: { id: obj.data.id },
success: function (e) {
layer.msg(e.msg);
if (e.code == 0) {
obj.del();
}
2021-11-15 23:51:08 +08:00
}
2021-11-23 23:09:15 +08:00
})
2021-11-15 23:51:08 +08:00
layer.close(index);
});
2021-11-23 23:09:15 +08:00
}
});
}
< / script >
{include file="common/layui" base='base' extend="['treeGrid','rightpage']" callback="init" /}
2021-11-15 23:51:08 +08:00
{/block}
<!-- /脚本 -->