advanced_search.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. var num = 0
  2. let arr = [{
  3. id: 0,
  4. name: "故障记录",
  5. English: 'faultRecord'
  6. },
  7. {
  8. id: 1,
  9. name: "故障案例",
  10. English: 'repairManual'
  11. },
  12. {
  13. id: 2,
  14. name: "技术资料",
  15. English: 'article'
  16. },
  17. ]
  18. $(function() {
  19. var storage = window.localStorage;
  20. let user = window.localStorage.getItem('user');
  21. let userInfo = JSON.parse(user);
  22. let type = '';
  23. var momEle = document.getElementById("search-box");
  24. $('.search-type span').click((e) => {
  25. console.log(e.target.id)
  26. type = e.target.id;
  27. $('.search-type span').css({
  28. color: 'black',
  29. // borderBottom: 'black'
  30. });
  31. e.target.style.color = '#09c'
  32. // e.target.style.borderBottom = '1px solid #09c'
  33. })
  34. $('#logOut').click(() => {
  35. const data = {
  36. id: userInfo.id
  37. };
  38. $.ajax({
  39. type: "post",
  40. url: urlBase + "api/common/login",
  41. async: true,
  42. data: JSON.stringify(data),
  43. success: res => {
  44. if (res.status == 0) {
  45. window.location.href = '../index.html';
  46. } else {
  47. alert(res.msg);
  48. }
  49. },
  50. error: xhr => {
  51. console.log(xhr)
  52. }
  53. });
  54. })
  55. $("input[id='add']").click(add);
  56. function add() {
  57. num++;
  58. var divEle = document.createElement("div");
  59. divEle.setAttribute("class", "form");
  60. divEle.setAttribute("id", `${num}`);
  61. var inner =
  62. '<div style="margin-top: 15px;display: block;margin-left:18% ;width:100%;" class="form"><select id="sel'+num+'" class="sel" lay-search="sel" lay-verify="required"><option value="">AND</option><option value="1">OR</option><option value="2">NOT</option></select><select id="all'+num+'" class="all" lay-search="all" lay-verify="required" style="margin-left:22px;"><option value="">故障记录</option><option value="1">故障案例</option><option value="2">技术资料</option></select><input style="width:256px;margin-left:10px;" type="text" id="search' +
  63. num + '" class="searchInput" placeholder="请输入关键字" /></div>'
  64. divEle.innerHTML = inner;
  65. // alert(divEle.innerHTML);
  66. if (num >= 4) {
  67. alert("最多四条")
  68. } else {
  69. momEle.appendChild(divEle);
  70. }
  71. }
  72. $("input[id='pop']").click(pop);
  73. function pop() {
  74. if (num != 0) {
  75. var current_dom = document.getElementById(`${num}`);
  76. momEle.removeChild(current_dom);
  77. num--
  78. } else {
  79. alert('最少有一个字段')
  80. }
  81. }
  82. $('#searchBtn').click(() => {
  83. if ($('.searchInput').val() == "") {} else {
  84. $('.search-box').addClass('search-box-toLeft');
  85. $('.search-data').css({
  86. 'display': 'block'
  87. });
  88. const data = {
  89. type: type,
  90. keyword: $('.searchInput').val()
  91. };
  92. $.ajax({
  93. type: "get",
  94. url: urlBase + "api/common/find",
  95. async: true,
  96. data: data,
  97. headers: {
  98. // token:"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIxIn0.Oik3R7IxeUi9v9d0C7kvFd2gF_xSu4WjspKKeXy3dGw"
  99. token: sessionStorage.getItem('token')
  100. },
  101. success: res => {
  102. if (res.status == 0) {
  103. $('.search-data-list').html();
  104. let data = res.data;
  105. let str = '';
  106. var name, path;
  107. let allData = [];
  108. for (var index in data) {
  109. for (var i = 0; i < data[index].length; i++) {
  110. cData = data[index];
  111. if (index == 'repairManual') {
  112. name = cData[i].device_type;
  113. // console.log(name)
  114. } else if (index == 'faultRecord') {
  115. name = cData[i].device_name + cData[i].equipment_name +
  116. cData[i].fault_content;
  117. // console.log(name)
  118. } else if (index == 'article') {
  119. name = cData[i].keywords;
  120. // console.log(name)
  121. }
  122. var fileType;
  123. if (cData[i].file_path) {
  124. fileType = cData[i].file_path.split('.')[1];
  125. path = urlBase + cData[i].file_path;
  126. }
  127. str += '<li class="search-data-item"><a href="' + path +
  128. '">' + name +
  129. '</a></li>'
  130. // console.log(str)
  131. }
  132. }
  133. $('.search-data-list').html(str)
  134. } else {
  135. alert(res.msg);
  136. }
  137. },
  138. error: xhr => {
  139. console.log(xhr)
  140. }
  141. });
  142. }
  143. });
  144. function getAll() {
  145. // $("#all").append($("<option>", {
  146. // value: -1,
  147. // text: "请选择"
  148. // }));
  149. for (var i = 0; i < arr.length; i++) {
  150. $("#all").append(
  151. $("<option>", {
  152. // value: arr[i].id,
  153. text: arr[i].name
  154. })
  155. );
  156. }
  157. };
  158. getAll()
  159. layui.use(["form"], function() {
  160. var form = layui.form
  161. form.on("select", function(data) {
  162. if (data.elem.id === "all"){
  163. roleName = data.elem[data.elem.selectedIndex].text;
  164. console.log(roleName)
  165. }
  166. })
  167. })
  168. })