| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432 | 
							- // TODO 临时构造plus对象,使得能够在浏览器中进行调试
 
- //var plus = null;
 
- 	// 登录者相关信息(包括userAgent)
 
- var loginerInfo = null,
 
- 	// 基础环境信息(包括当前webview)
 
- 	baseEnv = null,
 
- 	self = null,
 
- 	myScroll,
 
- 	imMessages,
 
- 	searchPage3,
 
- 	searchPage4,
 
- 	pageType,
 
- 	docInfo = null;
 
- 	
 
- 	
 
- 	// 搜索框
 
- var $searchbar = $('.searchbar'),
 
- 	// 搜索输入框
 
- 	$searchbarInput = $('.lin-search-ipt input'),
 
- 	// 搜索取消按钮
 
- 	$searchCancelBtn = $('.searchbar-cancel'),
 
- 	// 搜索框下面悬浮的搜索提示
 
- 	$searchSuggest = $('#search_suggest_text'),
 
- 	// 搜索结果展示容器
 
- 	$searchtResult = $('#search_result'),
 
- 	// 搜索无结果时显示
 
- 	$noResultWrap = $('#no_result_wrap'),
 
- 	$doingWrapper = $('#doing_wrapper'),
 
- 	$doingList = $('#doing_list');
 
- 	
 
- 	mui.plusReady(function() {
 
- 	 	self = plus.webview.currentWebview();
 
-     
 
- 		searchPage3 = plus.webview.getWebviewById('sousuosimpleliaotianjilu');
 
- 		if(searchPage3){
 
- 			searchPage3.hide();
 
- 		}else{
 
- 			searchPage3 = mui.preload({
 
- 				id:"sousuosimpleliaotianjilu",
 
- 			    url: 'sousuosimpleliaotianjilu.html'
 
- 			});
 
- 		}
 
- 		
 
- 		searchPage4 = plus.webview.getWebviewById('sousuosimpleliaotianjilu-ys');
 
- 		if(searchPage4){
 
- 			searchPage4.hide();
 
- 		}else{
 
- 			searchPage4 = mui.preload({
 
- 				id:"sousuosimpleliaotianjilu-ys",
 
- 			    url: 'sousuosimpleliaotianjilu-ys.html'
 
- 			});
 
- 		}
 
- 	
 
- });
 
- document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
 
- window.addEventListener("initSearch", function(e){
 
- 	imMessages = e.detail.imMessages;
 
- 	openSoftKeyboard();
 
- 	pageType = e.detail.pageType;
 
- 	setTimeout(function(){
 
- 		$doingList.html("");
 
- 		$("#searchPut").val(e.detail.kw);
 
- 		$("#searchPut").focus();
 
- 		$searchSuggest.trigger("click");
 
- 	},500)
 
- })
 
- // 获取登录相关信息
 
- var getLoginerInfo = function() {
 
- 		// 登录的相关信息
 
- 	var userAgent = plus && 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;
 
- 	});
 
- },
 
- // $el: $('.c-content-warp')
 
- getRowProps = function ($el) {
 
- 	var $textEllipsis = $el.find('.j-text-ellipsis'),
 
- 		$text = $textEllipsis.eq(0),
 
- 		$chart = $text.text('a'),
 
- 		enWidth = $chart.width(),
 
- 		$chart = $text.text('中'),
 
- 		zhWidth = $chart.width(),
 
- 		lineHeight = parseFloat($chart.css("lineHeight"), 10),
 
- 		rowHeight = $chart.height();
 
- 	$chart.text('');
 
- 	return {
 
- 		chartWidth: {
 
- 			zh: zhWidth,
 
- 			en: enWidth
 
- 		},
 
- 		rowHeight: Math.max(rowHeight, lineHeight),
 
- 		rowWidth: $el.width()
 
- 	};
 
- },
 
- replaceAll = function (text, arr) {
 
- 	var html = text;
 
- 	_.each(arr,function(kw) {
 
- 		var reg = new RegExp(kw+"(?!>)","gi");
 
- 		html = html.replace(reg,'<em>'+kw+'</em>');
 
- 	});
 
- 	return html;
 
- },
 
