No Description

searchhome.js 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. //搜索首页
  2. var ifdiv = false;
  3. var bigClass = 1,
  4. allPages = 1; // 总页数;
  5. var key = "",
  6. subject = "",
  7. industry = "",
  8. province = "",
  9. address = "",
  10. authentication = "",
  11. pageSize = 0,
  12. pageNo = 1
  13. var showblock = document.getElementById("li_show");
  14. var selectblock = document.getElementById("div_select");
  15. var searchVal = document.getElementById("searchval");
  16. var table = document.body.querySelector('.list');
  17. var yyhy = document.getElementById("yyhy");
  18. var xsly = document.getElementById("xsly");
  19. var provinceVal = document.getElementById("provinceval");
  20. var addressVal = document.getElementById("addressval");
  21. mui.init({
  22. pullRefresh: {
  23. container: '#pullrefresh',
  24. up: {
  25. contentrefresh: '正在加载...',
  26. callback: pullupRefresh
  27. }
  28. }
  29. });
  30. function pullupRefresh() {
  31. pageNo = ++pageNo;
  32. console.log(pageNo)
  33. key = searchVal.value;
  34. setTimeout(function() {
  35. expert2(key, subject, industry, province, address, authentication, 10, pageNo)
  36. }, 1000);
  37. }
  38. if(mui.os.plus) {
  39. mui.plusReady(function() {
  40. setTimeout(function() {
  41. mui('#pullrefresh').pullRefresh().pulldownLoading();
  42. }, 500);
  43. });
  44. } else {
  45. mui.ready(function() {
  46. mui('#pullrefresh').pullRefresh().pulldownLoading();
  47. });
  48. }
  49. mui.plusReady(function(){
  50. mui('.list').on('tap','a',function(){
  51. var id=this.getAttribute("data-id");
  52. console.log(id);
  53. var nwaiting = plus.nativeUI.showWaiting();//显示原生等待框
  54. if(bigClass==1){
  55. webviewShow = plus.webview.create("../html/proinforbrow.html",'proinforbrow.html',{},{proid:id});
  56. }else{
  57. webviewShow = plus.webview.create("../html/resinforbrow.html",'resinforbrow.html',{},{resourceId:id});
  58. }
  59. webviewShow.addEventListener("loaded", function() {
  60. nwaiting.close(); //新webview的载入完毕后关闭等待框
  61. webviewShow.show("slide-in-right",150); //把新webview窗体显示出来,显示动画效果为速度150毫秒的右侧移入动画
  62. }, false);
  63. })
  64. var self = plus.webview.currentWebview();
  65. searchVal.value=self.key;
  66. key=self.key;
  67. bigClass=self.bigClass;
  68. if(bigClass==1){
  69. selectblock.innerText='专家';
  70. }else{
  71. selectblock.innerText='资源';
  72. }
  73. //var perrid = plus.webview.getWebviewById('../html/search-home.html');
  74. //perrid.close();
  75. expert(key, subject, industry, province, address, authentication, 10, 1);
  76. })
  77. /*搜专家搜资源的下拉选择框*/
  78. selectblock.addEventListener('tap', function() {
  79. showblock.style.display = 'block';
  80. });
  81. mui("#li_show").on('tap', 'li', function() {
  82. bigClass = this.getAttribute("data-num");
  83. selectblock.innerHTML = this.innerHTML;
  84. showblock.style.display = 'none';
  85. plus.nativeUI.showWaiting();
  86. expert(key, subject, industry, province, address, authentication, 10, 1);
  87. });
  88. /*按键字搜索*/
  89. searchval.addEventListener("keyup", function() {
  90. var e = event || window.event || arguments.caller.arguments[0];
  91. if(e.keyCode == 13) {
  92. key = searchVal.value;
  93. plus.nativeUI.showWaiting();
  94. expert(key, subject, industry, province, address, authentication, 10, 1);
  95. }
  96. })
  97. /*省会*/
  98. mui(".provinceval").on('tap', 'a', function() {
  99. key = searchVal.value;
  100. province = this.innerText;
  101. document.getElementById("addressid").innerText = province;
  102. document.querySelector('#provinceval li a.active').classList.remove('active');
  103. this.classList.add("active");
  104. if(province == "全国") {
  105. province = "";
  106. address = "";
  107. addressVal.innerHTML = "";
  108. plus.nativeUI.showWaiting();
  109. mui('.mui-popover').popover('hide');
  110. expert(key, subject, industry, province, address, authentication, 10, 1);
  111. } else {
  112. mui.ajax(baseUrl + '/ajax/dataDict/qaCity', {
  113. data: {
  114. "dictCode": "ADDRESS",
  115. province: province
  116. },
  117. dataType: 'json', //数据格式类型
  118. type: 'GET', //http请求类型
  119. timeout: 10000,
  120. success: function(data) {
  121. var finallist = '<li class="mui-table-view-cell"><a class="active">全省</a></li>';
  122. console.log(data.success)
  123. console.log(JSON.stringify(data.data))
  124. if(data.success && data.data != "") {
  125. mui.each(data.data, function(i, n) {
  126. finallist += '<li class="mui-table-view-cell"><a >' + n.caption + '</a></li>';
  127. });
  128. addressVal.innerHTML = finallist;
  129. }
  130. },
  131. error: function() {
  132. plus.nativeUI.toast("服务器链接超时", toastStyle);
  133. }
  134. });
  135. }
  136. });
  137. /*市检索*/
  138. mui("#addressval").on('tap', 'a', function() {
  139. key = searchVal.value;
  140. address = this.innerText;
  141. document.querySelector('#addressval li a.active').classList.remove('active');
  142. this.classList.add("active");
  143. if(address == "全省") {
  144. address = "";
  145. }
  146. console.log(province);
  147. console.log(address);
  148. plus.nativeUI.showWaiting();
  149. mui('.mui-popover').popover('hide');
  150. expert(key, subject, industry, province, address, authentication, 10, 1);
  151. })
  152. /*应用行业*/
  153. mui(".yyhy").on('tap', 'a', function() {
  154. key = searchVal.value;
  155. industry = this.innerText;
  156. document.getElementById("industryid").innerText = industry;
  157. document.querySelector('#yyhy li a.active').classList.remove('active');
  158. this.classList.add("active");
  159. if(industry == "不限") {
  160. industry = "";
  161. }
  162. plus.nativeUI.showWaiting();
  163. mui('.mui-popover').popover('hide');
  164. console.log(key);
  165. console.log(subject);
  166. console.log(industry);
  167. console.log(address);
  168. console.log(province);
  169. console.log(authentication);
  170. expert(key, subject, industry, province, address, authentication, 10, 1);
  171. });
  172. /*学术领域*/
  173. mui(".xsly").on('tap', 'a', function() {
  174. key = searchVal.value;
  175. subject = this.innerText;
  176. document.getElementById("subjectid").innerText = subject;
  177. document.querySelector('#xsly li a.active').classList.remove('active');
  178. this.classList.add("active");
  179. if(subject == "不限") {
  180. subject = "";
  181. }
  182. /* console.log(key);
  183. console.log(subject);
  184. console.log(industry);
  185. console.log(address);
  186. console.log(province);
  187. console.log(authentication);*/
  188. plus.nativeUI.showWaiting();
  189. mui('.mui-popover').popover('hide');
  190. expert(key, subject, industry, province, address, authentication, 10, 1);
  191. });
  192. /*初始化数据*/
  193. function expert(key, subject, industry, province, address, authentication, pageSize, pageNo) {
  194. console.log(pageNo)
  195. if(bigClass == 1) {
  196. mui.ajax(baseUrl + '/ajax/professor/pqAPP', {
  197. data: {
  198. "key": key,
  199. "subject": subject,
  200. "industry": industry,
  201. "province": province,
  202. "address": address,
  203. "authentication": authentication,
  204. "pageSize": pageSize,
  205. "pageNo": pageNo,
  206. },
  207. dataType: 'json', //数据格式类型
  208. type: 'GET', //http请求类型
  209. timeout: 10000,
  210. success: function(data) {
  211. table.innerHTML = '';
  212. plus.nativeUI.closeWaiting();
  213. if(data.success && data.data.data != '') {
  214. var datalist = data.data.data;
  215. datalistEach(datalist);
  216. } else {
  217. plus.nativeUI.toast("抱歉,没有找到对应的搜索", toastStyle);
  218. }
  219. },
  220. error: function() {
  221. plus.nativeUI.toast("服务器链接超时", toastStyle);
  222. }
  223. });
  224. } else {
  225. mui.ajax(baseUrl + '/ajax/resource/pqRes', {
  226. data: {
  227. "key": key,
  228. "subject": subject,
  229. "industry": industry,
  230. "province": province,
  231. "address": address,
  232. "authentication": authentication,
  233. "pageSize": pageSize,
  234. "pageNo": pageNo,
  235. },
  236. dataType: 'json', //数据格式类型
  237. type: 'GET', //http请求类型
  238. timeout: 10000,
  239. success: function(data) {
  240. table.innerHTML = '';
  241. plus.nativeUI.closeWaiting();
  242. if(data.success && data.data.data != '') {
  243. var datalist = data.data.data;
  244. resourcesEach(datalist);
  245. } else {
  246. plus.nativeUI.toast("抱歉,没有找到对应的搜索", toastStyle);
  247. }
  248. },
  249. error: function() {
  250. plus.nativeUI.toast("服务器链接超时", toastStyle);
  251. }
  252. });
  253. }
  254. }
  255. /*上拉刷新数据*/
  256. function expert2(key, subject, industry, province, address, authentication, pageSize, pageNo) {
  257. //console.log(pageNo)
  258. //console.log(bigClass);
  259. if(bigClass == 1) {
  260. mui.ajax(baseUrl + '/ajax/professor/pqAPP', {
  261. data: {
  262. "key": key,
  263. "subject": subject,
  264. "industry": industry,
  265. "province": province,
  266. "address": address,
  267. "authentication": authentication,
  268. "pageSize": pageSize,
  269. "pageNo": pageNo,
  270. },
  271. dataType: 'json', //数据格式类型
  272. type: 'GET', //http请求类型
  273. timeout: 10000,
  274. async: false,
  275. success: function(data) {
  276. plus.nativeUI.closeWaiting();
  277. if(data.success && data.data.data != '') {
  278. mui('#pullrefresh').pullRefresh().enablePullupToRefresh(); //启用上拉刷新
  279. var datalist = data.data.data;
  280. var dice1 = data.data.total; //总条数
  281. var dice2 = data.data.pageSize; //每页条数
  282. if(pageNo == 1) { //下拉刷新需要先清空数据
  283. table.innerHTML = ''; // 在这里清空可以防止刷新时白屏
  284. }
  285. allPages = dice1 / dice2;
  286. var datalist = data.data.data;
  287. datalistEach(datalist);
  288. if(pageNo < allPages) {
  289. mui('#pullrefresh').pullRefresh().endPullupToRefresh(false); //能上拉
  290. } else {
  291. mui('#pullrefresh').pullRefresh().endPullupToRefresh(true); //不能上拉
  292. }
  293. } else {
  294. mui('#pullrefresh').pullRefresh().disablePullupToRefresh(); //没有数据禁止上拉刷新
  295. table.innerHTML = '';
  296. plus.nativeUI.toast("抱歉,没有找到对应的搜索", toastStyle);
  297. }
  298. },
  299. error: function() {
  300. plus.nativeUI.toast("服务器链接超时", toastStyle);
  301. mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
  302. }
  303. });
  304. } else {
  305. mui.ajax(baseUrl + '/ajax/resource/pqRes', {
  306. data: {
  307. "key": key,
  308. "subject": subject,
  309. "industry": industry,
  310. "province": province,
  311. "address": address,
  312. "authentication": authentication,
  313. "pageSize": pageSize,
  314. "pageNo": pageNo,
  315. },
  316. dataType: 'json', //数据格式类型
  317. type: 'GET', //http请求类型
  318. timeout: 10000,
  319. async: false,
  320. success: function(data) {
  321. plus.nativeUI.closeWaiting();
  322. if(data.success && data.data.data != '') {
  323. mui('#pullrefresh').pullRefresh().enablePullupToRefresh(); //启用上拉刷新
  324. var datalist = data.data.data;
  325. var dice1 = data.data.total; //总条数
  326. var dice2 = data.data.pageSize; //每页条数
  327. if(pageNo == 1) { //下拉刷新需要先清空数据
  328. table.innerHTML = ''; // 在这里清空可以防止刷新时白屏
  329. }
  330. allPages = dice1 / dice2;
  331. var datalist = data.data.data;
  332. resourcesEach(datalist);
  333. if(pageNo < allPages) {
  334. mui('#pullrefresh').pullRefresh().endPullupToRefresh(false); //能上拉
  335. } else {
  336. mui('#pullrefresh').pullRefresh().endPullupToRefresh(true); //不能上拉
  337. }
  338. } else {
  339. mui('#pullrefresh').pullRefresh().disablePullupToRefresh(); //没有数据禁止上拉刷新
  340. table.innerHTML = '';
  341. plus.nativeUI.toast("抱歉,没有找到对应的搜索", toastStyle);
  342. }
  343. },
  344. error: function() {
  345. plus.nativeUI.toast("服务器链接超时", toastStyle);
  346. mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
  347. }
  348. });
  349. }
  350. }
  351. /*专家数据遍历*/
  352. function datalistEach(datalist) {
  353. mui.each(datalist, function(index, item) {
  354. /*获取头像*/
  355. if(item.hasHeadImage == 1) {
  356. var img = baseUrl + "/images/head/" + item.id + "_m.jpg";
  357. } else {
  358. var img = "../images/default-photo.jpg";
  359. }
  360. /*判断用户是否认证*/
  361. var icon = ''
  362. if(item.authentication == 1) {
  363. icon = '<em class="mui-icon iconfont icon-vip authicon"></em>';
  364. } else {
  365. icon = '<em class="mui-icon iconfont icon-vip unauthicon"></em>';
  366. }
  367. /*获取研究方向信息*/
  368. var researchAreas = item.researchAreas;
  369. var rlist = ''
  370. for(var n = 0; n < researchAreas.length; n++) {
  371. rlist = '<span>' + researchAreas[n].caption + '</span>、';
  372. }
  373. /*获取资源信息*/
  374. var resources = item.resources;
  375. var zlist = ''
  376. for(var m = 0; m < resources.length; m++) {
  377. zlist = '<span>' + resources[m].resourceName + '</span>、';
  378. }
  379. var title = item.title || "";
  380. var office = item.office || "";
  381. var orgName = item.orgName || "";
  382. var address = item.address || "";
  383. if(title != "") {
  384. title = title + " , ";
  385. }
  386. if(office != "") {
  387. office = office + " , ";
  388. }
  389. if(orgName != "") {
  390. orgName = orgName;
  391. }
  392. if(address != "") {
  393. address = " | " + address;
  394. }
  395. var li = document.createElement('li');
  396. li.className = 'mui-table-view-cell mui-media';
  397. li.innerHTML = '<a class="proinfor" data-id="'+item.id+'"' +
  398. '<p><img class="mui-media-object mui-pull-left headimg" src="' + img + '"></p>' +
  399. '<div class="mui-media-body">' +
  400. '<span class="listtit">' + item.name + icon + '</span>' +
  401. '<p class="listtit2"><span>' + title + '</span><span>' + office + '</span><span>' + orgName + '</span><span>' + address + '</span></p>' +
  402. '<p class="mui-ellipsis listtit3">' + rlist + '</p>' +
  403. '<p class="mui-ellipsis listtit3">' + zlist + '</p>' +
  404. '</div></a></li>';
  405. table.appendChild(li, table.firstChild);
  406. });
  407. }
  408. /*资源数据遍历*/
  409. function resourcesEach(datalist) {
  410. mui.each(datalist, function(index, item) {
  411. /*获取头像*/
  412. if(item.images.length) {
  413. var img = baseUrl + "/images/resource/" + item.resourceId + ".jpg";
  414. } else {
  415. var img = "../images/default-resource.jpg";
  416. }
  417. /*判断用户是否认证*/
  418. var icon = ''
  419. if(item.professor.authentication == true) {
  420. icon = '<em class="mui-icon iconfont icon-vip authicon"></em>';
  421. } else {
  422. icon = '<em class="mui-icon iconfont icon-vip unauthicon"></em>';
  423. }
  424. var title = item.professor.title || "";
  425. var office = item.professor.office || "";
  426. var orgName = item.professor.orgName || "";
  427. var address = item.professor.address || "";
  428. if(title != "") {
  429. title = title + " , ";
  430. }
  431. if(office != "") {
  432. office = office + " , ";
  433. }
  434. if(orgName != "") {
  435. orgName = orgName;
  436. }
  437. if(address != "") {
  438. address = " | " + address;
  439. }
  440. var li = document.createElement('li');
  441. li.className = 'mui-table-view-cell mui-media';
  442. li.innerHTML = '<a class="proinfor" data-id="'+item.resourceId+'"' +
  443. '<p><img class="mui-media-object mui-pull-left resimg" src="' + img + '"></p>' +
  444. '<div class="mui-media-body">' +
  445. '<span class="listtit">' + item.resourceName + '</span>' +
  446. '<p class="mui-ellipsis listtit2">' + item.supportedServices + '</p>' +
  447. '<span class="listtit">' + item.professor.name + icon + '</span>' +
  448. '<p class="listtit3"><span>' + title + '</span><span>' + office + '</span><span>' + orgName + '</span><span>' + address + '</span></p>' +
  449. '</div></a></li>';
  450. table.appendChild(li, table.firstChild);
  451. });
  452. }
  453. //省
  454. mui.ajax(baseUrl + '/ajax/dataDict/qaCity', {
  455. data: {
  456. "dictCode": "PROVINCE"
  457. },
  458. dataType: 'json', //数据格式类型
  459. type: 'GET', //http请求类型
  460. timeout: 10000,
  461. success: function(data) {
  462. var finallist = '<li class="mui-table-view-cell"><a class="active">全国</a></li>';
  463. console.log(data.success)
  464. console.log(JSON.stringify(data.data))
  465. if(data.success && data.data != "") {
  466. mui.each(data.data, function(i, n) {
  467. finallist += '<li class="mui-table-view-cell"><a >' + n.caption + '</a></li>';
  468. });
  469. provinceVal.innerHTML = finallist;
  470. }
  471. },
  472. error: function() {
  473. plus.nativeUI.toast("服务器链接超时", toastStyle);
  474. }
  475. });
  476. //应用行业
  477. mui.ajax(baseUrl + '/ajax/dataDict/qa/INDUSTRY', {
  478. dataType: 'json', //数据格式类型
  479. type: 'GET', //http请求类型
  480. timeout: 10000,
  481. success: function(data) {
  482. var finallist = '<li class="mui-table-view-cell mui-col-xs-5"><a class="active">不限</a></li>';
  483. console.log(data.success)
  484. console.log(JSON.stringify(data.data))
  485. if(data.success && data.data != "") {
  486. mui.each(data.data, function(i, n) {
  487. finallist += '<li class="mui-table-view-cell mui-col-xs-5"><a >' + n.caption + '</a></li>';
  488. });
  489. yyhy.innerHTML = finallist;
  490. }
  491. },
  492. error: function() {
  493. plus.nativeUI.toast("服务器链接超时", toastStyle);
  494. }
  495. });
  496. //学术领域
  497. mui.ajax(baseUrl + '/ajax/dataDict/qa/SUBJECT', {
  498. dataType: 'json', //数据格式类型
  499. type: 'GET', //http请求类型
  500. timeout: 10000,
  501. success: function(data) {
  502. var finallist = '<li class="mui-table-view-cell mui-col-xs-5"><a class="active" >不限</a></li>';
  503. //console.log(data.success)
  504. //console.log(JSON.stringify(data.data))
  505. if(data.success && data.data != "") {
  506. mui.each(data.data, function(i, n) {
  507. finallist += '<li class="mui-table-view-cell mui-col-xs-5"><a >' + n.caption + '</a></li>';
  508. });
  509. xsly.innerHTML = finallist;
  510. }
  511. },
  512. error: function() {
  513. plus.nativeUI.toast("服务器链接超时", toastStyle);
  514. }
  515. });