index.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 pageTable = treeGrid.render({
  21. id: 'treeTable',
  22. elem: '#treeTable',
  23. idField: 'id',
  24. url: "/admin/position/index",
  25. cellMinWidth: 80,
  26. treeId: 'd_id',//树形id字段名称
  27. treeUpId: 'did',//树形父id字段名称
  28. treeShowName: 'title',//以树形式显示的字段
  29. height: 'full-0',
  30. isOpenDefault: true,
  31. cols: [[
  32. {field: 'd_id', width: 100, title: 'ID号', align: 'center'},
  33. {field: 'did', title: '单位ID', width: 120, align: 'center'},
  34. // { field: 'd_title', title: '单位名称'},
  35. {field: 'title', title: '岗位名称'},
  36. {field: 'remark', title: '备注'},
  37. // { field: 'work_price', title: '岗位工时单价(元)',align:'center'},
  38. {
  39. width: 180, title: '操作', align: 'center', templet: function (d) {
  40. var html = '<span class="layui-btn-group">' +
  41. '<button class="layui-btn layui-btn-xs" lay-event="add">添加下级部门</button>' +
  42. '<button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</button>' +
  43. '<button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button>' +
  44. '</span>';
  45. return html;
  46. }
  47. }
  48. ]]
  49. , page: false
  50. });
  51. //表头工具栏事件
  52. $('body').on('click', '.add-menu', function () {
  53. tool.side("/admin/position/add");
  54. return;
  55. });
  56. //操作按钮
  57. treeGrid.on('tool(treeTable)', function (obj) {
  58. if (obj.event === 'add') {
  59. tool.side("/admin/position/add?pid=" + obj.data.id);
  60. return;
  61. }
  62. if (obj.event === 'edit') {
  63. tool.side("/admin/position/add?id=" + obj.data.id);
  64. return;
  65. }
  66. if (obj.event === 'del') {
  67. layer.confirm('确定要删除吗?', {icon: 3, title: '提示'}, function (index) {
  68. let callback = function (e) {
  69. layer.msg(e.msg);
  70. if (e.code == 0) {
  71. obj.del();
  72. }
  73. }
  74. tool.delete("/admin/position/delete", {id: obj.data.id}, callback);
  75. layer.close(index);
  76. });
  77. }
  78. });
  79. }
  80. </script>
  81. {/block}
  82. <!-- /脚本 -->