project_record.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <style>
  2. /* 自定义样式 */
  3. .layui-table-testcss .layui-table-header,
  4. .layui-form-testcss > div{margin-bottom: 6px;}
  5. </style>
  6. <div class="p-3 bg-white">
  7. <table class="layui-hide" id="record" lay-filter="record"></table>
  8. </div>
  9. <script type="text/html" id="toolbarrecord">
  10. <div class="layui-btn-container">
  11. <button class="layui-btn layui-btn-sm" lay-event="add">+ 新建记录</button>
  12. </div>
  13. </script>
  14. <script>
  15. function record() {
  16. if ($('#projectTab').find('li').eq(1).data('load') == 'true') {
  17. console.log(1);
  18. return false;
  19. }
  20. $('#projectTab').find('li').eq(1).data('load', 'true');
  21. let tool = layui.tool, table = layui.table;
  22. //项目任务
  23. parent.layui.recordTable = table.render({
  24. elem: '#record',
  25. title: '文档列表',
  26. toolbar: '#toolbarrecord',
  27. cellMinWidth: 80,
  28. className: 'layui-table-testcss', // 用于给表格主容器追加 css 类名
  29. lineStyle: 'height: 151px;', // 定义表格的多行样式
  30. url: "/admin/project.record/cplist",
  31. where: {'project_id': project_id},
  32. page: true, //开启分页
  33. limit: 20,
  34. cols: [[
  35. {field: 'id', title: '记录编号', width: 80, align: 'center'},
  36. {field: 'title', title: '记录内容',
  37. templet: function (d) {
  38. var html = '<a class="side-a" lay-event="detail">' + d.content + '</a>';
  39. return html;
  40. }
  41. },
  42. {field: 'create_time', title: '创建时间', align: 'center', width: 150},
  43. {field: 'admin_name', title: '创建人', align: 'center', width: 100},
  44. {field: 'right', fixed: 'right', title: '操作', width: 100, align: 'center',
  45. templet: function (d) {
  46. var html = '<div class="layui-btn-group">';
  47. var btn1 = '<span class="layui-btn layui-btn-xs" lay-event="edit">编辑</span>';
  48. var btn2 = '<span class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</span>';
  49. return html + btn1 + btn2 + '</div>';
  50. }
  51. }
  52. ]]
  53. });
  54. //触发事件
  55. table.on('toolbar(record)', function (obj) {
  56. var checkStatus = table.checkStatus(obj.config.id);
  57. switch (obj.event) {
  58. case 'add':
  59. parent.layui.tool.side('/admin/project.record/add?project_id=' + project_id); // 项目id
  60. break;
  61. }
  62. });
  63. table.on('tool(record)', function (obj) {
  64. var data = obj.data; //获得当前行数据
  65. if (obj.event === 'detail') { //查看
  66. let url = '/admin/project.record/view?id=' + data.id;// 项目id
  67. parent.layui.tool.side(url);
  68. }
  69. if (obj.event === 'edit') {
  70. parent.layui.tool.side('/admin/project.record/edit?id=' + data.id); // 项目id
  71. return;
  72. }
  73. if (obj.event === 'del') {
  74. layer.confirm('确定要删除吗?', {
  75. icon: 3,
  76. title: '提示'
  77. }, function (index) {
  78. let callback = function (e) {
  79. layer.msg(e.msg);
  80. if (e.code == 0) {
  81. obj.del();
  82. }
  83. }
  84. tool.delete("/admin/project.record/del", {id: data.id}, callback);// 项目id
  85. layer.close(index);
  86. });
  87. }
  88. })
  89. }
  90. </script>