Nenhuma Descrição

index.js 4.4KB

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