- highlineKeyword = function ($el,searchText) {
 
- 	var props = getRowProps($el),
 
- 		chartWidth = props.chartWidth,
 
- 		rowHeight = props.rowHeight,
 
- 		rowWidth = props.rowWidth,
 
- 		// 每行显示字符数(以中文字符为标准计算)
 
- 		chartNum = Math.floor(rowWidth / chartWidth.zh),
 
- 		// 排除“咨询问题:”字符及前后“...”所占宽度
 
- 		exceptNum = 7,
 
- 		// 行数
 
- 		rowNum = 1,
 
- 		// 预计显示总字符数
 
- 		expectedNum = chartNum * rowNum - exceptNum,
 
- 		$target = $el.find('.j-text-ellipsis'),
 
- 		// 目标文本
 
- 		text = $target.attr('data-text').trim(),
 
- 		length = text.length,
 
- 		// 关键字数组
 
- 		kws = searchText.trim().replace(/\s+/g," ").split(" ");
 
- 	var fidx = 0,preFidx,diff = 0;
 
- 	$target.html(replaceAll(text, kws));
 
- 	if(Math.ceil($target.height() / rowHeight) <= rowNum) {
 
- 		return ;
 
- 	}
 
- 	if(text.length > expectedNum) {
 
- 		fidx = text.indexOf(kws[0])+kws[0].length-1;
 
- 		diff = fidx - expectedNum + 1;
 
- 		preFidx =  fidx;
 
- 		diff = (diff<0)?0:diff;
 
- 		var preChar = (diff>0)?"...":"";
 
- 		$target.html(preChar+replaceAll(text.slice(diff,preFidx+1), kws)+"...");
 
- 		while((Math.ceil($target.height() / rowHeight) <= rowNum) && (preFidx < length)) {
 
- 			preFidx++;
 
- 			$target.html(preChar+replaceAll(text.slice(diff,preFidx+1), kws)+"...");
 
- 		}
 
- 		if(preFidx == length && (Math.ceil($target.height() / rowHeight) <= rowNum)) {
 
- 			diff = diff>0?(diff - 1):0;
 
- 			$target.html(preChar+replaceAll(text.slice(diff,preFidx), kws));
 
- 		} else if((Math.ceil($target.height() / rowHeight) > rowNum)) {
 
- 			$target.html(preChar+replaceAll(text.slice(diff,preFidx), kws)+"...");
 
- 		}
 
- 	}
 
- },
 
- ellipsisText = function ($elements, searchText) {
 
- 	//$el.ellipsis({ row: 2});
 
- 	_.each($elements,function(el) {
 
- 		highlineKeyword($(el),searchText)
 
- 	});
 
- },
 
- // 控制搜索关键字悬浮提示的显示
 
- showSearchSuggest = function(text) {
 
- 	var suggestText = '搜索“'+text+'”';
 
- 	// 如果text不为空,则显示;否则隐藏
 
- 	if(text&&text.trim().length) {
 
- 		$searchSuggest.text(suggestText);
 
- 		$searchSuggest.show();
 
- 	} else {
 
- 		$searchSuggest.text('');
 
- 		$searchSuggest.hide();
 
- 	}
 
- },
 
- setPhoto = function(groupPhoto){
 
- 	var images = '';
 
- 		var cssArr=null;
 
- 		if(groupPhoto.length>=5){
 
- 			cssArr = ["top: 0;left: 50%;margin-left: -8px;","top: 12px;left: 2px;","top: 12px;left: 28px;","top: 27px;left: 5px;","top: 27px;left: 24px;"];
 
- 		}else if(groupPhoto.length==4){
 
- 			cssArr = ["top: 5px;left: 3px;","top: 5px;left: 25px;","top: 27px;left: 3px;"," top: 27px;left: 25px;"];
 
- 		}else if(groupPhoto.length==3){
 
- 			cssArr = ["top: 5px;left: 50%;margin-left: -10px;","top: 20px;left: 3px;","top: 20px;left: 25px;"];
 
- 		}else if(groupPhoto.length==2){
 
- 			cssArr = ["top: 5px;left: 50%;margin-left: -10px;"," top: 19px;left: 24px;"];
 
- 		}else if(groupPhoto.length==1 || groupPhoto.length==0){
 
- 			cssArr = ["position: absolute;width: 50px;height: 50px;border-radius: 50px;background-size: 50px;overflow: hidden;"];
 
- 		}
 
- 		for(var i in groupPhoto){
 
- 			if(i>4) break;
 
- 			if(groupPhoto[i].avatar){
 
- 				images+='<div class="div-image" style="'+cssArr[i]+'">'+
 
- 							'<img src="'+getImgUrl(groupPhoto[i].avatar)+'"/>'+
 
- 						'</div>';
 
- 			}else{
 
- 				if(groupPhoto[i].role=="doctor"){
 
- 					images+='<div class="div-image" style="'+cssArr[i]+'">'+
 
- 								'<img src="../../../images/d-default.png"/>'+
 
- 							'</div>';
 
- 				}else{
 
- 					images+='<div class="div-image" style="'+cssArr[i]+'">'+
 
- 								'<img src="../../../images/p-default.png"/>'+
 
- 							'</div>';
 
- 				}
 
- 				
 
- 			}
 
- 		} 
 
- 		return images;
 
- },
 
