var articleId = null; // 是否显示底部“收藏、分享”按钮 var showHandleBar = true; var patient = null; var patientName = ""; var pCodes = [], referrer, isfromAdmin; mui.init(); mui.plusReady(function() { self = plus.webview.currentWebview(); articleId = self.articleId; patient = self.patient; var userAgent = JSON.parse(plus.storage.getItem("userAgent")); if(userAgent.observer){ isfromAdmin=true; } patientName = self.patientName; pCodes = self.pCodes; referrer = self.referrer; showHandleBar = self.showHandleBar; initPage(); bindEvents(); }) function initPage() { var url = "/third/jkEdu/Article/getArticalById", params = { articleId: articleId, userType: 1 }; plus.nativeUI.showWaiting(); sendGet(url, params, null, function(res) { if(res.status == 200) { var content = res.data.articleContent; var reg=/group1\//g; content = content.replace(reg,imgUrlDomain+ 'group1/'); var html = template("article_tmpl", { it: res.data, content: content, showHandleBar: showHandleBar}); $("#xiangqing-content").html(html); //禁止超链接执行默认行为 $("#xiangqing-content a").attr("onclick","return false"); } else { queryFailed(res); } plus.nativeUI.closeWaiting(); }); } function queryFailed(res) { if(res.msg) { plus.nativeUI.toast(res.msg); } else { plus.nativeUI.toast("加载文章失败!"); } } /* * 收藏文章 */ function collectionArticle(code,$this){ plus.nativeUI.showWaiting(); var params = {}; params.articleId = code; params.userType = 1; //1医生,2居民 sendPost("/third/jkEdu/Article/saveArticleCollection",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"); span.html('已收藏'); plus.nativeUI.toast("收藏成功"); }else{ if(res.msg){ plus.nativeUI.toast(res.msg); }else{ plus.nativeUI.toast("收藏失败!"); } } }) } /* * 取消收藏文章 */ 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){ $this.attr("data-status", 0); $this.find("img").attr("src", "../images/shoucang_button.png"); var span = $this.find("span"); span.html('收藏'); plus.nativeUI.toast("取消收藏成功"); }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("发送成功!"); 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() { $("#xiangqing-content").on('tap','.collection', function(){ if(isfromAdmin){ mui.toast("观察者模式无法收藏健康文章"); }else{ 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','.share', function(){ var $this = $(this); var code = $this.attr("data-code"); var title = $this.attr("data-title"); if(!patient){ if(isfromAdmin){ mui.toast("观察者模式无法发送健康文章"); }else{ 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); } }); //为文章内的超链接监听点击事件 $("#xiangqing-content").on('click', "a", function(){ var $this = $(this), url = $this.attr("href"); mui.openWindow({ id: "browser-page", url: "../../browser/html/browser.html", extras: { url: url } }) }) template.helper("setPhoto", function(p) { return getImgUrl(p); }); template.helper("formatDate", function(str){ if(str){ return str.substr(0,19) }else{ return ""; } }); window.addEventListener("refresh", function refresh(e) { initPage(); }); } 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); } }