123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- 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: '<div><div class="c-f18 c-17b3ec c-t-left">发送给</div><div class="mt5 c-f14 c-t-left c-909090">'+patientName+'</div></div>',
- content: '<div><div class="c-f16 c-323232 c-t-left mb10">《'+title+'》</div><input id="messageInput" class="c-f14 pl10" placeholder="给居民留言..."/></div>',
- 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: '<div><div class="c-f18 c-17b3ec c-t-left">发送给</div><div class="mt5 c-f14 c-t-left c-909090">'+pCodes.length+'人</div></div>',
- content: '<div><div class="c-f16 c-323232 c-t-left mb10">《'+title+'》</div><input id="messageInput" class="c-f14 pl10" placeholder="给居民留言..."/></div>',
- 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);
- }
- }
|