datalist.html 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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/article_cate/datalist'
  25. ,cellMinWidth: 300
  26. ,treeId:'id'//树形id字段名称
  27. ,treeUpId:'pid'//树形父id字段名称
  28. ,treeShowName:'title'//以树形式显示的字段
  29. ,page:false
  30. ,cols: [[
  31. {field:'id',width:80, title: 'ID号', align:'center'}
  32. ,{field: 'sort', title: '排序', align:'center', width:80}
  33. ,{field:'title',width:240, title: '分类名称'}
  34. ,{field:'pid', title: '父级ID',width:80, align:'center'}
  35. ,{field:'keywords', title: '关键词', width:200,}
  36. ,{field:'desc', title: '描述'}
  37. ,{width:160,title: '操作', align:'center',templet: function(d){
  38. var html = '<span class="layui-btn-group"><span class="layui-btn layui-btn-normal layui-btn-xs" lay-event="add">添加子分类</span><span class="layui-btn layui-btn-xs" lay-event="edit">编辑</span><span class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</span></span>';
  39. return html;
  40. }
  41. }
  42. ]]
  43. });
  44. //表头工具栏事件
  45. $('.add-menu').on('click', function(){
  46. tool.side("/admin/article_cate/add");
  47. return;
  48. });
  49. //操作按钮
  50. treeGrid.on('tool(treeTable)',function (obj) {
  51. if (obj.event === 'add') {
  52. tool.side("/admin/article_cate/add?pid="+obj.data.id);
  53. return;
  54. }
  55. if (obj.event === 'edit') {
  56. tool.side("/admin/article_cate/edit?id="+obj.data.id);
  57. return;
  58. }
  59. if(obj.event === 'del'){
  60. layer.confirm('确定要删除吗?', {icon: 3, title:'提示'}, function(index){
  61. let callback = function (e) {
  62. layer.msg(e.msg);
  63. if (e.code == 0) {
  64. obj.del();
  65. }
  66. }
  67. tool.delete("/admin/article_cate/del", { id: obj.data.id}, callback);
  68. layer.close(index);
  69. });
  70. }
  71. });
  72. }
  73. </script>
  74. {/block}
  75. <!-- /脚本 -->