edit_record.html 4.2 KB

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