flight.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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 loadflight(page, size, searchTitle) {
  14. if (page === null || page === undefined) page = defaultPage;
  15. if (size === null || size === undefined) size = defaultSize;
  16. var tableOption = {
  17. elem: "#flight",
  18. height: "full-81",
  19. limit: size,
  20. cols: [
  21. [{
  22. type: "checkbox"
  23. },
  24. {
  25. field: "aircraft_type",
  26. title: "机型",
  27. align: "center",
  28. },
  29. {
  30. field: "aircraft_id",
  31. title: "装备id",
  32. align: "center",
  33. },
  34. {
  35. field: "input_time",
  36. title: "导入时间",
  37. align: "center",
  38. },
  39. {
  40. field: "file_path",
  41. title: "数据路径",
  42. align: "center",
  43. },
  44. {
  45. fixed: "right",
  46. title: "操作",
  47. width: 265,
  48. toolbar: "#operationToolbar",
  49. align: "center"
  50. }
  51. ]
  52. ]
  53. };
  54. if (searchTitle === null || searchTitle === undefined || searchTitle === "") {
  55. fetchJSON("api/flightData/listpage?page=" + (page + 1) + "&size=" + size, {}, "get",
  56. function(data) {
  57. if (data.status === 0) {
  58. if (tableFirstLoad) {
  59. tableFirstLoad = false;
  60. laypage.render({
  61. curr: page + 1,
  62. elem: "pagination",
  63. count: data.data.total,
  64. layout: ["count", "prev", "page", "next", "limit",
  65. "refresh", "skip"
  66. ],
  67. jump: function(obj, first) {
  68. if (first) return;
  69. currentPage = obj.curr - 1;
  70. currentSize = obj.limit;
  71. loadflight(currentPage, currentSize,
  72. searchTitleKey);
  73. }
  74. });
  75. }
  76. tableOption.data = data.data.list;
  77. table.render(tableOption);
  78. } else {
  79. showMsg(data.msg, 2, 2000);
  80. }
  81. });
  82. } else {
  83. fetchJSON("api/flight/getByName?name=" + searchTitle , {},
  84. "get",
  85. function(data) {
  86. if (data.status === 0) {
  87. if (tableFirstLoad) {
  88. tableFirstLoad = false;
  89. laypage.render({
  90. curr: page + 1,
  91. elem: "pagination",
  92. count: data.data.length,
  93. layout: ["count", "prev", "page", "next", "limit",
  94. "refresh", "skip"
  95. ],
  96. jump: function(obj, first) {
  97. if (first) return;
  98. currentPage = obj.curr - 1;
  99. currentSize = obj.limit;
  100. loadflight(currentPage, currentSize,
  101. searchTitleKey);
  102. }
  103. });
  104. }
  105. tableOption.data = data.data;
  106. table.render(tableOption);
  107. } else {
  108. showMsg(data.msg, 2, 2000);
  109. }
  110. });
  111. }
  112. }
  113. loadflight();
  114. $("#searchArticle").on("click", function(e) {
  115. e.preventDefault();
  116. tableFirstLoad = true;
  117. searchTitleKey = title.val().trim();
  118. if (searchTitleKey === "")
  119. loadflight(0, currentSize);
  120. else
  121. loadflight(0, currentSize, searchTitleKey);
  122. });
  123. $("#keyword").on("keyup", function(e) {
  124. e.preventDefault();
  125. if (e.keyCode === 13) {
  126. $("#searchArticle").click();
  127. }
  128. });
  129. // 监听表内工具条
  130. table.on("tool(flight)", function(obj) {
  131. var data = obj.data;
  132. if (obj.event === "edit") {
  133. // 打开编辑框 进行详细编辑
  134. x_admin_show(
  135. "编辑",
  136. encodeURI(
  137. "../admin/flight-add.html?id=" + data.id + "&aircraft_type=" +
  138. data.aircraft_type + "&aircraft_id=" + data.aircraft_id +
  139. "&input_time=" + data.input_time + "&file_path=" + data
  140. .file_path
  141. ),
  142. 470,
  143. 410,
  144. function() {
  145. loadflight(currentPage, currentSize);
  146. }
  147. );
  148. } else
  149. if (obj.event === "delete") {
  150. // 删除
  151. var ids = [];
  152. ids.push(data.id);
  153. layer.confirm("确认要删除吗?", function() {
  154. fetchJSON("api/flightData/delete", {
  155. ids: ids
  156. }, "post", function(data) {
  157. if (data.status === 0) {
  158. showMsg("已删除!", 1, 2000);
  159. tableFirstLoad = true;
  160. loadflight(currentPage, currentSize);
  161. } else {
  162. showMsg(data.msg, 2, 2000);
  163. }
  164. });
  165. });
  166. }else
  167. if (obj.event === 'download') {
  168. var file_path = data.file_path;
  169. var newurl = file_path.substr(1, file_path.length);
  170. file_path = newurl.substr(newurl.indexOf('\\') + 1, file_path.length);
  171. newurl = file_path.substr(0, file_path.indexOf('.'));
  172. var newimg = file_path.substr(file_path.indexOf('.'),file_path.length);
  173. console.log(newimg)
  174. newurl = urlBase + "sourcekg/" + newurl + newimg;
  175. console.log(newurl)
  176. window.open(newurl)
  177. }
  178. });
  179. // 批量删除
  180. $("#batchDelete").on("click", function(e) {
  181. e.preventDefault();
  182. var checkedData = table.checkStatus("flight").data;
  183. if (checkedData.length === 0) {
  184. showMsg("未选择需要删除的日志", 2, 2000);
  185. return;
  186. }
  187. layer.confirm("确认要删除吗?", function() {
  188. var ids = [];
  189. for (var i = 0; i < checkedData.length; i++) {
  190. ids.push(checkedData[i].id);
  191. }
  192. fetchJSON("api/flightData/delete", {
  193. ids: ids
  194. }, "post", function(data) {
  195. if (data.status === 0) {
  196. showMsg("已删除!");
  197. tableFirstLoad = true;
  198. loadflight(currentPage, currentSize);
  199. } else {
  200. showMsg(data.msg, 2, 2000);
  201. }
  202. });
  203. });
  204. });
  205. // 新建用户
  206. $("#addair").on("click", function(e) {
  207. e.preventDefault();
  208. tableFirstLoad = true;
  209. x_admin_show("增加",
  210. "../admin/flight-add.html?id=0&aircraft_type=&aircraft_id=&input_time=&file_path=",
  211. 470,
  212. 410,
  213. function() {
  214. loadflight(currentPage, currentSize);
  215. });
  216. });
  217. });
  218. });