list.html 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <div class="layui-layout layui-layout-admin" style="padding-left: 20px;">
  2. <div class="layui-row" style="margin-top: 20px;">
  3. <div class="layui-col-xs6">
  4. <a class="layui-btn" data-type="tabAdd" href="/group/add">新增</a>
  5. </div>
  6. <div class="layui-col-xs6 search_text">
  7. <form class="layui-form" action="" onsubmit="javascript:return false;">
  8. <div class="demoTable">
  9. <div class="layui-inline" style="width: 40%">
  10. <input class="layui-input" name="groupName" id="groupName" autocomplete="off" placeholder="分组名称" >
  11. </div>
  12. <button class="layui-btn" data-type="reload">查询</button>
  13. </div>
  14. </form>
  15. </div>
  16. </div>
  17. <table class="layui-hide" id="table_list" lay-filter="table_filter">
  18. </table>
  19. <script type="text/html" id="bar">
  20. <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  21. <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
  22. </script>
  23. </div>
  24. <script>
  25. layui.use(['table','form','element'], function(){
  26. var table = layui.table;
  27. var form = layui.form;
  28. var element = layui.element;
  29. //方法级渲染
  30. table.render({
  31. elem: '#table_list'
  32. ,url: '/group/table'
  33. ,cols: [[
  34. // {checkbox: true, fixed: true},
  35. {field:'id', title: 'ID', align:'center',sort: true, width:150}
  36. ,{field:'group_name',title: '分组名称'}
  37. ,{field:'detail', title: '分组说明'}
  38. ,{field:'create_time', title: '创建时间'}
  39. ,{field:'update_time', title: '修改时间'}
  40. ,{fixed: 'right', width:160, align:'center', toolbar: '#bar'}
  41. ]]
  42. ,id: 'listReload'
  43. ,page: true
  44. ,height: "full-130"
  45. });
  46. var $ = layui.$, active = {
  47. reload: function(){
  48. table.reload('listReload', {
  49. where: {
  50. groupName: $('#groupName').val(),
  51. }
  52. });
  53. }
  54. };
  55. //监听工具条
  56. table.on('tool(table_filter)', function(obj){
  57. var data = obj.data;
  58. if(obj.event === 'detail'){
  59. //layer.msg('ID:'+ data.id + ' 的查看操作');
  60. } else if(obj.event === 'del'){
  61. layer.confirm('真的删除【'+data.group_name+'】分组么', function(index){
  62. var jsData = {'id':data.id}
  63. $.post('{{urlfor "GroupController.AjaxDel"}}', jsData, function (out) {
  64. if (out.status == 0) {
  65. layer.alert('删除成功了', {icon: 1},function(index){
  66. layer.close(index);
  67. window.location.reload();
  68. });
  69. } else {
  70. layer.msg(out.message)
  71. }
  72. }, "json");
  73. obj.del();
  74. layer.close(index);
  75. });
  76. } else if(obj.event === 'edit'){
  77. window.location.href="/group/edit?id="+data.id
  78. }
  79. });
  80. $('.demoTable .layui-btn').on('click', function(){
  81. var type = $(this).data('type');
  82. active[type] ? active[type].call(this) : '';
  83. });
  84. });
  85. </script>