| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465 | 
							- var baseInfo = null, // 基本信息(包括userAgent)
 
-     baseEnv = null,// 基础环境信息(包括当前webview)
 
-     self;
 
-     
 
- var $searchbarInput = $('#search-input'),
 
-     $searchSuggest = $('#searchValWrap'),// 搜索框下面悬浮的搜索提示
 
-     $searchtResult = $('#search_result'),// 搜索结果展示容器
 
-     $noResultWrap = $('#no_result_wrap'),// 搜索无结果时显示
 
- 	$selectedTeamName = $('#selected_team_name'),// 所选团队的团队名称显示
 
-     $patiList = $('#pati_list');
 
- var lastId = 1,// 分页查询最后一页
 
-     search_keyword = "",
 
-     iscroller,// iscroll 滚动条实例
 
-     teamId, // 所选团队
 
-     pagesize = 15,// 每页加载数据量
 
-     hasMoreResults = false,
 
-     sendCount = 0, //记录发送人数
 
-     type,//转移或分配
 
-     docCode,//医生code
 
-     level;//2全科 3健管
 
-     
 
- // 获取登录相关信息
 
- var getBaseInfo = function() { 
 
-     var userAgent = JSON.parse(plus.storage.getItem("userAgent")); // 登录的相关信息 
 
-     self = plus.webview.currentWebview();
 
-     
 
-     docCode = self.docCode;
 
-     level = self.level;
 
-     type = self.type;
 
-     teamId = self.lastTeamId;//团队id
 
- 	
 
-     return {
 
-         userAgent: userAgent,
 
-         teamInfo: JSON.parse(plus.storage.getItem("teamInfo"))
 
-     }
 
- },
 
- // 获取基础环境信息
 
- getBaseEnvPromise = function () {
 
-     var env = {
 
-         webview: plus&&plus.webview.currentWebview()
 
-     };
 
-     return Promise.resolve().then(function(res) {
 
-         return env;
 
-     });
 
- },
 
- updateLastTeamId = function(id) {
 
-     teamId = id;
 
-     plus.storage.setItem("selectedTeamId",teamId+"");
 
- },
 
- // 初始化选择团队
 
- initTeams = function (){
 
-     template.helper("setChecked", function(id, i) {
 
-         if(teamId && teamId==id)
 
-             return "checked";
 
-         return "";
 
-     })
 
-     $('.lin-sel-group').html(template('teams_tmpl', baseInfo.teamInfo));
 
- 	var $selected = $('.lin-sel-group').find("li.checked");
 
- 	$selectedTeamName.text($selected.attr("data-name"));
 
- },
 
- showGroupSel = function() {
 
-     var isShow = isShow || $('.lin-sel-group:hidden').length != 0;
 
-     $('.lin-mask').toggle(isShow);
 
-     $('.lin-sel-group').toggle(isShow);
 
- },
 
- // 初始化“患者”视图列表
 
- initPatientViewList = function(data,keyword,isAppend) {
 
-     var html = template("pati_list_tmpl", {list: _.map(data,function(o) {
 
-         o.jsonStr = JSON.stringify(o);
 
- 		var addr = '';
 
-         if(o.address){
 
-         	addr = (o.address.indexOf(keyword) != -1) ? o.address : "";
 
-         }
 
-         var id = (o.idcard.indexOf(keyword) != -1) ? o.idcard : "";
 
-         o.labels = addr+" "+id;
 
-         return o;
 
-     })});
 
-     if(isAppend === true) {
 
-         $patiList.append(html)
 
-     } else {
 
-         $patiList.html(html);
 
-     }
 
-     ellipsisText($patiList.find('li'),keyword);
 
- },
 
- // $el: $('li')
 
