// 基本信息(包括userAgent) var baseInfo = null, //滚动条 scroller1=null, // 基础环境信息(包括当前webview) baseEnv = null, patient = null, patientName =""; var $articleList = $(".mui-table-view"); var self; var mscrolls = []; var pagesize = 10; // 获取登录相关信息 var getBaseInfo = function() { // 登录的相关信息 var userAgent = JSON.parse(plus.storage.getItem("userAgent")) return { userAgent: userAgent } }, // 获取基础环境信息 getBaseEnvPromise = function () { var env = { webview: plus&&plus.webview.currentWebview() }; return Promise.resolve().then(function(res) { return env; }); }, refreshPage = function(){ baseInfo = getBaseInfo(); var index = $('.mui-control-item.mui-active').index(); var view = $('.mui-table-view').eq(index); view.empty(); var scroll = mscrolls[index]; if(scroll) { scroll.pulldownLoading(); } }, resPage = function(){ var view = plus.webview.getWebviewById("jiankangjiaoyu"); if(view){ mui.fire(view,"refresh"); } var my_store = plus.webview.getWebviewById("my_store"); if(my_store){ mui.fire(my_store,"refresh"); } }, collectionArticle=function(code,$this){ plus.nativeUI.showWaiting(); var params = {}; params.article=code; sendPost("/doctor/health/edu/collectionArticle",params,function(res){ plus.nativeUI.closeWaiting(); if(res.msg){ plus.nativeUI.toast(res.msg); }else{ plus.nativeUI.toast("收藏失败!"); } },function(res){ plus.nativeUI.closeWaiting(); if(res.status==200){ $this.attr("data-status", 1); $this.find("img").attr("src", "../images/shoucang_pre.png"); var span = $this.find("span"); var collectNum = parseInt(span.html()); span.html(collectNum+1); plus.nativeUI.toast("收藏成功"); resPage(); }else{ if(res.msg){ plus.nativeUI.toast(res.msg); }else{ plus.nativeUI.toast("收藏失败!"); } } }) }, unCollectionArticle=function(code,$this){ plus.nativeUI.showWaiting(); var params = {}; params.article=code; sendPost("/third/jkEdu/Article/cancelArticleCollection",params,function(res){ plus.nativeUI.closeWaiting(); if(res.msg){ plus.nativeUI.toast(res.msg); }else{ plus.nativeUI.toast("取消收藏失败!"); } },function(res){ plus.nativeUI.closeWaiting(); if(res.status==200){ $this.attr("data-status", 0); $this.find("img").attr("src", "../images/shoucang_button.png"); var span = $this.find("span"); var collectNum = parseInt(span.html()); span.html(collectNum-1); plus.nativeUI.toast("取消收藏成功"); resPage(); }else{ if(res.msg){ plus.nativeUI.toast(res.msg); }else{ plus.nativeUI.toast("取消收藏失败!"); } } }) }, //事件绑定 bindEvents = function(){ $(".header-link").on("click",'.shoucang-btn',function(){ openWebviewExtras("my_store.html",{patient:patient,patientName:self.patientName}); }) .on("click",'.search-btn',function(){ openWebviewExtras("search_article.html",{type:0,patient:patient,patientName:self.patientName}); }) $articleList.on('tap','li .article-info',function() { var code = $(this).attr("data-article-code"); var title = $(this).attr('data-title'); openWebviewExtras("article.html",{article:code,patient:patient,patientName:self.patientName}); return false; }).on('tap','div.collect', function(){ var $this = $(this); var status = $this.attr("data-status"); var code = $this.attr("data-code"); if(status == 0){ collectionArticle(code,$this); }else{ unCollectionArticle(code,$this); } }).on('tap','div.share', function(){ var $this = $(this); var code = $this.attr("data-code"); var title = $this.attr("data-title"); if(!patient){ openWebviewExtras("xuanzejumin_more.html",{article:code,origin:'jiaoyu',articleTitle:title,patientName:self.patientName}); }else{ showDialog(code,title,patientName); } }); $('.mui-control-item').on('tap',function() { var index = $(this).index(); var scroll = mscrolls[index]; var view = $('.mui-table-view').eq(index); var isEmpty = view.find('li').length==0; if(scroll && isEmpty) { scroll.pullupLoading(); } }); document.querySelector('.mui-slider').addEventListener('slide', function(event) { $('.mui-control-item').eq(event.detail.slideNumber).trigger('tap'); }); /*刷新事件*/ window.addEventListener("refresh", function refresh(e) { refreshPage(); }); }, loadListPromise = function(wheaType,page) { return new Promise(function(resolve, reject) { sendGet("/third/jkEdu/Article/getCollectionArticalList",{ articleState: 1, // 1-正常,2-删除,3-草稿 patient: patient || "", pageIndex: page, pageSize: pagesize },function(res){ if(res.msg){ mui.toast(res.msg); }else{ mui.toast("加载失败!"); } },function(res){ if(res.status==200){ resolve(res.list) }else{ if(res.msg){ mui.toast(res.msg); }else{ mui.toast("加载失败!"); } } }) }, true); }, initScroll = function () { //循环初始化所有下拉刷新,上拉加载。 if(mscrolls.length == 0) { $.each(document.querySelectorAll('.mui-slider-group .mui-scroll-wrapper'), function(index, pullRefreshEl) { var page = 1; var wheaType= $(this).closest('.mui-slider-item').attr('data-type')||""; var pullRefresh = mui(pullRefreshEl).pullRefresh({ down: { callback: function() { page = 1; var self = this; var ul = self.element.querySelector('.mui-table-view'); var $scrollEl = $(ul).closest('.mui-scroll'); var $noResult = $scrollEl.find('.no-result'); $noResult.hide(); loadListPromise(wheaType,page) .then(function(list) { plus.nativeUI.closeWaiting(); if(list && list.length) { page++; setTimeout(function() { var html = template('articleimgLi',{list: list}); $(ul).html(html); self.endPulldownToRefresh(list.length < pagesize); }, 1000); } else { if(page == 1) { $noResult.show(); self.endPulldownToRefresh(true); } self.endPulldownToRefresh(); } }) .catch(function(e) { console && console.error(e) }) } }, up: { callback: function() { var self = this; var ul = self.element.querySelector('.mui-table-view'); var $scrollEl = $(ul).closest('.mui-scroll'); var $noResult = $scrollEl.find('.no-result'); loadListPromise(wheaType,page) .then(function(list) { if(list && list.length) { page++; setTimeout(function() { var html = template('articleimgLi',{list: list}); $(ul).append(html); self.endPullupToRefresh(list.length < pagesize); }, 1000); } else { if(page == 1) { $noResult.show(); } self.endPullupToRefresh(true); } }) .catch(function(e) { console && console.error(e) }) } } }); mscrolls.push(pullRefresh) }); } }, send = function(article){ var params = {}; params.code =article; params.patient=patient; //params.teamCode=1; params.attachedContent = $.trim($('#messageInput').val()); plus.nativeUI.showWaiting(); sendPost("/doctor/jkEdu/article/doctorSendArticleToPatients",params,sendError,function(res){ if(res.status == 200){ mui.toast("发送成功!"); var $this = $("[data-code="+article+"]"); $this.append('