暂无描述

searchhome.js 19KB

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