list.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. <div class="layui-btn-group">
  5. <button class="layui-btn" id="add_api">增加</button>
  6. </div>
  7. </div>
  8. <div class="layui-col-xs6 search_text">
  9. <form class="layui-form" action="" onsubmit="javascript:return false;">
  10. <div class="demoTable">
  11. <div class="layui-inline" style="width: 40%">
  12. <input class="layui-input" name="TemplateName" id="TemplateName" autocomplete="off" placeholder="文档名称" >
  13. </div>
  14. <button class="layui-btn" data-type="reload" id="reload">查询</button>
  15. </div>
  16. </form>
  17. </div>
  18. </div>
  19. <table class="layui-hide" id="table_list" lay-filter="table_filter">
  20. </table>
  21. <script type="text/html" id="bar">
  22. <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  23. <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
  24. </script>
  25. </div>
  26. <script>
  27. layui.use(['table','form','element'], function(){
  28. var table = layui.table;
  29. var form = layui.form;
  30. var element = layui.element;
  31. //方法级渲染
  32. table.render({
  33. elem: '#table_list'
  34. ,url: '/template/table'
  35. ,cols: [[
  36. // {checkbox: true, fixed: true},
  37. {field:'id', title: 'ID', align:'center',sort: true, width:50}
  38. ,{field:'template_name',title: '模板名称'}
  39. ,{field:'create_time', title: '创建时间'}
  40. ,{field:'update_time', title: '修改时间'}
  41. ,{fixed: 'right', width:160, align:'center', toolbar: '#bar'}
  42. ]]
  43. ,id: 'listReload'
  44. ,page: true
  45. ,height: "full-130"
  46. });
  47. var $ = layui.$, active = {
  48. reload: function(){
  49. table.reload('listReload', {
  50. where: {
  51. TemplateName: $('#TemplateName').val()
  52. }
  53. });
  54. }
  55. };
  56. $("#add_api").on("click",function() {
  57. window.location.href="/template/add"
  58. })
  59. //监听工具条
  60. table.on('tool(table_filter)', function(obj){
  61. var data = obj.data;
  62. if(obj.event === 'edit'){
  63. window.location.href="/template/edit?id="+data.id
  64. } else if(obj.event === 'del'){
  65. var msg = "确定要删除"+data.template_name+"吗?";
  66. layer.confirm(msg, function(){
  67. var del_data = {"id":data.id}
  68. $.post('{{urlfor "TemplateController.AjaxDel"}}', del_data, function (out) {
  69. if (out.status == 0) {
  70. layer.msg("操作成功",{icon: 1},function () {
  71. $("#reload").click();
  72. })
  73. } else {
  74. layer.msg(out.message)
  75. }
  76. }, "json");
  77. return false;
  78. });
  79. return false;
  80. }else{
  81. layer.msg('操作不存在');
  82. }
  83. });
  84. $('.demoTable .layui-btn').on('click', function(){
  85. var type = $(this).data('type');
  86. active[type] ? active[type].call(this) : '';
  87. });
  88. });
  89. </script>