Nav apraksta

index.js 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. //首页
  2. var pageIndex = 1; // 页数
  3. var allPages = 1; // 总页数
  4. var table = document.body.querySelector('.list');
  5. var search = document.getElementById("search");
  6. mui.plusReady(function(){
  7. plus.nativeUI.showWaiting();
  8. })
  9. mui('.list').on('tap','a',function(){
  10. var id=this.getAttribute("data-id");
  11. console.log(id);
  12. plus.nativeUI.showWaiting();//显示原生等待框
  13. webviewShow = plus.webview.create("../html/proinforbrow.html",'proinforbrow.html',{},{proid:id});//后台创建webview并打开show.html
  14. })
  15. /*点击搜索按钮*/
  16. search.addEventListener('focus', function() {
  17. var nwaiting = plus.nativeUI.showWaiting();//显示原生等待框
  18. webviewShow = plus.webview.create("../html/search-home.html","../html/search-home.html");//后台创建webview并打开show.html
  19. webviewShow.addEventListener("loaded", function() {
  20. nwaiting.close(); //新webview的载入完毕后关闭等待框
  21. webviewShow.show("slide-in-right",150); //把新webview窗体显示出来,显示动画效果为速度150毫秒的右侧移入动画
  22. }, false);
  23. });
  24. /*点击热门领域*/
  25. mui('.gridbg').on('tap','li',function(){
  26. var subject = this.getAttribute("data-title");
  27. plus.nativeUI.showWaiting();//显示原生等待框
  28. webviewShow = plus.webview.create("../html/search.html",'search.html',{},{subject:subject,bigClass:1});//后台创建webview并打开show.html
  29. })
  30. /*页面数据初始化*/
  31. getOnePase();
  32. mui.init({
  33. pullRefresh: {
  34. container: '#pullrefresh',
  35. up: {
  36. contentrefresh: '正在加载...',
  37. callback: pullupRefresh
  38. }
  39. }
  40. });
  41. function pullupRefresh() {
  42. pageIndex = ++pageIndex;
  43. setTimeout(function() {
  44. getaData()
  45. }, 1000);
  46. }
  47. if(mui.os.plus) {
  48. mui.plusReady(function() {
  49. setTimeout(function() {
  50. mui('#pullrefresh').pullRefresh().pulldownLoading();
  51. }, 500);
  52. });
  53. } else {
  54. mui.ready(function() {
  55. mui('#pullrefresh').pullRefresh().pulldownLoading();
  56. });
  57. }
  58. /*获取上拉加载更多数据*/
  59. function getaData() {
  60. mui.plusReady(function() {
  61. mui.ajax(baseUrl + '/ajax/professor/pqHot', {
  62. data: {
  63. "pageNo": pageIndex,
  64. "pageSize": 10,
  65. },
  66. dataType: 'json', //数据格式类型
  67. type: 'GET', //http请求类型
  68. timeout: 10000,
  69. async:false,
  70. success: function(data) {
  71. if(data.success) {
  72. //console.log("成功");
  73. var dice1 = data.data.total; //总条数
  74. var dice2 = data.data.pageSize; //每页条数
  75. var result = '';
  76. if(pageIndex == 1) { //下拉刷新需要先清空数据
  77. table.innerHTML = ''; // 在这里清空可以防止刷新时白屏
  78. }
  79. allPages = dice1 / dice2;
  80. var datalist = data.data.data;
  81. datalistEach(datalist);
  82. if(pageIndex < allPages) {
  83. mui('#pullrefresh').pullRefresh().endPullupToRefresh(false); /*能上拉*/
  84. } else {
  85. mui('#pullrefresh').pullRefresh().endPullupToRefresh(true); /*不能上拉*/
  86. }
  87. }
  88. },
  89. error: function() {
  90. plus.nativeUI.toast("服务器链接超时", toastStyle);
  91. mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
  92. }
  93. });
  94. });
  95. }
  96. /*获取第一页数据*/
  97. function getOnePase() {
  98. mui.plusReady(function() {
  99. mui.ajax(baseUrl + '/ajax/professor/pqHot', {
  100. data: {
  101. "pageNo": 1,
  102. "pageSize": 10,
  103. },
  104. dataType: 'json', //数据格式类型
  105. type: 'GET', //http请求类型
  106. timeout: 10000,
  107. success: function(data) {
  108. if(data.success) {
  109. plus.nativeUI.closeWaiting();
  110. var datalist = data.data.data;
  111. datalistEach(datalist);
  112. }
  113. },
  114. error: function() {
  115. plus.nativeUI.toast("服务器链接超时", toastStyle);
  116. }
  117. });
  118. });
  119. }
  120. /*数据遍历*/
  121. function datalistEach(datalist) {
  122. mui.each(datalist, function(index, item) {
  123. /*获取头像*/
  124. if(item.hasHeadImage == 1) {
  125. var img = "../images/head/" + item.id + "_m.jpg";
  126. } else {
  127. var img = "../images/default-photo.jpg";
  128. }
  129. /*获取研究方向信息*/
  130. var researchAreas = item.researchAreas;
  131. var rlist = ''
  132. for(var n = 0; n < researchAreas.length; n++) {
  133. //console.log(researchAreas[n].caption);
  134. rlist = '<span>' + researchAreas[n].caption + '</span>、';
  135. }
  136. /*获取资源信息*/
  137. var resources = item.resources;
  138. var zlist = ''
  139. for(var m = 0; m < resources.length; m++) {
  140. //console.log(resources[m].caption);
  141. zlist = '<span>' + resources[m].resourceName + '</span>、';
  142. }
  143. var title = item.title || "";
  144. var office = item.office || "";
  145. var orgName = item.orgName || "";
  146. var address = item.address || "";
  147. if(title != "") {
  148. title = title + " , ";
  149. }
  150. if(office != "") {
  151. office = office + " , ";
  152. }
  153. if(orgName != "") {
  154. orgName = orgName;
  155. }
  156. if(address != "") {
  157. address = " | " + address;
  158. }
  159. var li = document.createElement('li');
  160. li.className = 'mui-table-view-cell mui-media';
  161. li.innerHTML = '<a class="proinfor" data-id="'+item.id+'"' +
  162. '<p><img class="mui-media-object mui-pull-left headimg" src="' + img + '"></p>' +
  163. '<div class="mui-media-body">' +
  164. '<span class="listtit">' + item.name + '<em class="mui-icon iconfont icon-vip authicon"></em></span>' +
  165. '<p class="listtit2"><span>' + title + '</span><span>' + office + '</span><span>' + orgName + '</span><span>' + address + '</span></p>' +
  166. '<p class="mui-ellipsis listtit3">' + rlist + '</p>' +
  167. '<p class="mui-ellipsis listtit3">' + zlist + '</p>' +
  168. '</div></a></li>';
  169. table.appendChild(li, table.firstChild);
  170. });
  171. }