Ei kuvausta

searchhome.js 19KB

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