machine.js 8.0 KB

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