2022-02-11 13:23:31 +08:00
{extend name="../../base/view/common/base" /}
2021-11-15 23:51:08 +08:00
<!-- 主体 -->
{block name="body"}
2022-06-08 15:13:48 +08:00
< div class = "p-3" >
< div class = "gg-form-bar border-t border-x" >
2021-11-23 18:04:44 +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 >
{/block}
<!-- /主体 -->
<!-- 脚本 -->
{block name="script"}
< script >
2022-06-08 15:13:48 +08:00
const moduleInit = ['tool', 'treeGrid'];
function gouguInit() {
var treeGrid = layui.treeGrid,table = layui.table, tool = layui.tool;
2022-06-18 08:52:28 +08:00
var pageTable = treeGrid.render({
2021-11-15 23:51:08 +08:00
id: 'treeTable'
, elem: '#treeTable'
, idField: 'id'
2022-02-11 13:23:31 +08:00
, url: "/user/department/index"
, cellMinWidth: 80
2021-11-15 23:51:08 +08:00
, treeId: 'id'//树形id字段名称
, treeUpId: 'pid'//树形父id字段名称
, treeShowName: 'title'//以树形式显示的字段
, height: 'full-0'
,isOpenDefault:true
, cols: [[
{ field: 'id', width: 100, title: 'ID号', align: 'center' }
, { field: 'pid', title: '上级部门ID',width: 120, align: 'center'}
, { field: 'title', title: '部门名称'}
2021-11-16 14:57:25 +08:00
, { field: 'leader', title: '部门负责人',width: 120, align: 'center'}
, { field: 'phone', title: '部门电话',width: 160,}
2021-11-29 16:47:24 +08:00
, { width:180, title: '操作', align: 'center', templet: function (d) {
2021-11-23 18:04:44 +08:00
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 > ';
2021-11-15 23:51:08 +08:00
return html;
}
}
]]
, page: false
});
2021-11-23 18:04:44 +08:00
//表头工具栏事件
2022-06-08 15:13:48 +08:00
$('body').on('click','.add-menu', function(){
tool.side("/user/department/add");
2021-11-23 18:04:44 +08:00
return;
});
//操作按钮
2021-11-15 23:51:08 +08:00
treeGrid.on('tool(treeTable)', function (obj) {
2021-11-23 18:04:44 +08:00
if (obj.event === 'add') {
2022-06-08 15:13:48 +08:00
tool.side("/user/department/add?pid="+obj.data.id);
2021-11-23 18:04:44 +08:00
return;
}
if (obj.event === 'edit') {
2022-06-08 15:13:48 +08:00
tool.side("/user/department/add?id="+obj.data.id);
2021-11-23 18:04:44 +08:00
return;
}
2021-11-15 23:51:08 +08:00
if (obj.event === 'del') {
2022-06-08 15:13:48 +08:00
layer.confirm('确定要删除吗?', {icon: 3, title:'提示'}, function(index){
let callback = function (e) {
layer.msg(e.msg);
if (e.code == 0) {
obj.del();
2021-11-15 23:51:08 +08:00
}
2022-06-08 15:13:48 +08:00
}
tool.delete("/user/department/delete", { id: obj.data.id }, callback);
2021-11-15 23:51:08 +08:00
layer.close(index);
});
}
});
}
< / script >
{/block}
<!-- /脚本 -->