subsystem.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 loadAirList(page, size, searchTitle) {
  14. if (page === null || page === undefined) page = defaultPage;
  15. if (size === null || size === undefined) size = defaultSize;
  16. var tableOption = {
  17. elem: "#airList",
  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: "syst_name",
  31. title: "系统",
  32. align: "center"
  33. },
  34. {
  35. field: "device_name",
  36. title: "子系统",
  37. align: "center"
  38. },
  39. {
  40. fixed: "right",
  41. title: "操作",
  42. width: 265,
  43. toolbar: "#operationToolbar",
  44. align: "center"
  45. }
  46. ]
  47. ]
  48. };
  49. var deviceType = 1;
  50. if (searchTitle === null || searchTitle === undefined || searchTitle === "") {
  51. fetchJSON("api/device/listpage?page=" + (page + 1) + "&deviceType=" + deviceType + "&size=" + size, {}, "get", function(data) {
  52. if (data.status === 0) {
  53. if (tableFirstLoad) {
  54. tableFirstLoad = false;
  55. laypage.render({
  56. curr: page + 1,
  57. elem: "pagination",
  58. count: data.data.total,
  59. layout: ["count", "prev", "page", "next", "limit", "refresh", "skip"],
  60. jump: function(obj, first) {
  61. if (first) return;
  62. currentPage = obj.curr - 1;
  63. currentSize = obj.limit;
  64. loadAirList(currentPage, currentSize, searchTitleKey);
  65. }
  66. });
  67. }
  68. tableOption.data = data.data.list;
  69. table.render(tableOption);
  70. } else {
  71. showMsg(data.msg, 2, 2000);
  72. }
  73. });
  74. } else {
  75. fetchJSON("api/device/getByName?name=" + searchTitle + "&deviceType=" + deviceType, {}, "get", function(data) {
  76. if (data.status === 0) {
  77. if (tableFirstLoad) {
  78. tableFirstLoad = false;
  79. laypage.render({
  80. curr: page + 1,
  81. elem: "pagination",
  82. count: data.data.length,
  83. layout: ["count", "prev", "page", "next", "limit", "refresh", "skip"],
  84. jump: function(obj, first) {
  85. if (first) return;
  86. currentPage = obj.curr - 1;
  87. currentSize = obj.limit;
  88. loadAirList(currentPage, currentSize, searchTitleKey);
  89. }
  90. });
  91. }
  92. tableOption.data = data.data;
  93. table.render(tableOption);
  94. } else {
  95. showMsg(data.msg, 2, 2000);
  96. }
  97. });
  98. }
  99. }
  100. loadAirList();
  101. $("#searchArticle").on("click", function(e) {
  102. e.preventDefault();
  103. tableFirstLoad = true;
  104. searchTitleKey = title.val().trim();
  105. if (searchTitleKey === "")
  106. loadAirList(0, currentSize);
  107. else
  108. loadAirList(0, currentSize, searchTitleKey);
  109. });
  110. $("#keyword").on("keyup", function(e) {
  111. e.preventDefault();
  112. if (e.keyCode === 13) {
  113. $("#searchArticle").click();
  114. }
  115. });
  116. // 监听表内工具条
  117. table.on("tool(airList)", function(obj) {
  118. var data = obj.data;
  119. if (obj.event === "edit") {
  120. console.log(data)
  121. // 打开编辑框 进行详细编辑
  122. x_admin_show(
  123. "编辑",
  124. encodeURI(
  125. "../admin/subsystem-add.html?id=" + data.id + "&device_type=" + data.device_type + "&aircraft_type=" + data.aircraft_type + "&syst_name=" + data.syst_name + "&device_name=" + data.device_name
  126. ),
  127. 470,
  128. 314,
  129. function() {
  130. loadAirList(currentPage, currentSize);
  131. }
  132. );
  133. } else if (obj.event === "delete") {
  134. // 删除
  135. var ids = [];
  136. ids.push(data.id);
  137. layer.confirm("确认要删除吗?", function() {
  138. fetchJSON("api/device/delete", {
  139. ids: ids
  140. }, "post", function(data) {
  141. if (data.status === 0) {
  142. showMsg("已删除!", 1, 2000);
  143. tableFirstLoad = true;
  144. loadAirList(currentPage, currentSize);
  145. } else {
  146. showMsg(data.msg, 2, 2000);
  147. }
  148. });
  149. });
  150. }
  151. });
  152. // 批量删除
  153. $("#batchDelete").on("click", function(e) {
  154. e.preventDefault();
  155. var checkedData = table.checkStatus("airList").data;
  156. if (checkedData.length === 0) {
  157. showMsg("未选择需要删除的日志", 2, 2000);
  158. return;
  159. }
  160. layer.confirm("确认要删除吗?", function() {
  161. var ids = [];
  162. for (var i = 0; i < checkedData.length; i++) {
  163. ids.push(checkedData[i].id);
  164. }
  165. fetchJSON("api/device/delete", {
  166. ids: ids
  167. }, "post", function(data) {
  168. if (data.status === 0) {
  169. showMsg("已删除!");
  170. tableFirstLoad = true;
  171. loadAirList(currentPage, currentSize);
  172. } else {
  173. showMsg(data.msg, 2, 2000);
  174. }
  175. });
  176. });
  177. });
  178. // 新建用户
  179. $("#addair").on("click", function(e) {
  180. e.preventDefault();
  181. tableFirstLoad = true;
  182. x_admin_show("增加",
  183. "../admin/subsystem-add.html?id=0&device_type=&aircraft_type=&syst_name=&device_name=",
  184. 470,
  185. 314,
  186. function() {
  187. loadAirList(currentPage, currentSize);
  188. });
  189. });
  190. });
  191. });