project_record.html 3.8 KB

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