| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377 | 
							-     // 基本信息(包括userAgent)
 
- var baseInfo = null,
 
- 	//滚动条
 
- 	scroller1=null,
 
-     // 基础环境信息(包括当前webview)
 
-     baseEnv = null,
 
-     
 
-     patient = null,
 
-     
 
-     patientName ="";
 
-     //搜索输入框
 
- var $searchInput = $(".search-input"),
 
-     //文章列表
 
-     $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()
 
-     };
 
- 	var self = plus.webview.currentWebview();
 
- 	mui.back = function(){
 
- 		var opener = self.opener();
 
- 		if(opener.id=='p2dzixun'){
 
- 			mui.fire(opener, 'update');
 
- 		} else if(opener.id == 'fuwujilu') {
 
- 			mui.fire(opener, 'refresh');
 
- 		}
 
- 		self.close();
 
- 	}
 
-     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();
 
- 	}
 
- },
 
- 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("收藏成功");
 
- 		}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("/doctor/health/edu/uncollectionArticle",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("取消收藏成功");
 
- 		}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();
 
- 		}
 
- 	});
 
- 	
 
- 	$('#recordsLink').on('tap',function() {
 
- //		openWebviewExtras("fasongjilu.html");
 
- 		openWebviewExtras("myArticle.html");
 
- 	});
 
- 	
 
- 	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) {
 
- 		sendPost("/doctor/health/edu/list",{
 
- 			patient: patient || "",
 
- 			wheaType: wheaType,
 
- 			page: 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("加载失败!");
 
- 		    	}
 
- 	    	}
 
- 	    }) 
 
- 	});
 
- },
 
- 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('<div class="sent-flag"><span class="c-fff c-f14 ml10">已发送</span></div>');
 
-             var num = $this.find(".send_count").text();
 
-             $this.find(".send_count").text(parseInt(num)+1);
 
-         }else{
 
-             sendError(res);
 
-         }
 
-         plus.nativeUI.closeWaiting();
 
-     });
 
- },
 
- sendError = function (res){
 
- 	plus.nativeUI.closeWaiting();
 
- 	if(res.msg){
 
- 		mui.toast(res.msg);
 
- 	}else{
 
- 		mui.toast("发送失败!");
 
- 	}  	
 
- },
 
- sendSuccess = function (res){
 
- 	plus.nativeUI.closeWaiting();
 
- 	if(res.status==200){
 
- 		mui.toast("发送成功!");
 
- 		var view  = plus.webview.getWebviewById("jiankangjiaoyu");
 
- 		if(view){
 
- 			mui.fire(view,"refresh");
 
- 		}
 
- 		view=plus.webview.getWebviewById("article");
 
- 		if(view){
 
- 			mui.fire(view,"refresh");
 
- 			openWebviewExtras("article.html",{article:article,patient:patient,patientName:self.patientName});
 
- 		}else{
 
- 			openWebviewExtras("jiankangjiaoyu.html",{patient:patient,patientName:self.patientName});
 
- 		}
 
- 		
 
- 	}else{
 
- 		sendError(res);
 
- 	}
 
- },
 
- showDialog = function (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();
 
- };
 
-     
 
- // 页面业务处理流程开始
 
- new Promise(function(resolve, reject) {
 
-     // TODO 临时放开
 
-     //resolve(true);
 
- 	
 
-     mui.plusReady(function() {
 
-         // hrefhrefplus已经准备好,可以往下执行
 
-         resolve(true);
 
-     });
 
- }).then(function() {
 
-     
 
-     // 获取基础环境信息
 
-     return getBaseEnvPromise().then(function(env) {
 
-         baseEnv = env;
 
-     }).then(function() {
 
-         // 获取登录基本信息
 
-         baseInfo = getBaseInfo();
 
-         var self = plus.webview.currentWebview();
 
-         patient = self.patient;
 
-         patientName = self.patientName;
 
-         initScroll();
 
-         // 绑定页面事件
 
-         bindEvents(); 
 
-         
 
-         var openerId = self.opener().id;
 
-         if(openerId=="home2.html") { // 首页进入
 
-         	$('#recordsLink').show();
 
-         }
 
-         $('.mui-control-item.mui-active').trigger('tap');
 
-     })
 
- }).catch(function(e) {
 
-     plus.nativeUI.closeWaiting();
 
-     console && console.error(e);
 
- });
 
- template.helper("setPhoto", function(p) {		
 
- 	return getImgUrl(p);
 
- });
 
 
  |