post_list.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <div class="layui-fluid">
  2. <div class="layui-card">
  3. <div class="layui-form layui-card-header layuiadmin-card-header-auto">
  4. <button class="layui-btn layuiadmin-btn" data-type="add">添加</button>
  5. </div>
  6. <div class="layui-card-body">
  7. <table id="{$lay_table}" lay-filter="{$lay_table}"></table>
  8. <script type="text/html" id="setTpl">
  9. <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">
  10. <i class="layui-icon layui-icon-edit"></i>编辑
  11. </a>
  12. <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">
  13. <i class="layui-icon layui-icon-delete"></i>删除
  14. </a>
  15. </script>
  16. </div>
  17. </div>
  18. </div>
  19. <script>
  20. layui.use(['index', 'admin', 'form', 'table'], function () {
  21. const $ = layui.$;
  22. const admin = layui.admin;
  23. const form = layui.form;
  24. const table = layui.table;
  25. form.render();
  26. table.render({
  27. elem: '#{$lay_table}',
  28. url: "{:url('recruit/listPost')}?id={$id}",
  29. cols: [
  30. [
  31. {field: 'code', title: '编号', width: 300},
  32. {field: 'name', title: '岗位名称'},
  33. {field: 'number', title: '招聘人数', width: 160},
  34. {field: 'update_time', title: '修改时间', width: 160, align: 'center'},
  35. {title: '操作', width: 350, align: 'center', fixed: 'right', toolbar: '#setTpl'}
  36. ]
  37. ],
  38. page: true,
  39. limit: 50,
  40. cellMinWidth: 150,
  41. text: '对不起,加载出现异常!'
  42. });
  43. form.on('submit({$lay_btn})', function (data) {
  44. table.reload('{$lay_table}', {
  45. where: data.field,
  46. page: {
  47. curr: 1
  48. }
  49. });
  50. });
  51. //事件
  52. const active = {
  53. add: function () {
  54. const index = layer.open({
  55. type: 2,
  56. title: '添加岗位',
  57. content: "{:url('recruit/postForm')}?recruit_id={$id}",
  58. maxmin: true,
  59. area: ['550px', '550px']
  60. });
  61. layer.full(index);
  62. }
  63. };
  64. //监听工具条
  65. table.on('tool({$lay_table})', function (obj) {
  66. const data = obj.data;
  67. if (obj.event === 'del') {
  68. layer.confirm('确定删除吗?', function (index) {
  69. admin.req({
  70. url: "{:url('recruit/delPost')}",
  71. data: {
  72. id: data.id
  73. },
  74. done: function (res) {
  75. layui.table.reload('{$lay_table}');
  76. }
  77. });
  78. layer.close(index);
  79. });
  80. } else if (obj.event === 'edit') {
  81. const index = layer.open({
  82. type: 2,
  83. title: '编辑岗位',
  84. content: "{:url('recruit/postForm')}?id=" + data.id,
  85. maxmin: true,
  86. area: ['550px', '550px']
  87. });
  88. layer.full(index);
  89. }
  90. });
  91. $('.layui-btn.layuiadmin-btn').on('click', function () {
  92. const type = $(this).data('type');
  93. active[type] ? active[type].call(this) : '';
  94. });
  95. });
  96. </script>