datalist.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. <script type="text/html" id="barDemo">
  13. <div class="layui-btn-group"><a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="read">查看</a><a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a><a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a></div>
  14. </script>
  15. {/block}
  16. <!-- /主体 -->
  17. <!-- 脚本 -->
  18. {block name="script"}
  19. <script>
  20. const moduleInit = ['tool', 'treeGrid'];
  21. function gouguInit() {
  22. var treeGrid = layui.treeGrid,table = layui.table, tool = layui.tool;
  23. var pageTable = treeGrid.render({
  24. id:'treeTable'
  25. ,elem: '#treeTable'
  26. ,idField:'id'
  27. ,url:'/admin/goods_cate/datalist'
  28. ,cellMinWidth: 100
  29. ,treeId:'id'//树形id字段名称
  30. ,treeUpId:'pid'//树形父id字段名称
  31. ,treeShowName:'title'//以树形式显示的字段
  32. ,cols: [[
  33. {field:'id',width:80, title: 'ID号', align:'center'}
  34. ,{field: 'sort', title: '排序', align:'center', width:80}
  35. ,{field:'title',width:240, title: '分类名称'}
  36. ,{field:'pid', title: '父级ID',width:80, align:'center'}
  37. ,{field:'keywords', title: '关键词', width:200,}
  38. ,{field:'desc', title: '描述'}
  39. ,{width:160,title: '操作', align:'center',templet: function(d){
  40. 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>';
  41. return html;
  42. }
  43. }
  44. ]]
  45. ,page:false
  46. //,skin:'line'
  47. });
  48. //表头工具栏事件
  49. $('.add-menu').on('click', function(){
  50. tool.side("/admin/goods_cate/add");
  51. return;
  52. });
  53. //操作按钮
  54. treeGrid.on('tool(treeTable)',function (obj) {
  55. if (obj.event === 'add') {
  56. tool.side('/admin/goods_cate/add?pid='+obj.data.id);
  57. return;
  58. }
  59. if (obj.event === 'edit') {
  60. tool.side('/admin/goods_cate/edit?id='+obj.data.id);
  61. return;
  62. }
  63. if(obj.event === 'del'){
  64. layer.confirm('确定要删除吗?', {icon: 3, title:'提示'}, function(index){
  65. let callback = function (e) {
  66. layer.msg(e.msg);
  67. if (e.code == 0) {
  68. obj.del();
  69. }
  70. }
  71. tool.delete("/admin/goods_cate/del", { id: obj.data.id }, callback);
  72. layer.close(index);
  73. });
  74. }
  75. });
  76. }
  77. </script>
  78. {/block}
  79. <!-- /脚本 -->