index_1.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. {extend name="common/base"/}
  2. <!-- 主体 -->
  3. {block name="body"}
  4. <div class="p-3">
  5. <table class="layui-hide" id="test" lay-filter="test"></table>
  6. </div>
  7. <script type="text/html" id="status">
  8. <i class="layui-icon {{# if(d.status == 1){ }}green layui-icon-ok{{# } else { }}yellow layui-icon-close{{# } }}"></i>
  9. </script>
  10. <script type="text/html" id="toolbarDemo">
  11. <div class="layui-btn-container">
  12. <button class="layui-btn layui-btn-sm" lay-event="add">+ 添加岗位</button>
  13. </div>
  14. </script>
  15. <script type="text/html" id="barDemo">
  16. <div class="layui-btn-group"><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></div>
  17. </script>
  18. {/block}
  19. <!-- /主体 -->
  20. <!-- 脚本 -->
  21. {block name="script"}
  22. <script>
  23. const moduleInit = ['tool'];
  24. function gouguInit() {
  25. var table = layui.table, tool = layui.tool;
  26. layui.pageTable = table.render({
  27. elem: '#test',
  28. title: '岗位列表',
  29. toolbar: '#toolbarDemo',
  30. url: "/admin/position/index", //数据接口
  31. page: false, //开启分页
  32. cols: [
  33. [
  34. {
  35. field: 'id',
  36. title: 'ID号',
  37. align: 'center',
  38. width: 80
  39. },
  40. {
  41. field: 'd_title',
  42. title: '所属单位',
  43. align: 'center',
  44. width: 120
  45. },
  46. {
  47. field: 'title',
  48. title: '岗位名称',
  49. align: 'center',
  50. width: 120
  51. },
  52. {
  53. field: 'remark',
  54. title: '备注'
  55. },
  56. // {
  57. // field: 'work_price',
  58. // title: '岗位工时单价(元)',
  59. // align: 'center',
  60. // width: 132
  61. // },
  62. {
  63. field: 'status',
  64. title: '状态',
  65. toolbar: '#status',
  66. align: 'center',
  67. width: 60
  68. },
  69. {
  70. field: 'right',
  71. title: '操作',
  72. toolbar: '#barDemo',
  73. width: 120,
  74. align: 'center'
  75. }
  76. ]
  77. ]
  78. });
  79. //表头工具栏事件
  80. table.on('toolbar(test)', function(obj){
  81. if (obj.event === 'add') {
  82. tool.side("/admin/position/add");
  83. return;
  84. }
  85. });
  86. //监听行工具事件
  87. table.on('tool(test)', function (obj) {
  88. var data = obj.data;
  89. if(obj.event === 'edit'){
  90. tool.side('/admin/position/add?id='+data.id);
  91. return;
  92. }
  93. if (obj.event === 'del') {
  94. if (data.id == 1) {
  95. layer.msg('董事长职位不能删除');
  96. return;
  97. }
  98. layer.confirm('您确定要删除该岗位', {
  99. icon: 3,
  100. title: '提示'
  101. }, function (index) {
  102. let callback = function (e) {
  103. layer.msg(e.msg);
  104. if (e.code == 0) {
  105. obj.del();
  106. }
  107. }
  108. tool.delete("/admin/position/delete", { id: obj.data.id }, callback);
  109. layer.close(index);
  110. });
  111. }
  112. });
  113. }
  114. </script>
  115. {/block}
  116. <!-- /脚本 -->