device.js 8.6 KB

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