datalist.html 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. <table class="layui-hide" id="gallery_cate" lay-filter="gallery_cate"></table>
  9. </div>
  10. {/block}
  11. <!-- /主体 -->
  12. <!-- 脚本 -->
  13. {block name="script"}
  14. <script>
  15. const moduleInit = ['tool', 'treeGrid'];
  16. function gouguInit() {
  17. var treeGrid = layui.treeGrid,table = layui.table, tool = layui.tool;
  18. var pageTable = treeGrid.render({
  19. id:'gallery_cate'
  20. ,elem: '#gallery_cate'
  21. ,idField:'id'
  22. ,url:'/admin/gallery_cate/datalist'
  23. ,cellMinWidth: 300
  24. ,treeId:'id'//树形id字段名称
  25. ,treeUpId:'pid'//树形父id字段名称
  26. ,treeShowName:'title'//以树形式显示的字段
  27. ,page:false
  28. ,cols: [
  29. [
  30. {
  31. fixed: 'left',
  32. field: 'id',
  33. title: '编号',
  34. align: 'center',
  35. width: 80
  36. },{
  37. field: 'sort',
  38. title: '排序',
  39. align: 'center',
  40. width: 100
  41. },{
  42. field: 'title',
  43. title: '分类名称',
  44. width: 200
  45. },{
  46. field: 'pid',
  47. title: '父级ID',
  48. align: 'center',
  49. width: 100
  50. },{
  51. field: 'keywords',
  52. title: '关键字',
  53. width: 200
  54. },{
  55. field: 'desc',
  56. title: '分类描述'
  57. },
  58. {width:160,title: '操作', align:'center',templet: function(d){
  59. 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>';
  60. return html;
  61. }
  62. }
  63. ]
  64. ]
  65. });
  66. //监听表头工具栏事件
  67. $('.add-menu').on('click', function(){
  68. tool.side("/admin/gallery_cate/add");
  69. return false;
  70. });
  71. //监听表格行工具事件
  72. treeGrid.on('tool(gallery_cate)', function(obj) {
  73. var data = obj.data;
  74. if (obj.event === 'add') {
  75. tool.side('/admin/gallery_cate/add?pid='+obj.data.id);
  76. }
  77. else if (obj.event === 'edit') {
  78. tool.side('/admin/gallery_cate/edit?id='+obj.data.id);
  79. }
  80. else if (obj.event === 'del') {
  81. layer.confirm('确定要删除该记录吗?', {
  82. icon: 3,
  83. title: '提示'
  84. }, function(index) {
  85. let callback = function (e) {
  86. layer.msg(e.msg);
  87. if (e.code == 0) {
  88. obj.del();
  89. }
  90. }
  91. tool.delete("/admin/gallery_cate/del", { id: data.id }, callback);
  92. layer.close(index);
  93. });
  94. }
  95. return false;
  96. });
  97. }
  98. </script>
  99. {/block}
  100. <!-- /脚本 -->