mui.init(); var page = 0, pageSize = 10, patient, patientName, isAdmin, pCodes, referrer; var back = mui.back; mui.back = function(){ var self = plus.webview.currentWebview(), opener = self.opener(); if(opener){ mui.fire(opener, 'reload'); } back(); } mui.plusReady(function(){ var self = plus.webview.currentWebview(); isAdmin = self.isAdmin; patient = self.patient; patientName = self.patientName; pCodes = self.pCodes; referrer = self.referrer; getList(true); initScroller(); bindEvents(); }); function getList(isInit){ if(isInit){ page = 0; } var url = "/third/jkEdu/Article/getCollectionArticalList", params = { articleState: 1, // 1-正常,2-删除,3-草稿 pageIndex: page, pageSize: pageSize, userType: 1 //1医生,2居民 }; if(patient){ params.patient = patient; } sendGet(url, params, null, function(res){ if(res.status == 200){ if(isInit && res.data.length == 0){ $("#articleList").hide(); $(".no-result").show(); }else{ var html = template('li-tmp', {list : res.data}); if(isInit){ $("#articleList").empty().append(html); }else{ $("#articleList").append(html); } if(res.data.length < pageSize){ mui('.mui-scroll-wrapper').pullRefresh().endPullupToRefresh(true); }else{ mui('.mui-scroll-wrapper').pullRefresh().endPullupToRefresh(false); page ++; } } }else{ mui.toast(res.msg); } }, true); } /* * 取消收藏文章 */ function unCollectionArticle(code,$this){ plus.nativeUI.showWaiting(); var params = {}; params.articleId=code; params.userType = 1; //1医生,2居民 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){ var $li = $this.closest('.article-li'); $li.remove(); plus.nativeUI.toast("取消收藏成功"); var $lis = $(".article-li"), len = $lis.length; if(len == 0){ $("#articleList").hide(); $(".no-result").show(); } }else{ if(res.msg){ plus.nativeUI.toast(res.msg); }else{ plus.nativeUI.toast("取消收藏失败!"); } } }) } //弹框提示是否发送给居民 function showDialog(article,title,patientName) { dialog({ title: '
发送给
'+patientName+'
', content: '
《'+title+'》
', okValue: '立即发送', cancelValue: '我再看看', cancel: function () { return; }, ok: function() { send(article); } }).showModal(); } //发送文章给患者 function send(article){ var url = "/doctor/jkEdu/article/doctorSendArticleToPatients", params = { articleId: article, patient: patient, leaveWords: $.trim($('#messageInput').val()) }; if(pCodes){ params.patient = pCodes.join(","); } var docInfo = JSON.parse(plus.storage.getItem('docInfo')); params.currentUserRole = docInfo.hospital; params.currentUserRoleLevel = 4; plus.nativeUI.showWaiting(); sendPost(url, params, null, function(res){ if(res.status == 10000){ mui.toast("发送成功!"); var $this = $(".share[data-code="+article+"]"); if(!pCodes){ $this.after('
已发送
'); } var num = $this.find(".send_count").text(); $this.find(".send_count").text(parseInt(num)+1); if(referrer == "manbing"){ var self = plus.webview.currentWebview(), selfId = self.id; backToManbingPage(self, selfId); } }else{ if(res.msg){ mui.toast(res.msg); }else{ mui.toast("发送失败!"); } } plus.nativeUI.closeWaiting(); }); } function bindEvents(){ $("#articleList").on('tap', ".article-info", function(e){ e.stopPropagation(); var code = $(this).attr("data-article-code"); var title = $(this).attr('data-title'); if(isAdmin){ openWebviewExtras("../../home/html/jianjiaotuisong-xiangqing.html",{articleId:code}); }else{ openWebview("article-info.html", { articleId:code, patient: patient, patientName: patientName, pCodes: pCodes, showHandleBar: true, referrer: referrer }) } return false; }).on('tap','div.collect', function(e){ e.stopPropagation(); var $this = $(this); var code = $this.attr("data-code"); unCollectionArticle(code,$this); }).on('tap','div.share', function(e){ e.stopPropagation(); var $this = $(this); var code = $this.attr("data-code"); var title = $this.attr("data-title"); if(isAdmin){ openWebviewExtras("../../home/html/tuisong_duixiang.html",{articleId:code}); }else{ if(!patient){ if(pCodes){ dialog({ title: '
发送给
'+pCodes.length+'人
', content: '
《'+title+'》
', okValue: '立即发送', cancelValue: '我再看看', cancel: function () { return; }, ok: function() { send(code); } }).showModal(); return false; }else{ openWebview("xuanzejumin_more.html", { article: code, articleTitle: title, origin: 'jiaoyu' }); } }else{ showDialog(code,title,patientName); } } }); template.helper("setContent", function(str){ if(str){ var reg=/<[^<>]+>/g; str = str.replace(reg, ''); return str; }else{ return ""; } }); template.helper("getArticleImage", function(str){ if(str){ if(str.indexOf("../") > -1){ return ""; //原福州代码中返回的相对路径 } var url = getImgUrl(str); return ""; } return ""; }) window.addEventListener("refresh", function(e){ getList(true); }) } function initScroller(){ //阻尼系数 var deceleration = mui.os.ios?0.003:0.0009; mui('.mui-scroll-wrapper').scroll({ bounce: false, indicators: true, //是否显示滚动条 deceleration:deceleration }); mui('.mui-scroll-wrapper').pullRefresh({ down: { callback: function(){ getList(true); this.endPulldownToRefresh(); } }, up: { callback: function(){ var self = this; setTimeout(function(){ getList(false); self.endPullupToRefresh(); }, 500); } } }); } function backToManbingPage(wv, selfId){ var targetId = "zhongdiangenzong"; if(wv.id == targetId){ setTimeout(function(){ plus.webview.getWebviewById(selfId).close(); }, 300); }else{ var opener = wv.opener(); if(wv.id != selfId){ wv.close(); } backToManbingPage(opener, selfId); } }