technicalterm.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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: "#technicalterm",
  18. height: "full-81",
  19. limit: size,
  20. cols: [
  21. [{
  22. type: "checkbox"
  23. },
  24. {
  25. field: "cn_name",
  26. title: "中文名称",
  27. align: "center",
  28. },
  29. {
  30. field: "eng_name",
  31. title: "英文名称",
  32. align: "center"
  33. },
  34. {
  35. field: "content",
  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. if (searchTitle === null || searchTitle === undefined || searchTitle === "") {
  50. fetchJSON("api/technicalterm/listpage?page=" + (page + 1) + "&size=" + size, {}, "get", function(data) {
  51. if (data.status === 0) {
  52. if (tableFirstLoad) {
  53. tableFirstLoad = false;
  54. laypage.render({
  55. curr: page + 1,
  56. elem: "pagination",
  57. count: data.data.total,
  58. layout: ["count", "prev", "page", "next", "limit", "refresh", "skip"],
  59. jump: function(obj, first) {
  60. if (first) return;
  61. currentPage = obj.curr - 1;
  62. currentSize = obj.limit;
  63. loadAirList(currentPage, currentSize, searchTitleKey);
  64. }
  65. });
  66. }
  67. tableOption.data = data.data.list;
  68. table.render(tableOption);
  69. } else {
  70. showMsg(data.msg, 2, 2000);
  71. }
  72. });
  73. } else {
  74. fetchJSON("api/technicalterm/findByCnName?name=" + searchTitle, {}, "get", function(data) {
  75. if (data.status === 0) {
  76. if (tableFirstLoad) {
  77. tableFirstLoad = false;
  78. laypage.render({
  79. curr: page + 1,
  80. elem: "pagination",
  81. count: data.data.length,
  82. layout: ["count", "prev", "page", "next", "limit", "refresh", "skip"],
  83. jump: function(obj, first) {
  84. if (first) return;
  85. currentPage = obj.curr - 1;
  86. currentSize = obj.limit;
  87. loadAirList(currentPage, currentSize, searchTitleKey);
  88. }
  89. });
  90. }
  91. tableOption.data = data.data;
  92. table.render(tableOption);
  93. } else {
  94. showMsg(data.msg, 2, 2000);
  95. }
  96. });
  97. }
  98. }
  99. loadAirList();
  100. $("#searchArticle").on("click", function(e) {
  101. e.preventDefault();
  102. tableFirstLoad = true;
  103. searchTitleKey = title.val().trim();
  104. if (searchTitleKey === "")
  105. loadAirList(0, currentSize);
  106. else
  107. loadAirList(0, currentSize, searchTitleKey);
  108. });
  109. $("#keyword").on("keyup", function(e) {
  110. e.preventDefault();
  111. if (e.keyCode === 13) {
  112. $("#searchArticle").click();
  113. }
  114. });
  115. // 监听表内工具条
  116. table.on("tool(technicalterm)", function(obj) {
  117. var data = obj.data;
  118. if (obj.event === "edit") {
  119. // 打开编辑框 进行详细编辑
  120. x_admin_show(
  121. "编辑",
  122. encodeURI(
  123. "../admin/technicalterm-add.html?id=" + data.id + "&cn_name=" + data.cn_name + "&eng_name=" + data.eng_name+ "&content=" + data.content
  124. ),
  125. 450,
  126. 320,
  127. function() {
  128. loadAirList(currentPage, currentSize);
  129. }
  130. );
  131. } else if (obj.event === "delete") {
  132. // 删除
  133. var ids = [];
  134. ids.push(data.id);
  135. layer.confirm("确认要删除吗?", function() {
  136. fetchJSON("api/technicalterm/delete", {
  137. ids: ids
  138. }, "post", function(data) {
  139. if (data.status === 0) {
  140. showMsg("已删除!", 1, 2000);
  141. tableFirstLoad = true;
  142. loadAirList(currentPage, currentSize);
  143. } else {
  144. showMsg(data.msg, 2, 2000);
  145. }
  146. });
  147. });
  148. }
  149. });
  150. // 批量删除
  151. $("#batchDelete").on("click", function(e) {
  152. e.preventDefault();
  153. var checkedData = table.checkStatus("technicalterm").data;
  154. if (checkedData.length === 0) {
  155. showMsg("未选择需要删除的日志", 2, 2000);
  156. return;
  157. }
  158. layer.confirm("确认要删除吗?", function() {
  159. var ids = [];
  160. for (var i = 0; i < checkedData.length; i++) {
  161. ids.push(checkedData[i].id);
  162. }
  163. fetchJSON("api/technicalterm/delete", {
  164. ids: ids
  165. }, "post", function(data) {
  166. if (data.status === 0) {
  167. showMsg("已删除!");
  168. tableFirstLoad = true;
  169. loadAirList(currentPage, currentSize);
  170. } else {
  171. showMsg(data.msg, 2, 2000);
  172. }
  173. });
  174. });
  175. });
  176. // 新建用户
  177. $("#addair").on("click", function(e) {
  178. e.preventDefault();
  179. tableFirstLoad = true;
  180. x_admin_show("添加",
  181. "../admin/technicalterm-add.html?id=0&cn_name=&eng_name=&content=",
  182. 450,
  183. 320,
  184. function() {
  185. loadAirList(currentPage, currentSize);
  186. });
  187. });
  188. //表格导入
  189. $("#tolead").on("click", function(e) {
  190. e.preventDefault();
  191. tableFirstLoad = true;
  192. x_admin_show("导入",
  193. "../admin/technicalterm-edit.html",
  194. 350,
  195. 200,
  196. function() {
  197. loadAirList(currentPage, currentSize);
  198. });
  199. });
  200. });
  201. });