No Description

index.js 5.3KB

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