index.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. {extend name="common/base"/}
  2. <!-- 主体 -->
  3. {block name="body"}
  4. <div class="p-3">
  5. <div class="gg-form-bar border-t border-x" style="padding-bottom:10px;">
  6. <button class="layui-btn layui-btn-sm add-menu">+ 添加部门</button>
  7. </div>
  8. <div>
  9. <table class="layui-hide" id="treeTable" lay-filter="treeTable"></table>
  10. </div>
  11. </div>
  12. {/block}
  13. <!-- /主体 -->
  14. <!-- 脚本 -->
  15. {block name="script"}
  16. <script>
  17. const moduleInit = ['tool', 'treeGrid'];
  18. function gouguInit() {
  19. var treeGrid = layui.treeGrid,table = layui.table, tool = layui.tool;
  20. var allcount;
  21. var pageTable = treeGrid.render({
  22. id: 'treeTable'
  23. , elem: '#treeTable'
  24. , idField: 'id'
  25. , url: "/admin/department/index"
  26. , cellMinWidth: 80
  27. , treeId: 'id'//树形id字段名称
  28. , treeUpId: 'pid'//树形父id字段名称
  29. , treeShowName: 'title'//以树形式显示的字段
  30. , height: 'full-0'
  31. ,isOpenDefault:true
  32. ,parseData: function(res) { // 数据解析回调函数
  33. // 在这里可以获取数据总数
  34. allcount = res.data.length;
  35. console.log(res.data.length)
  36. return {
  37. code: res.code, // 数据状态码
  38. msg: res.msg, // 状态信息
  39. count: res.count, // 数据总数
  40. data: res.data // 当前页数据
  41. };
  42. },
  43. cols: [[
  44. {fixed: 'left', field: 'id', title: '编号', align: 'center', width: 80,
  45. templet: function(d){
  46. console.log(d)
  47. return allcount - (d.LAY_INDEX-1);
  48. }
  49. }, { field: 'pid', title: '上级部门ID',width: 120, align: 'center'}
  50. , { field: 'title', title: '部门名称'}
  51. , { field: 'leader', title: '部门负责人',width: 120, align: 'center'}
  52. , { field: 'phone', title: '部门电话',width: 160,}
  53. , { width:180, title: '操作', align: 'center', templet: function (d) {
  54. var html = '<span class="layui-btn-group"><button class="layui-btn layui-btn-xs" lay-event="add">添加下级部门</button><button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</button><button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button></span>';
  55. return html;
  56. }
  57. }
  58. ]]
  59. , page: false
  60. });
  61. //表头工具栏事件
  62. $('body').on('click','.add-menu', function(){
  63. tool.side("/admin/department/add");
  64. return;
  65. });
  66. //操作按钮
  67. treeGrid.on('tool(treeTable)', function (obj) {
  68. if (obj.event === 'add') {
  69. tool.side("/admin/department/add?pid="+obj.data.id);
  70. return;
  71. }
  72. if (obj.event === 'edit') {
  73. tool.side("/admin/department/add?id="+obj.data.id);
  74. return;
  75. }
  76. if (obj.event === 'del') {
  77. layer.confirm('确定要删除吗?', {icon: 3, title:'提示'}, function(index){
  78. let callback = function (e) {
  79. layer.msg(e.msg);
  80. if (e.code == 0) {
  81. obj.del();
  82. }
  83. }
  84. tool.delete("/admin/department/delete", { id: obj.data.id }, callback);
  85. layer.close(index);
  86. });
  87. }
  88. });
  89. }
  90. </script>
  91. {/block}
  92. <!-- /脚本 -->