- getRowProps = function ($el) {
 
-     var $textEllipsis = $el,
 
-         $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 = 0,
 
-         // 行数
 
-         rowNum = 1,
 
-         // 预计显示总字符数
 
-         expectedNum = chartNum * rowNum - exceptNum,
 
-         $target = $el,
 
-         // 目标文本
 
-         text = $.trim($target.attr('data-text')),
 
-         length = text.length,
 
-         // 关键字数组
 
-         kws = $.trim(searchText).replace(/\s+/g," ").split(" ");
 
-     var fidx = 0,preFidx,diff = 0;
 
-     $target.html(replaceAll(text, kws));
 
-     if(Math.floor($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.floor($target.height() / rowHeight) <= rowNum) && (preFidx < length)) {
 
-             preFidx++;
 
-             $target.html(preChar+replaceAll(text.slice(diff,preFidx+1), kws)+"...");
 
-         }
 
-         if(preFidx == length && (Math.floor($target.height() / rowHeight) <= rowNum)) {
 
-             diff = diff>0?(diff - 1):0;
 
-             $target.html(preChar+replaceAll(text.slice(diff,preFidx), kws));
 
-         } else if((Math.floor($target.height() / rowHeight) > rowNum)) {
 
-             $target.html(preChar+replaceAll(text.slice(diff,preFidx), kws)+"...");
 
-         }
 
-     }
 
- },
 
- ellipsisText = function ($elements, searchText) {
 
-     _.each($elements,function(el) {
 
-         var $textEl = $(el).find(".j-text-ellipsis");
 
-         _.each($textEl, function(t){
 
-             highlineKeyword($(t),searchText);
 
-         });
 
-     });
 
- },
 
- // 分页查询列表
 
- searchByPaging = function () {
 
-     search_keyword = $searchbarInput.val();
 
-     if(!$.trim(search_keyword)) {
 
-         return ;
 
-     }
 
-     plus.nativeUI.showWaiting();
 
-     // page: 分页索引,filter:搜素关键字,pagesize:每页条数
 
-     var url = type == "分配" ? '/doctor/patient_label_info/getPatientUnSign' : '/doctor/family_contract/getPatientByParams' ;
 
-     params = { page:1, filter: search_keyword, pagesize:pagesize, teamCode:teamId,doctor:docCode,level:level};
 
-     getReqPromise(url,params,'get').then(function(res){
 
-         if(res.status == 200) {
 
-             lastId = lastId+1;
 
-             if(!res.data || !res.data.length) {
 
-                 $searchtResult.hide();
 
-                 $noResultWrap.show();
 
-             } else {
 
-                 if(res.data.length < pagesize) {
 
-                     hasMoreResults = false;
 
-                 } else {
 
-                     hasMoreResults = true;
 
-                 }
 
-                 $noResultWrap.hide();
 
-                 $searchtResult.show();
 
-                 initPatientViewList(res.data,search_keyword);
 
-             }
 
-             if(!iscroller) {
 
-                 iscroller = initScroller($searchtResult,url,
 
-                 function() { // 传递分页参数
 
-                     return $.extend({},params,{page:lastId,filter:search_keyword});
 
-                 },function(res) {
 
-                     lastId =  lastId+1;     
 
-                     search_keyword = $searchbarInput.val();
 
-                     initPatientViewList(res.data,search_keyword,true);
 
-                     iscroller.refresh();
 
-                 });
 
-             }
 
-             iscroller.refresh();
 
-         } else {
 
-             plus.nativeUI.toast("搜索失败!");
 
-         }
 
-         plus.nativeUI.closeWaiting();
 
-     }).catch(function(e) {
 
-         console && console.error(e)
 
-     });
 
- },
 
- // 滚动条分页实例初始化
 
- initScroller = function($el,url,getData,pullUpAction) {
 
-     var scroller;
 
-     if(hasMoreResults) {
 
-         scroller = $el.initScroll({pullDown: false,pullUpAction: function() {
 
-             var data = getData();
 
-             getReqPromise(url,data,'get').then(function(data) {
 
-                 if(pullUpAction && $.isFunction(pullUpAction)) {
 
-                     pullUpAction(data);
 
-                     console.log(data.list)
 
-                     updatePullUpText(scroller,data.list);
 
-                 }
 
-             })
 
-         }});
 
-     } else {
 
-         scroller = $el.initScroll({pullDown: false,pullUp: false});
 
-     }
 
-     
 
-     return scroller;
 
- },
 
- // 更新分页上拉加载的提示文本
 
- updatePullUpText= function(scroller,list) {
 
-     var $wrap = $(scroller.wrapper),
 
-         $pullupLabel = $wrap.find('.pullUpLabel');
 
-     if(!list || !list.length) {
 
-         $pullupLabel.text('没有更多');
 
-     } else {
 
-         $pullupLabel.text('上拉加载更多');
 
-     }
 
-     scroller.on('refresh',function() {
 
-         
 
-         if(!list || !list.length) {
 
-             $pullupLabel.text('没有更多');
 
-         } else {
 
-             $pullupLabel.text('上拉加载更多');
 
-         }
 
-     });
 
- },
 
