Uoutline.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. $(function() {
  2. var defaultPage = 0;
  3. var defaultSize = 10;
  4. var currentPage = defaultPage;
  5. var currentSize = defaultSize;
  6. var tableFirstLoad = true;
  7. layui.use(["form", "table", "laypage", "layer"], function() {
  8. var table = layui.table;
  9. var laypage = layui.laypage;
  10. var layer = layui.layer;
  11. var title = $("#realName");
  12. var searchTitleKey = "";
  13. function loadoutLineList(page, size, searchTitle) {
  14. if (page === null || page === undefined) page = defaultPage;
  15. if (size === null || size === undefined) size = defaultSize;
  16. var tableOption = {
  17. elem: "#outLineList",
  18. height: "full-81",
  19. limit: size,
  20. cols: [
  21. [
  22. {
  23. field: "outline_name",
  24. title: "大纲名称",
  25. align: "center"
  26. },
  27. {
  28. fixed: "right",
  29. title: "操作",
  30. toolbar: "#operationToolbar",
  31. align: "center"
  32. }
  33. ]
  34. ]
  35. };
  36. if (searchTitle === null || searchTitle === undefined || searchTitle === "") {
  37. fetchJSON("api/outline/listpage?page=" + (page + 1) + "&size=" + size, {}, "get", function(data) {
  38. if (data.status === 0) {
  39. if (tableFirstLoad) {
  40. tableFirstLoad = false;
  41. laypage.render({
  42. curr: page + 1,
  43. elem: "pagination",
  44. count: data.data.total,
  45. layout: ["count", "prev", "page", "next", "limit", "refresh", "skip"],
  46. jump: function(obj, first) {
  47. if (first) return;
  48. currentPage = obj.curr - 1;
  49. currentSize = obj.limit;
  50. loadoutLineList(currentPage, currentSize, searchTitleKey);
  51. }
  52. });
  53. }
  54. tableOption.data = data.data.list;
  55. table.render(tableOption);
  56. } else {
  57. showMsg(data.msg, 2, 2000);
  58. }
  59. });
  60. } else {
  61. fetchJSON("api/outline/getByName?name=" + searchTitle, {}, "get", function(data) {
  62. if (data.status === 0) {
  63. if (tableFirstLoad) {
  64. tableFirstLoad = false;
  65. laypage.render({
  66. curr: page + 1,
  67. elem: "pagination",
  68. count: data.data.total,
  69. layout: ["count", "prev", "page", "next", "limit", "refresh", "skip"],
  70. jump: function(obj, first) {
  71. if (first) return;
  72. currentPage = obj.curr - 1;
  73. currentSize = obj.limit;
  74. loadoutLineList(currentPage, currentSize, searchTitleKey);
  75. }
  76. });
  77. }
  78. tableOption.data = data.data;
  79. table.render(tableOption);
  80. } else {
  81. showMsg(data.msg, 2, 2000);
  82. }
  83. });
  84. }
  85. }
  86. loadoutLineList();
  87. $("#searchArticle").on("click", function(e) {
  88. e.preventDefault();
  89. tableFirstLoad = true;
  90. searchTitleKey = title.val().trim();
  91. if (searchTitleKey === "")
  92. loadoutLineList(0, currentSize);
  93. else
  94. loadoutLineList(0, currentSize, searchTitleKey);
  95. });
  96. $("#keyword").on("keyup", function(e) {
  97. e.preventDefault();
  98. if (e.keyCode === 13) {
  99. $("#searchArticle").click();
  100. }
  101. });
  102. // 监听表内工具条
  103. table.on("tool(outLineList)", function(obj) {
  104. var data = obj.data;
  105. if (obj.event === "edit") {
  106. x_admin_show(
  107. "在线查看",
  108. encodeURI(
  109. "../admin/Uoutline-edit.html?file_path=" + data.file_path
  110. ),
  111. 1300,
  112. 600,
  113. function() {
  114. loadoutLineList(currentPage, currentSize);
  115. }
  116. );
  117. // console.log(data.file_path)
  118. var data = obj.data.file_path
  119. flie = urlBase + data
  120. sessionStorage.setItem("url", flie)
  121. } else if (obj.event === "delete") {
  122. // console.log(data)
  123. // 删除
  124. var ids = [];
  125. ids.push(data.id);
  126. layer.confirm("确认要删除吗?", function() {
  127. fetchJSON("api/outline/delete", {
  128. ids: ids
  129. }, "post", function(data) {
  130. if (data.status === 0) {
  131. showMsg("已删除!", 1, 2000);
  132. tableFirstLoad = true;
  133. loadoutLineList(currentPage, currentSize);
  134. } else {
  135. showMsg(data.msg, 2, 2000);
  136. }
  137. });
  138. });
  139. }
  140. });
  141. // 批量删除
  142. $("#batchDelete").on("click", function(e) {
  143. e.preventDefault();
  144. var checkedData = table.checkStatus("outLineList").data;
  145. if (checkedData.length === 0) {
  146. showMsg("未选择需要删除的日志", 2, 2000);
  147. return;
  148. }
  149. layer.confirm("确认要删除吗?", function() {
  150. var ids = [];
  151. for (var i = 0; i < checkedData.length; i++) {
  152. ids.push(checkedData[i].id);
  153. }
  154. fetchJSON("api/outline/delete", {
  155. ids: ids
  156. }, "post", function(data) {
  157. if (data.status === 0) {
  158. showMsg("已删除!");
  159. tableFirstLoad = true;
  160. loadoutLineList(currentPage, currentSize);
  161. } else {
  162. showMsg(data.msg, 2, 2000);
  163. }
  164. });
  165. });
  166. });
  167. // 新建用户
  168. $("#addair").on("click", function(e) {
  169. e.preventDefault();
  170. tableFirstLoad = true;
  171. x_admin_show("添加",
  172. "../admin/outline-add.html?id=0&outline_name=&aircraft_type=&major_type=&description=&file_path=&input_time=&remarks=",
  173. 800,
  174. 400,
  175. function() {
  176. loadoutLineList(currentPage, currentSize);
  177. });
  178. });
  179. });
  180. });