- // 初始化视图列表
 
- initDoingViewList = function(chatList) {
 
- 	var searchText = $searchbarInput.val().trim();
 
- 	template.helper("setAge", function(timestamp) {
 
- 		return calcAge(timestamp);
 
- 	});
 
- 	console.error(chatList)
 
- 	var html = template("ltjl_li_tmpl", {list: chatList,pageType:pageType});
 
- 	$doingList.html(html);
 
- 	myScroll.refresh();
 
- 	ellipsisText($doingList.find('.c-content-warp'),searchText);
 
- 	plus.nativeUI.closeWaiting();	
 
- 	loadPhoto();
 
- },
 
- loadPhoto = function(){
 
- 	$.each($('#doing_list li'), function(i, v) {
 
- 		var sesType = $(v).attr('data-session-type');
 
- 		var busType = $(v).attr('data-business-type');
 
- 		imClient.Sessions.getParticipantsAvatars($(v).attr('data-code'), function(rs){
 
- 			if(rs.length>0){
 
- 				var $photo = $(v).find('.c-avatar-m');
 
- 				if(sesType==1 || sesType==3){
 
- 					$photo.html(setPhoto(rs));
 
- 				} else {
 
- 					for(var k in rs){
 
- 						if(docInfo.code != rs[k].id){
 
- 							$photo.html('<img src="'+ getImgUrl(rs[0].avatar) +'">');
 
- 							break;
 
- 						}
 
- 					}
 
- 				}
 
- 			}
 
- 		}, function(){
 
- 			
 
- 		})
 
- 	});
 
- },
 
- // 搜索框搜索执行方法
 
- search = function () {
 
- 	plus.nativeUI.showWaiting();
 
- 	var kw = $searchbarInput.val().trim();
 
- 	if(pageType=="1"){//pageType:1居民 2医生
 
- 		im.getSearchPatientAll(docInfo.code,kw,"3",docInfo.level, function(res){
 
- 			if(res.length==0) {
 
- 				$noResultWrap.show();
 
- 				$searchtResult.hide();
 
- 				plus.nativeUI.closeWaiting();
 
- 			} else {
 
- 				$noResultWrap.hide();
 
- 				$searchtResult.show();
 
- 				$doingWrapper.show();
 
- 				initDoingViewList(res);
 
- 				
 
- 			}
 
- 		});
 
- 	}else{
 
- 		imClient.Search.searchMessages(docInfo.code, kw, 1, 100,function(res){
 
- 			if(res.length==0) {
 
- 				$noResultWrap.show();
 
- 				$searchtResult.hide();
 
- 				plus.nativeUI.closeWaiting();
 
- 			} else {
 
- 				$noResultWrap.hide();
 
- 				$searchtResult.show();
 
- 				$doingWrapper.show();
 
- 				initDoingViewList(res);
 
- 				
 
- 			}
 
- 		});
 
- 	}
 
- 		
 
- },
 
- calcAge = function(timestamp){
 
- 	var date = new Date(timestamp);
 
- 	Y = date.getFullYear() + '-';
 
- 	M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
 
- 	D = date.getDate() < 10 ?'0'+date.getDate():date.getDate();
 
- 	var birthday = Y+M+D; 
 
- 	var r   =   birthday.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);     
 
-     if(r==null)return   false;     
 
-     var d= new   Date(r[1],   r[3]-1,   r[4]);     
 
-     if(d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]){   
 
-           var   Y   =   new   Date().getFullYear();   
 
-           return (Y-r[1]);   
 
-     }   
 
- }
 
- // 绑定页面事件
 
