search.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. let str = '';
  2. function geturl() {
  3. x_admin_show(
  4. "在线查看",
  5. encodeURI(
  6. "../admin/look.html"
  7. ),
  8. 1300,
  9. 600,
  10. );
  11. }
  12. $(function() {
  13. var storage = window.localStorage;
  14. let user = window.localStorage.getItem('user');
  15. let userInfo = JSON.parse(user);
  16. let type = '';
  17. let a = true
  18. let b = true
  19. let c = true
  20. $('.search-type span').click((e) => {
  21. // console.log(e.target.id)
  22. type = e.target.id;
  23. $('.search-type span').css({
  24. color: 'black',
  25. // borderBottom: 'black'
  26. });
  27. e.target.style.color = '#09c'
  28. // e.target.style.borderBottom = '1px solid #09c'
  29. })
  30. //搜索
  31. $('.searchBtn').click(() => {
  32. if ($('.searchInput').val() == "") {
  33. $('.search-data').css({
  34. 'display': 'none'
  35. });
  36. } else {
  37. var url2 = "look.html"
  38. // console.log(url2)
  39. $("#bot").css({
  40. display: 'block'
  41. })
  42. $('.search-box').addClass('search-box-toLeft');
  43. $('.search-data').css({
  44. 'display': 'block'
  45. });
  46. const data = {
  47. type: type,
  48. keyword: $('.searchInput').val()
  49. };
  50. $.ajax({
  51. type: "get",
  52. url: urlBase + "api/common/find",
  53. async: true,
  54. data: data,
  55. headers: {
  56. // token:"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIxIn0.Oik3R7IxeUi9v9d0C7kvFd2gF_xSu4WjspKKeXy3dGw"
  57. token: sessionStorage.getItem('token')
  58. },
  59. success: res => {
  60. if (res.status == 0) {
  61. $('.search-data-list').html();
  62. let data = res.data;
  63. // console.log(data)
  64. var name, path, major, type, system;
  65. let allData = [];
  66. for (var index in data) {
  67. // console.log(index)
  68. for (var i = 0; i < data[index].data.length; i++) {
  69. cData = data[index].data;
  70. // console.log(cData)
  71. if (index == 'repairManual') {
  72. name = cData[i].manual_name;
  73. major = cData[i].major;
  74. type = cData[i].aircraft;
  75. system = cData[i].manual_system;
  76. } else if (index == 'faultRecord') {
  77. name = cData[i].device_name;
  78. major = cData[i].major;
  79. type = cData[i].aircraft_type;
  80. system = cData[i].faultparts_system;
  81. } else if (index == 'article') {
  82. name = cData[i].title;
  83. major = cData[i].major_name;
  84. type = cData[i].aircraft;
  85. system = cData[i].aircraft_system;
  86. }
  87. var fileType;
  88. var file_path = cData[i].file_path;
  89. sessionStorage.setItem("url1",file_path)
  90. str +=
  91. '<li class="search-data-item"><a href=javascript:geturl()>' +
  92. name + '</a><p>机型:<span>' + type +
  93. '</span></p><p>专业:<span>' + major +
  94. '</span></p><p>系统:<span>' + system + '</span></p></li>'
  95. // console.log(str)
  96. }
  97. }
  98. $('.search-data-list').html(str)
  99. } else {
  100. alert(res.msg);
  101. }
  102. },
  103. error: xhr => {
  104. // console.log(xhr)
  105. }
  106. });
  107. }
  108. });
  109. //二次搜索
  110. $("#bot").click(() => {
  111. if ($('.searchInput').val() == "") {
  112. $('.search-data').css({
  113. 'display': 'none'
  114. });
  115. } else {
  116. var one = document.getElementById("search").value;
  117. const data = {
  118. type: type,
  119. keyword1: one,
  120. keyword2: $('.searchInput').val()
  121. }
  122. $.ajax({
  123. type: "get",
  124. url: urlBase + "api/common/refind",
  125. async: true,
  126. data: data,
  127. headers: {
  128. // token:"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIxIn0.Oik3R7IxeUi9v9d0C7kvFd2gF_xSu4WjspKKeXy3dGw"
  129. token: sessionStorage.getItem('token')
  130. },
  131. success: res => {
  132. if (res.status == 0) {
  133. $('.search-data-list').html();
  134. let data = res.data;
  135. // console.log(data)
  136. let str = '';
  137. var name, path, major, type, system;
  138. let allData = [];
  139. for (var index in data) {
  140. // console.log(data)
  141. for (var i = 0; i < data[index].data.length; i++) {
  142. cData = data[index].data;
  143. // console.log(cData)
  144. if (index == 'repairManual') {
  145. name = cData[i].manual_name;
  146. major = cData[i].major;
  147. type = cData[i].aircraft;
  148. system = cData[i].manual_system;
  149. } else if (index == 'faultRecord') {
  150. name = cData[i].device_name;
  151. major = cData[i].major;
  152. type = cData[i].aircraft_type;
  153. system = cData[i].faultparts_system;
  154. } else if (index == 'article') {
  155. name = cData[i].title;
  156. major = cData[i].major_name;
  157. type = cData[i].aircraft;
  158. system = cData[i].aircraft_system;
  159. }
  160. var file_path = cData[i].file_path;
  161. sessionStorage.setItem("url1",file_path)
  162. // str += '<li class="search-data-item"><a href=""></a></li>'
  163. str += '<li class="search-data-item"><a href=javascript:geturl()>' + name + '</a><p>机型:<span>' + type +
  164. '</span></p><p>专业:<span>' + major +
  165. '</span></p><p>系统:<span>' + system + '</span></p></li>'
  166. // console.log(str)
  167. }
  168. }
  169. $('.search-data-list').html(str)
  170. } else {
  171. alert(res.msg);
  172. }
  173. },
  174. error: xhr => {
  175. // console.log(xhr)
  176. }
  177. });
  178. }
  179. });
  180. })