bookAirEqu.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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: "#outLineList",
  18. height: "full-81",
  19. limit: size,
  20. cols: [
  21. [{
  22. title: '序号',
  23. templet: '#xuhao',
  24. align: "center",
  25. width: 60
  26. },
  27. {
  28. field: "aircraft_type",
  29. title: "机型",
  30. align: "center"
  31. },
  32. {
  33. field: "author",
  34. title: "作者",
  35. templet: '#type',
  36. align: "center"
  37. },
  38. {
  39. field: "book_name",
  40. title: "书名",
  41. templet: '#type',
  42. align: "center"
  43. },
  44. {
  45. field: "description",
  46. title: "描述",
  47. templet: '#type',
  48. align: "center"
  49. },
  50. {
  51. field: "img",
  52. title: "图片",
  53. align: "center"
  54. },
  55. {
  56. field: "file_path",
  57. title: "文件名",
  58. templet: '#typeTpl',
  59. align: "center"
  60. },
  61. {
  62. field: "input_time",
  63. title: "开始时间",
  64. align: "center"
  65. },
  66. {
  67. field: "major_type",
  68. title: "专业",
  69. align: "center"
  70. },
  71. {
  72. field: "publish_time",
  73. title: "出版时间",
  74. align: "center"
  75. },
  76. // {
  77. // field: "remarks",
  78. // title: "备注",
  79. // align: "center"
  80. // },
  81. {
  82. fixed: "right",
  83. title: "操作",
  84. toolbar: "#operationToolbar",
  85. align: "center"
  86. }
  87. ]
  88. ]
  89. };
  90. var majorType = "飞控设备";
  91. var name = "";
  92. var major = "飞控设备";
  93. var search = 0;
  94. if (searchTitle === null || searchTitle === undefined || searchTitle === "") {
  95. var url = "api/book/searchByMajor?page=" + (page + 1) + "&size=" + size + "&majorType=" + majorType + "&name=" + name;
  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. loadAirList(currentPage, currentSize, searchTitleKey);
  110. }
  111. });
  112. }
  113. // console.log(data.data)
  114. tableOption.data = data.data.list;
  115. table.render(tableOption);
  116. } else {
  117. showMsg(data.msg, 2, 2000);
  118. }
  119. });
  120. } else {
  121. var url = "api/book/getByKeyword?major=" + major + "&keyword=" +
  122. searchTitle + "&type=" + search +
  123. "&size=" + size + "&page=" + (page + 1)
  124. fetchJSON(url, {}, "get", function(data) {
  125. if (data.status === 0) {
  126. if (tableFirstLoad) {
  127. tableFirstLoad = false;
  128. laypage.render({
  129. curr: page + 1,
  130. elem: "pagination",
  131. count: data.data.total,
  132. layout: ["count", "prev", "page", "next", "limit",
  133. "refresh", "skip"
  134. ],
  135. jump: function(obj, first) {
  136. if (first) return;
  137. currentPage = obj.curr - 1;
  138. currentSize = obj.limit;
  139. loadAirList(currentPage, currentSize,
  140. searchTitleKey);
  141. }
  142. });
  143. }
  144. console.log(data.data.list)
  145. tableOption.data = data.data.list;
  146. table.render(tableOption);
  147. } else {
  148. showMsg(data.msg, 2, 2000);
  149. }
  150. });
  151. }
  152. }
  153. loadAirList();
  154. $("#searchArticle").on("click", function(e) {
  155. e.preventDefault();
  156. tableFirstLoad = true;
  157. searchTitleKey = title.val().trim();
  158. search = $("#find").find("option:selected").val();
  159. if (searchTitleKey === "")
  160. loadAirList(0, currentSize);
  161. else
  162. loadAirList(0, currentSize, searchTitleKey);
  163. });
  164. $("#keyword").on("keyup", function(e) {
  165. e.preventDefault();
  166. if (e.keyCode === 13) {
  167. $("#searchArticle").click();
  168. }
  169. });
  170. // 监听表内工具条
  171. table.on("tool(outLineList)", function(obj) {
  172. var data = obj.data;
  173. console.log(data)
  174. if (obj.event === "edit") {
  175. x_admin_show(
  176. "编辑",
  177. encodeURI(
  178. "book-edit.html?id=" + data.id + "&aircraft_type=" + data.aircraft_type + "&author=" + data.author + "&book_name=" + data.book_name + "&description=" + data.description + "&img=" + data.img + "&input_time=" + data.input_time + "&major_type=" + data.major_type + "&publish_time=" + data.publish_time + "&type_id=" + data.type_id + "&type_name=" + data.type_name + "&file_path=" + data.file_path
  179. ),
  180. 800,
  181. 400,
  182. function() {
  183. loadAirList(currentPage, currentSize);
  184. }
  185. );
  186. } else if (obj.event === "delete") {
  187. // console.log(data)
  188. // 删除
  189. var ids = [];
  190. ids.push(data.id);
  191. layer.confirm("确认要删除吗?", function() {
  192. fetchJSON("api/book/delete", {
  193. ids: ids
  194. }, "post", function(data) {
  195. if (data.status === 0) {
  196. showMsg("已删除!", 1, 2000);
  197. tableFirstLoad = true;
  198. loadAirList(currentPage, currentSize);
  199. } else {
  200. showMsg(data.msg, 2, 2000);
  201. }
  202. });
  203. });
  204. }
  205. });
  206. // 批量删除
  207. $("#batchDelete").on("click", function(e) {
  208. e.preventDefault();
  209. var checkedData = table.checkStatus("outLineList").data;
  210. if (checkedData.length === 0) {
  211. showMsg("未选择需要删除的日志", 2, 2000);
  212. return;
  213. }
  214. layer.confirm("确认要删除吗?", function() {
  215. var ids = [];
  216. for (var i = 0; i < checkedData.length; i++) {
  217. ids.push(checkedData[i].id);
  218. }
  219. fetchJSON("api/book/delete", {
  220. ids: ids
  221. }, "post", function(data) {
  222. if (data.status === 0) {
  223. showMsg("已删除!");
  224. tableFirstLoad = true;
  225. loadAirList(currentPage, currentSize);
  226. } else {
  227. showMsg(data.msg, 2, 2000);
  228. }
  229. });
  230. });
  231. });
  232. // 导入
  233. //表格导入
  234. $("#tolead").on("click", function(e) {
  235. e.preventDefault();
  236. tableFirstLoad = true;
  237. x_admin_show("导入",
  238. "./faul-add.html",
  239. 350,
  240. 200,
  241. function() {
  242. loadAirList(currentPage, currentSize);
  243. });
  244. });
  245. // 新建用户
  246. $("#add").on("click", function(e) {
  247. e.preventDefault();
  248. tableFirstLoad = true;
  249. x_admin_show("添加",
  250. "book-add.html?id=0&author=&aircraft_type=&book_name=&description=&img=&input_time=&major_type&publish_time=&type_id=&type_name=&file_path=",
  251. 800,
  252. 450,
  253. function() {
  254. loadAirList(currentPage, currentSize);
  255. });
  256. });
  257. });
  258. });