- bindEvents = function(){
 
-     $patiList.on('tap','li[data-patient-code]',function() {  
 
-     	$searchbarInput.blur();
 
-         var $checked = $(this).find(".n-list-checked"),
 
-             isChecked = $checked.hasClass('checked');
 
-         if(isChecked){
 
-             $checked.removeClass('checked');
 
-             sendCount--;
 
-         }else{
 
-             $checked.addClass('checked');
 
-             sendCount++;
 
-         }
 
-         $("#sendCount").text(sendCount);
 
-         
 
-         if(sendCount>0){
 
- 	    	$('#sendBtn').addClass('active');//变色
 
- 	    }else{
 
- 	    	$('#sendBtn').removeClass('active');
 
- 	    }
 
-         return false;
 
-     });
 
-     
 
- //  $('.demo-comtop h1').on('click', showGroupSel);
 
- //	$('.lin-sel-group').on('click', 'li', function(){
 
- //		updateLastTeamId($(this).attr("data-code"));
 
- //		$selectedTeamName.text($(this).attr("data-name"));
 
- //		showGroupSel(undefined, false);
 
- //		if(!$(this).hasClass('checked')){
 
- //			$(this).addClass('checked').siblings().removeClass('checked');
 
- //		}
 
- //		refreshPage();
 
- //	});
 
- 	
 
- 	$("#sendBtn").on('click',function(){
 
-     	if(sendCount<=0){
 
- 			mui.toast('请至少选一个居民!');
 
- 			return;
 
- 		}
 
- 		plus.nativeUI.showWaiting();
 
- 		var patientList=[],//包含居民code和名字
 
- 			pCodeArr=[],
 
-     		pCode;
 
-     		
 
-         $(".n-list-link").each(function(){
 
-         	var d = $(this).find(".n-list-checked"),
 
-         		obj={};
 
-         	if(d.hasClass("checked")){
 
-         		obj.code = ($(this).attr("data-patient-code"));
 
-         		obj.name = ($(this).data("name"));
 
-         		patientList.push(obj);
 
-         	}
 
-         })
 
-         
 
- 		$.each(patientList, function(i, v) {
 
- 			pCodeArr.push(v.code)
 
- 		});
 
-     	//居民code字符串
 
- 		pCode = pCodeArr.join(',');
 
- 		
 
- 		if(type=='分配'){
 
- 			to_next(pCode);
 
- 			return;
 
- 		}
 
- 		sendPost("/doctor/consult/getConsultByPatientAndDoctor", {patientCode: pCode, doctor: docCode}, null, function(res){
 
- 			var tem = {};
 
- 			if(res.length==0){
 
- 				to_next(pCode);
 
- 			} else if(pCodeArr.length == res.length){
 
- 				plus.nativeUI.closeWaiting();
 
- 				mui.confirm("对不起,您选择的居民均有尚未结束的健康咨询,无法继续转移。", "提示", ["我知道了"], function(e){})
 
- 				return;
 
- 			} else if(res.length <= 3 ){
 
- 				tem = getCanTrans(patientList, res);
 
- 				mui.confirm("居民"+ tem.names + "尚有未结束的健康咨询,本次只可转移其余居民,是否继续?", "提示", ["继续转移", "不了,谢谢"], function(e){
 
- 					if(e.index == 0){
 
- 						to_next(tem.canPati);
 
- 						cancleSel(res);
 
- 					}
 
- 				})
 
- 			} else if(res.length < pCodeArr.length){
 
- 				tem = getCanTrans(patientList, res);
 
- 				mui.confirm("选中居民中有"+ res.length + "人,尚有未结束的健康咨询,本次只可转移其余居民,是否继续?", "提示", ["继续转移", "不了,谢谢"], function(e){
 
- 					if(e.index == 0){
 
- 						to_next(tem.canPati);
 
- 						cancleSel(res);
 
- 					}
 
- 				})
 
- 			} else{
 
- 				
 
- 			}
 
- 			plus.nativeUI.closeWaiting();
 
- 		})
 
- 	})
 
- 	
 
- 	function getCanTrans(patientList, notCodes){
 
- 		var canPati = [];
 
- 		var names = [];
 
- 		$.each(patientList, function(i, v) {
 
- 			var has = false;
 
- 			$.each(notCodes, function(n, m) {
 
- 				if(v.code == m){
 
- 					has = true;
 
- 					names.push(v.name);
 
- 				}
 
- 			});
 
- 			if(!has){
 
- 				canPati.push(v.code);
 
- 			}
 
- 		});
 
- 		return {canPati: canPati.join(","), names: names.join(",")}
 
- 	}
 
- 	
 
- 	function cancleSel(notCodes){
 
- 		var $ul, $prev, len;
 
- 		$.each(notCodes, function(i, c) {
 
- 			var $lis = $('#listDiv .n-list-link[data-code="'+ c +'"]');
 
- 			$.each($lis, function(i, v) {
 
- 				$(v).removeClass('checked');
 
- 				$ul = $(v).closest('ul');
 
- 				$prev = $ul.prev();
 
- 				len = $(v).closest('ul').find('li.checked').length;
 
- 				if(len==0)
 
- 					$prev.removeClass('checked').removeClass('incomplete');
 
- 				else if(len==$ul.parent().attr('data-amount'))
 
- 					$prev.removeClass('incomplete').addClass('checked');
 
- 				else
 
- 					$prev.removeClass('checked').addClass('incomplete');
 
- 			});
 
- 			removeChecked(c);
 
- 		});
 
- 		showNum();
 
- 	}
 
- 	
 
- 	function to_next(pCode){
 
- 		mui.openWindow({
 
- 			id: "choose_doctor.html",
 
- 			url: "../../tuandui/html/choose_doctor.html",
 
- 			extras: {
 
- 				teamCode: teamId,
 
- 				sendCount:sendCount,
 
- 				patients:pCode,
 
- 				level: level,
 
- 				docCode:docCode,
 
- 				type:type
 
- 			}
 
- 		})
 
- 	}
 
-    
 
-     $searchbarInput.on('input', function(){
 
-     	var $this = $(this),
 
-     		html = $this.val(),
 
-         	reg = new RegExp("<"+"(?!>)","gi");
 
- 			html = html.replace(reg,'<'); 
 
- 		var reg = new RegExp(">"+"(?!>)","gi");
 
- 			html = html.replace(reg,'>'); 
 
- 	        $('#searchVal').html(html);
 
- 	        $('.u-icon-delete').toggle($this.val() != "");
 
- 	        $searchSuggest.toggle($this.val()!="");
 
- 	        $searchtResult.hide();
 
- 	        $noResultWrap.hide();
 
- 	        $("#sendCount").text(0);
 
- 	        sendCount=0;
 
- 	        $('#sendBtn').removeClass('active');
 
-     }).on('keydown',function(e) {
 
-         if (e.which === 13) {
 
-             lastId = 1;
 
-             $searchSuggest.hide();
 
-             searchByPaging();
 
-         }
 
-     });
 
-     
 
-     $('.u-icon-delete').on('click', function(){
 
-         $(this).hide();
 
-         $searchSuggest.hide();
 
-         $searchbarInput.val("");
 
-         $('#searchVal').html("");
 
-     })
 
-     
 
-     $searchSuggest.on('click',function() {
 
-         lastId = 1;
 
-         $searchSuggest.hide();
 
-         $("#sendCount").text(0);
 
-         sendCount=0;
 
-         searchByPaging();
 
-         $('#sendBtn').removeClass('active');
 
-     });
 
- };
 
- // 页面业务处理流程开始
 
- new Promise(function(resolve, reject) {
 
-     // TODO 临时放开
 
-     //resolve(true);
 
-     mui.plusReady(function() {
 
-         // hrefhrefplus已经准备好,可以往下执行
 
-         resolve(true);
 
-         initKeyboardAndroid();
 
-     });
 
- }).then(function() {
 
-     
 
-     // 获取基础环境信息
 
-     return getBaseEnvPromise().then(function(env) {
 
-         baseEnv = env;
 
-     }).then(function() {
 
-         // 获取登录基本信息
 
-         baseInfo = getBaseInfo();
 
-         initTeams();
 
-         openSoftKeyboard();
 
-         $searchbarInput.focus();
 
-         // 绑定页面事件
 
-         bindEvents();
 
-     })
 
- }).catch(function(e) {
 
-     plus.nativeUI.closeWaiting();
 
-     console && console.error(e);
 
- });
 
 
  |