- bindEvents = function () {
 
- 	$searchbarInput.on('input', function() {
 
- 		var text = $(this).val().trim();
 
- 		$searchtResult.hide();
 
- 		$('#no_result_wrap').hide();
 
- 		showSearchSuggest(text);	
 
- 	}).on('keydown',function(e) {
 
- 		if (e.which === 13) {
 
- 			search();
 
- 		}
 
- 	});
 
- 	
 
- 	$('.lin-search-ipt a,.div-back').on('tap', function(){
 
- 		plus.webview.currentWebview().close();
 
- 	})
 
- 	
 
- 	$searchSuggest.on('click',function() {
 
- 		$searchSuggest.hide();
 
- 		search();
 
- 		$searchtResult.show();
 
- 	});
 
- 	
 
- 	$searchtResult.on('tap','li',function() {
 
- 		if(imMessages){//转发消息
 
- 			var oCode = $(this).attr("data-code");
 
- 			mui.confirm("是否确认将消息逐条转发给"+$(this).attr("data-name")+"?", "提示", ["不了,谢谢", "确认转发"], function(e) {
 
- 				if(e.index == 0) {
 
- 					
 
- 				} else {
 
- 					Promise.all(_.map(imMessages,function(msg){
 
- 						return new Promise(function(resolve, reject) {
 
- 							im.sendPrivateMsg(curDocCode, oCode, msg.content, msg.type,function() {
 
- 								resolve(true);
 
- 							},function(msg) {
 
- 								console.log(JSON.stringify(msg))
 
- 								resolve(true);
 
- 							})
 
- 						})
 
- 					})).then(function() {
 
- 						mui.fire(self.opener().opener().opener(), "revertZf");
 
- 						self.opener().opener().close();
 
- 						self.opener().close();
 
- 						self.close();
 
- 						mui.toast("转发成功");
 
- 					}).catch(function(e){
 
- 						console.log(e)
 
- 					})
 
- 				}
 
- 			})
 
- 		}else{
 
- 			var $this = $(this),
 
- 				code = $this.attr('data-code'),
 
- 				chatCode = $this.attr("data-chat"),
 
- 				name = $this.attr('data-name'),
 
- 				photo = $this.attr('data-photo'),
 
- 				sex = $this.attr('data-sex'),
 
- 				amount = $this.attr("data-amount"),
 
- 				msgId = $this.attr('data-msgId'),
 
- 				type = $this.attr('data-type');
 
- 			
 
- 				if(type=="1" && amount<=1){//医生和居民间会话
 
- 					openWebview("../../message/html/p2p.html",{otherCode: code,otherName: name,otherPhoto: photo,otherSex: sex,msgId:msgId});
 
- 				}else if(type=="1" && amount>1){
 
- 					var kw = $searchbarInput.val().trim();
 
- 					if(pageType=="1"){
 
- 						mui.fire(searchPage3, "initSearch", {kw:kw,type:type,chatCode:code});
 
- 						searchPage3.show();
 
- 					}else{
 
- 						mui.fire(searchPage4, "initSearch", {kw:kw,type:type,chatCode:code});
 
- 						searchPage4.show();
 
- 					}
 
- 					
 
- 				}else if(type=="2" && amount<=1){//群聊
 
- 					openWebview("../../message/html/qiuzhuqunliao.html",{groupName: name, groupCode: code,msgId:msgId});
 
- 				}else if(type=="2" && amount>1){
 
- 					var kw = $searchbarInput.val().trim();
 
- 					if(pageType=="1"){
 
- 						mui.fire(searchPage3, "initSearch", {kw:kw,type:type,chatCode:code});
 
- 						searchPage3.show();
 
- 					}else{
 
- 						mui.fire(searchPage4, "initSearch", {kw:kw,type:type,chatCode:code});
 
- 						searchPage4.show();
 
- 					}
 
- 				}
 
- 		}
 
- 		
 
- 	});
 
- };
 
- $(function(){
 
- //	$searchbarInput.val('').focus();
 
- 	$searchtResult.hide();
 
- })
 
- // 页面业务处理流程开始
 
- 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() {
 
- 		initKeyboardAndroid();
 
- 		// 获取登录医生信息
 
- 		loginerInfo = getLoginerInfo();
 
- 		docInfo = JSON.parse(plus.storage.getItem("docInfo"));
 
-     	myScroll = $('#search_result').lscroll();
 
-     	
 
-    	  	imMessages = self.imMessages;
 
- 		openSoftKeyboard();
 
- 		pageType = self.pageType;
 
- 		$("#searchPut").val(self.kw);
 
- 		
 
- 		// 绑定页面事件
 
- 		bindEvents();
 
- 		$searchSuggest.trigger("click");
 
- 	})
 
- }).catch(function(e) {
 
- 	plus.nativeUI.closeWaiting();
 
- 	console && console.error(e);
 
- });
 
 
  |