list.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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="/admin/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="realName" id="realName" 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-primary layui-btn-xs" lay-event="detail">查看</a> -->
  21. <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  22. <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="status">启|禁</a>
  23. </script>
  24. </div>
  25. <script>
  26. layui.use(['table','form','element'], function(){
  27. var table = layui.table;
  28. var form = layui.form;
  29. var element = layui.element;
  30. //方法级渲染
  31. table.render({
  32. elem: '#table_list'
  33. ,url: '/admin/table'
  34. ,cols: [[
  35. // {checkbox: true, fixed: true},
  36. {field:'id', title: 'ID', align:'center',sort: true, width:150}
  37. ,{field:'login_name',title: '登录账号'}
  38. ,{field:'real_name', title: '真实姓名'}
  39. ,{field:'phone', title: '联系电话'}
  40. ,{field:'email', title: '电子邮箱'}
  41. ,{field:'status_text', title: '状态'}
  42. ,{fixed: 'right', width:160, align:'center', toolbar: '#bar'}
  43. ]]
  44. ,id: 'listReload'
  45. ,page: true
  46. ,height: "full-130"
  47. });
  48. var $ = layui.$, active = {
  49. reload: function(){
  50. table.reload('listReload', {
  51. where: {
  52. realName: $('#realName').val(),
  53. }
  54. });
  55. }
  56. };
  57. //监听工具条
  58. table.on('tool(table_filter)', function(obj){
  59. var data = obj.data;
  60. if(obj.event === 'edit'){
  61. window.location.href="/admin/edit?id="+data.id
  62. } else if(obj.event === 'status'){
  63. acts = "禁用";
  64. status = "disable";
  65. if (data.status === 0) {
  66. acts = '启用';
  67. status = "enable";
  68. }
  69. if (data.id==1 && obj.event === 'disable') {
  70. layer.msg('超级管理员不允许操作');
  71. return false;
  72. }
  73. layer.confirm('真的'+acts+'【'+data.login_name+'】账号么', function(index){
  74. var jsData = {'id':data.id,'status':status}
  75. $.post('{{urlfor "AdminController.AjaxDel"}}', jsData, function (out) {
  76. if (out.status == 0) {
  77. layer.alert(out.message, {icon: 1},function(index){
  78. layer.close(index);
  79. window.location.reload();
  80. });
  81. } else {
  82. layer.msg(out.message)
  83. }
  84. }, "json");
  85. // obj.del();
  86. layer.close(index);
  87. })
  88. }else{
  89. layer.msg('操作不存在');
  90. }
  91. });
  92. $('.demoTable .layui-btn').on('click', function(){
  93. var type = $(this).data('type');
  94. active[type] ? active[type].call(this) : '';
  95. });
  96. });
  97. </script>