jianjiaotuisong.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. // 基本信息(包括userAgent)
  2. var baseInfo = null,
  3. //滚动条
  4. scroller1=null,
  5. // 基础环境信息(包括当前webview)
  6. baseEnv = null,
  7. page = 1,
  8. iscroller,
  9. patient = null;
  10. //搜索输入框
  11. var $searchbarInput = $('.search-input'),
  12. //文章列表
  13. $articleList = $("#jjts-category-ul");
  14. var self;
  15. var mscrolls = [];
  16. var pagesize = 10;
  17. var $eventListWrapper = $('#jjts-content');
  18. var $noResultWrap = $('#no_result_wrap');
  19. var $sliderSegmentedControl = $("#sliderSegmentedControl");
  20. // 获取登录相关信息
  21. var getBaseInfo = function() {
  22. // 登录的相关信息
  23. var userAgent = JSON.parse(plus.storage.getItem("userAgent"))
  24. return {
  25. userAgent: userAgent
  26. }
  27. },
  28. // 获取基础环境信息
  29. getBaseEnvPromise = function () {
  30. var env = {
  31. webview: plus&&plus.webview.currentWebview()
  32. };
  33. var self = plus.webview.currentWebview();
  34. mui.back = function(){
  35. var opener = self.opener();
  36. if(opener.id=='p2dzixun'){
  37. mui.fire(opener, 'update');
  38. } else if(opener.id == 'fuwujilu') {
  39. mui.fire(opener, 'refresh');
  40. }
  41. self.close();
  42. }
  43. return Promise.resolve().then(function(res) {
  44. return env;
  45. });
  46. },
  47. refreshPage = function(){
  48. baseInfo = getBaseInfo();
  49. var index = $('.mui-control-item.mui-active').index();
  50. var view = $('.mui-table-view').eq(index);
  51. view.empty();
  52. var scroll = mscrolls[index];
  53. if(scroll) {
  54. scroll.pulldownLoading();
  55. }
  56. },
  57. //事件绑定
  58. bindEvents = function(){
  59. $articleList.on('tap','.content-tuisong',function() {
  60. var articleId = $(this).attr('data-id');
  61. openWebviewExtras("jianjiaotuisong-xiangqing.html",{articleId:articleId});
  62. return false;
  63. });
  64. $eventListWrapper.on('tap','.yituisong',function() {
  65. $("#slider").hide();
  66. $(".sucaiku").removeClass("show");
  67. $(".yituisong").addClass("show");
  68. getYituisongList(page,pagesize,true);
  69. $("#view_wrap").show();
  70. });
  71. $eventListWrapper.on('tap','.sucaiku',function() {
  72. $("#slider").show();
  73. $("#view_wrap").hide();
  74. $(".yituisong").removeClass("show");
  75. $(".sucaiku").addClass("show");
  76. });
  77. $sliderSegmentedControl.on('tap','.mui-control-item',function(){
  78. var index = $(this).index();
  79. var scroll = mscrolls[index];
  80. var view = $('.mui-table-view').eq(index);
  81. var isEmpty = view.find('li').length==0;
  82. if(scroll && isEmpty) {
  83. scroll.pullupLoading();
  84. }
  85. })
  86. $articleList.on('tap','.tuisong',function() {
  87. var articleId = $(this).attr('data-id');
  88. openWebviewExtras("tuisong_duixiang.html",{articleId:articleId});
  89. return false;
  90. });
  91. $searchbarInput.on('click',function() {
  92. openWebviewExtras("jianjiaotuisong_search.html");
  93. return false;
  94. });
  95. /*刷新事件*/
  96. window.addEventListener("refresh", function refresh(e) {
  97. refreshPage();
  98. });
  99. },
  100. loadListPromise = function(wheaType,page) {
  101. var url = "third/jkEdu/Article/getDoctorArticalList",
  102. params = {articleTitle: "",articleState:1,firstLevelCategoryId:wheaType,pageIndex:page,pageSize:pagesize};
  103. return new Promise(function(resolve, reject) {
  104. sendGet(url,params,function(res){
  105. if(res.msg){
  106. mui.toast(res.msg);
  107. }else{
  108. mui.toast("加载失败!");
  109. }
  110. },function(res){
  111. if(res.status==200){
  112. resolve(res.data)
  113. }else{
  114. if(res.msg){
  115. mui.toast(res.msg);
  116. }else{
  117. mui.toast("加载失败!");
  118. }
  119. }
  120. })
  121. });
  122. },
  123. initScroll = function () {
  124. //循环初始化所有下拉刷新,上拉加载。
  125. if(mscrolls.length == 0) {
  126. $.each(document.querySelectorAll('.mui-slider-group .mui-scroll-wrapper'), function(index, pullRefreshEl) {
  127. var page = 0;
  128. var wheaType= $(this).closest('.mui-slider-item').attr('data-type')||"";
  129. var pullRefresh = mui(pullRefreshEl).pullRefresh({
  130. down: {
  131. callback: function() {
  132. page = 0;
  133. var self = this;
  134. var ul = self.element.querySelector('.mui-table-view');
  135. var $scrollEl = $(ul).closest('.mui-scroll');
  136. var $noResult = $scrollEl.find('.no-result');
  137. $noResult.hide();
  138. loadListPromise(wheaType,page)
  139. .then(function(list) {
  140. plus.nativeUI.closeWaiting();
  141. if(list && list.length) {
  142. page++;
  143. setTimeout(function() {
  144. var html = template('jjts-article-list',{list: list});
  145. $(ul).html(html);
  146. self.endPulldownToRefresh(list.length < pagesize);
  147. }, 1000);
  148. } else {
  149. if(page == 0) {
  150. $noResult.show();
  151. self.endPulldownToRefresh(true);
  152. }
  153. self.endPulldownToRefresh(true);
  154. }
  155. })
  156. .catch(function(e) {
  157. console && console.error(e)
  158. })
  159. }
  160. },
  161. up: {
  162. callback: function() {
  163. var self = this;
  164. var ul = self.element.querySelector('.mui-table-view');
  165. var $scrollEl = $(ul).closest('.mui-scroll');
  166. var $noResult = $scrollEl.find('.no-result');
  167. loadListPromise(wheaType,page)
  168. .then(function(list) {
  169. if(list && list.length) {
  170. page++;
  171. setTimeout(function() {
  172. var html = template('jjts-article-list',{list: list});
  173. $(ul).append(html);
  174. self.endPullupToRefresh(list.length < pagesize);
  175. }, 1000);
  176. } else {
  177. if(page == 0) {
  178. $noResult.show();
  179. }
  180. self.endPullupToRefresh(true);
  181. }
  182. })
  183. .catch(function(e) {
  184. console && console.error(e)
  185. })
  186. }
  187. }
  188. });
  189. mscrolls.push(pullRefresh)
  190. });
  191. }
  192. }
  193. function initTuiSongScroller() {
  194. iscroller = mui("#view_wrap.mui-scroll-wrapper").pullRefresh({
  195. up: {
  196. callback: function() {
  197. page++;
  198. getYituisongList(page,10);
  199. this.endPullupToRefresh();
  200. }
  201. },
  202. down: {
  203. callback: function() {
  204. var self1 = this;
  205. page = 1;
  206. getYituisongList(1,pagesize,true);
  207. self1.endPulldownToRefresh();
  208. }
  209. }
  210. });
  211. }
  212. function getYituisongList(pageNum,pageSize,isInit){
  213. var url = "doctor/jkEdu/article/pushArticleList",
  214. params = {page: pageNum,pagesize: pageSize};
  215. plus.nativeUI.showWaiting();
  216. sendGet(url, params, null, function(res){
  217. if(res.status==10000){
  218. plus.nativeUI.closeWaiting();
  219. var list = res.result;
  220. if(list.length == 0) {
  221. if(isInit){
  222. $eventListWrapper.hide();
  223. $noResultWrap.show();
  224. }else{
  225. iscroller.endPullupToRefresh(true);
  226. }
  227. } else {
  228. $noResultWrap.hide();
  229. $eventListWrapper.show();
  230. var html = template('yituisong-tmp', {list:list});
  231. if(isInit) {
  232. $("#jktj_list").html(html);
  233. if(res.result.length == pageSize){
  234. iscroller.finished = false;
  235. }
  236. } else {
  237. $("#jktj_list").append(html)
  238. }
  239. if(res.result && res.result.length < pageSize) {
  240. iscroller.endPullupToRefresh(true);
  241. }else{
  242. iscroller.endPullupToRefresh(true);
  243. }
  244. }
  245. initTuiSongScroller();
  246. } else {
  247. plus.nativeUI.closeWaiting();
  248. mui.toast("数据获取失败");
  249. }
  250. });
  251. }
  252. // 页面业务处理流程开始
  253. new Promise(function(resolve, reject) {
  254. // TODO 临时放开
  255. //resolve(true);
  256. mui.plusReady(function() {
  257. // hrefhrefplus已经准备好,可以往下执行
  258. resolve(true);
  259. });
  260. }).then(function() {
  261. // 获取基础环境信息
  262. return getBaseEnvPromise().then(function(env) {
  263. baseEnv = env;
  264. }).then(function() {
  265. // 获取登录基本信息
  266. baseInfo = getBaseInfo();
  267. var self = plus.webview.currentWebview();
  268. getCategoryList();
  269. // 绑定页面事件
  270. bindEvents();
  271. $('.mui-control-item.mui-active').trigger('tap');
  272. })
  273. }).catch(function(e) {
  274. plus.nativeUI.closeWaiting();
  275. console && console.error(e);
  276. });
  277. template.helper("setPhoto", function(p) {
  278. return getImgUrl(p);
  279. });
  280. //获取文章分类(一级标题)
  281. getCategoryList = function () {
  282. var url = "third/jkEdu/Article/getCategoryList",
  283. params = {categoryLevel: 1};
  284. plus.nativeUI.showWaiting();
  285. sendGet(url, params, null, function(res){
  286. if(res.status==200){
  287. plus.nativeUI.closeWaiting();
  288. var list = res.data;
  289. if(list.length == 0) {
  290. $eventListWrapper.hide();
  291. $noResultWrap.show();
  292. } else {
  293. $noResultWrap.hide();
  294. $eventListWrapper.show();
  295. var html = template('categoryList', {list:list});
  296. $("#sliderSegmentedControl").html(html);
  297. var html2 = template('jjts-article-ul', {list:list});
  298. $("#jjts-category-ul").html(html2);
  299. initScroll();
  300. initTuiSongScroller();
  301. mui('#slider').slider({
  302. interval:0//自动轮播周期,若为0则不自动播放,默认为0;
  303. });
  304. }
  305. } else {
  306. $eventListWrapper.hide();
  307. $noResultWrap.show();
  308. mui.toast(res.msg);
  309. }
  310. });
  311. }