| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466 | 
							- 	// 基本信息(包括userAgent)
 
- var baseInfo = null,
 
- 	// 基础环境信息(包括当前webview)
 
- 	baseEnv = null;
 
- 	
 
- 	// 搜索框
 
- var $searchbar = $('.searchbar'),
 
- 	// 搜索输入框
 
- 	$searchbarInput = $('.lin-search-ipt input'),
 
- 	// 搜索取消按钮
 
- 	$searchCancelBtn = $('.searchbar-cancel'),
 
- 	// 搜索框下面悬浮的搜索提示
 
- 	$searchSuggest = $('#search_suggest_text'),
 
- 	// 搜索结果展示容器
 
- 	$searchtResult = $('#search_result'),
 
- 	// 搜索无结果时显示
 
- 	$noResultWrap = $('#no_result_wrap'),
 
- 	$patiList = $('#pati_list'),
 
- 	$history = $('#history_search'),//历史搜索
 
- 	$hisSearList = $('#his_sear_list');
 
- 	
 
- var lastId = 1,// 分页查询最后一页
 
-     search_keyword = "", //记录搜索框的内容
 
- 	// iscroll 滚动条实例
 
- 	iscroller,
 
- 	// 从缓存取出所选团队
 
- 	// 每页加载数据量
 
- 	pagesize = 15,
 
- 	myScroll,
 
- 	hasMoreResults = false,
 
- 	historyData=[],//历史数据
 
- 	historyStr,
 
- 	inputText="";
 
- 	
 
- var self;
 
- mui.plusReady(function() {
 
- //	initKeyboardAndroid();
 
- 	self = plus.webview.currentWebview();
 
-     docInfo = JSON.parse(plus.storage.getItem("docInfo"));
 
-     historyStr = window.localStorage.getItem("qianyueSearchHis"+docInfo.code);
 
- 	if(historyStr){
 
- 		historyStr = JSON.parse(historyStr).join(',');
 
- 		historyData = historyStr.split(',');
 
- 	}else{
 
- 		historyData = [];
 
- 	}
 
- 	if(historyData.length){
 
- 		$history.show();
 
- 	}
 
-      //阻尼系数
 
-     var deceleration = mui.os.ios?0.003:0.0009;
 
-     mui('.mui-scroll-wrapper').scroll({
 
-         scrollX: true,
 
-         bounce: false,
 
-         indicators: true, //是否显示滚动条
 
-         deceleration:deceleration
 
-     });
 
- });
 
- window.addEventListener("initSearch", function(e){
 
- //	openSoftKeyboard();
 
- 	baseInfo = getBaseInfo();
 
- 	setTimeout(function(){
 
- 		$("#searchPut").focus();
 
- 	},500)
 
- })
 
- // 获取登录相关信息
 
- var getBaseInfo = function() {
 
- 		// 登录的相关信息
 
- 	var userAgent = JSON.parse(plus.storage.getItem("userAgent"))
 
- 	return {
 
- 		userAgent: userAgent
 
- 	}
 
- },
 
- // 获取基础环境信息
 
- getBaseEnvPromise = function () {
 
- 	self =  plus.webview.currentWebview();
 
- 	var env = {
 
- 		webview: plus.webview.currentWebview()
 
- 	};
 
- 	return Promise.resolve().then(function(res) {
 
- 		return env;
 
- 	});
 
- },
 
- historyList = function(){
 
- 	historyStr = window.localStorage.getItem("qianyueSearchHis"+docInfo.code);
 
- 	if(historyStr){
 
- 		historyStr = JSON.parse(historyStr).join(',');
 
- 		historyData = historyStr.split(',');
 
- 	}else{
 
- 		historyData = [];
 
- 	}
 
- 	var html = template('his_list_tmpl',{list:historyData});
 
- 	$hisSearList.html('');
 
- 	$hisSearList.append(html);
 
- },
 
- // 初始化“患者”视图列表
 
- initPatientViewList = function(data,keyword,isAppend) {
 
-     data.inputText = inputText;
 
-     data.patients_len = data.patients.length;
 
-     var html = template('pati_list_tmpl', data)
 
- 		searchText = $searchbarInput.val().trim();
 
- 	if(isAppend === true) {
 
- 		$patiList.append(html)
 
- 	} else {
 
- 		$patiList.html(html);
 
- 	}
 
- 	ellipsisText($patiList.find('li'),searchText);
 
- },
 
- // $el: $('.c-content-warp')
 
- 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) {
 
- 	//$el.ellipsis({ row: 2});
 
- 	_.each($elements,function(el) {
 
- 	    var $textEl = $(el).find(".j-text-ellipsis");
 
- 	    _.each($textEl, function(t){
 
- 	        highlineKeyword($(t),searchText)
 
- 	    })
 
- 	});
 
- },
 
- // 控制搜索关键字悬浮提示的显示
 
- showSearchSuggest = function(text) {
 
- 	var suggestText = '搜索“'+text+'”';
 
- 	// 如果text不为空,则显示;否则隐藏
 
- 	if(text&&text.trim().length) {
 
- 		$searchSuggest.text(suggestText);
 
- 		$searchSuggest.show();
 
- 	} else {
 
- 		$searchSuggest.text('');
 
- 		$searchSuggest.hide();
 
- 	}
 
- },
 
- // 分页查询列表
 
- searchByPaging = function () {
 
- 	search_keyword = $searchbarInput.val();
 
- 	if(!$.trim(search_keyword)) {
 
- 		return ;
 
- 	}
 
- 	plus.nativeUI.showWaiting();
 
- 	// page: 分页索引,filter:搜素关键字,pagesize:每页条数
 
- 	var url = "/doctor/patient_label_info/getPatientByNameOrIdcard",
 
- 		params = {str: search_keyword};
 
- 	getReqPromise(url,params, "GET").then(function(res){
 
-  		if(res.status == 200) {
 
- 			if(res.data.teams.length == 0 && res.data.patients.length == 0 ) {
 
- 				$searchtResult.hide();
 
- 				$noResultWrap.show();
 
- 			} else {
 
- 				$noResultWrap.hide();
 
- 				$searchtResult.show();
 
- 				initPatientViewList(res.data,search_keyword);
 
- 			}
 
-  		} else {
 
-  			plus.nativeUI.toast("搜索失败");
 
-  		}
 
-    		plus.nativeUI.closeWaiting();
 
- 	}).catch(function(e) {
 
- 		console && console.error(e)
 
- 	});
 
- },
 
- // 滚动条分页实例初始化
 
- initScroller = function($el,url,getData,pullUpAction, reqType) {
 
- 	var scroller;
 
- 	if(hasMoreResults) {
 
- 		scroller = $el.initScroll({pullDown: false,pullUpAction: function() {
 
- 			var data = getData();
 
- 			getReqPromise(url,data,reqType).then(function(data) {
 
- 				if(pullUpAction && $.isFunction(pullUpAction)) {
 
- 					pullUpAction(data);
 
- 					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() {
 
- 		var code = $(this).attr("data-patient-code");
 
- 		openWebview("huanzhexinxi.html",{
 
- 			patiCode: code
 
- 		});
 
- 		return false;
 
- 	}).on('tap', 'li[data-code]', function(){
 
- 	    var code = $(this).attr("data-code");
 
- 	    openWebview("juminxinxi.html",{patiCode: code});
 
- 	});
 
- 	
 
- 	$('#clear_his_data').on('tap', function(){
 
- 		window.localStorage.removeItem("qianyueSearchHis"+docInfo.code);
 
- 		historyList();
 
- 		$history.hide();
 
- 	})
 
- 	
 
- 	$hisSearList.on('click','.his-list',function(){
 
- 		var $that = $(this);
 
- 		lastId = 1;
 
- 		$("#searchAll").hide();
 
- 	    $searchSuggest.hide();
 
- 	    $history.hide();
 
- 	    $searchbarInput.val($that.text())
 
- 		searchByPaging();
 
- 	})
 
- 	
 
- 	$searchbarInput.on('input', function() {
 
- 		var text = $(this).val().trim();
 
- 		$searchtResult.hide();
 
- 		$('#no_result_wrap').hide();
 
- 		if(text.length > 0){
 
- 		    $history.hide();
 
- 		}else{
 
- 		    $history.show();
 
- 		}
 
- 		showSearchSuggest(text);	
 
- 	}).on('keydown',function(e) {
 
- 		if (e.which === 13 || e.keycode === 13) {
 
- 			saveHisData();//保存历史数据20个
 
-             validateInputText();
 
- 		}
 
- 	});
 
- 	
 
- 	$('.lin-search-ipt a').on('click', function(){
 
- 		plus.webview.currentWebview().close();
 
- 	})
 
- 	
 
- 	function saveHisData(){
 
- 		//保存历史数据20个
 
- 		var value = $searchbarInput.val().trim();
 
- 		if(value){
 
- 			if(historyData.length>19){
 
- 				historyData.pop();
 
- 			}
 
- 			if(historyData.indexOf(value)>-1){
 
- 				historyData =  _.filter(historyData, function(o){ return o != value; });
 
- 			}
 
- 			historyData.unshift(value);
 
- 			var str = JSON.stringify(historyData)
 
- 			window.localStorage.setItem("qianyueSearchHis"+docInfo.code,str);
 
- 			historyList();
 
- 		}
 
- 	}
 
- 	
 
- 	$searchSuggest.on('click',function() {
 
- 		saveHisData();//保存历史数据20个
 
- 	    validateInputText();
 
- 	});
 
- 	
 
- 	$searchCancelBtn.on('click',function() {
 
- 		mui.back();
 
- 	});
 
- 	
 
- 	//搜索全部居民的绑定事件
 
- 	$("#searchAll").on('click', function(){
 
- 	    openWebview("search_all.html");
 
- 	});
 
- },
 
- validateInputText = function(){
 
-     //校验输入的数据
 
-     var text = $('#searchPut').val(),
 
-         reg = /[\u4E00-\u9FA5]/i, //验证汉字
 
-         pass = false,
 
-         inputName = true;
 
-     if(!reg.test(text)){
 
-         pass = IdentityCodeValid(text);
 
-         inputName = false;
 
-         inputText = "idcard";
 
-     }else{
 
-         //校验汉字
 
-         pass = (text.length > 1);
 
-         inputText = "name";
 
-         if(!pass){
 
-             dialog({
 
-                 contentType: "tipsbox",
 
-                 skin:"popup",
 
-                 closeTime: 2000,
 
-                 content: "请输入完整的姓名"
 
-             }).showModal();
 
-         }
 
-     }
 
-     if(inputName){
 
-         $noResultWrap.find("div").text("无符合条件的结果,请确认输入的名字是否正确");
 
-     }else{
 
-         $noResultWrap.find("div").text("无符合条件的结果,请确认输入的身份证号是否正确");
 
-     }
 
-     if(pass){
 
-         lastId = 1;
 
-         $searchSuggest.hide();
 
-         searchByPaging();
 
-     }
 
- },
 
- IdentityCodeValid = function(code) { 
 
-     var city={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江 ",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北 ",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏 ",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外 "};
 
-     var tip = "";
 
-     var pass= true;
 
-     
 
-     if(!code || !/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[12])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i.test(code)){
 
-         tip = "身份证号格式错误";
 
-         pass = false;
 
-     }
 
-     
 
-    else if(!city[code.substr(0,2)]){
 
-         tip = "地址编码错误";
 
-         pass = false;
 
-     }
 
-     else{
 
-         //18位身份证需要验证最后一位校验位
 
-         if(code.length == 18){
 
-             code = code.split('');
 
-             //∑(ai×Wi)(mod 11)
 
-             //加权因子
 
-             var factor = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ];
 
-             //校验位
 
-             var parity = [ 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 ];
 
-             var sum = 0;
 
-             var ai = 0;
 
-             var wi = 0;
 
-             for (var i = 0; i < 17; i++)
 
-             {
 
-                 ai = code[i];
 
-                 wi = factor[i];
 
-                 sum += ai * wi;
 
-             }
 
-             var last = parity[sum % 11];
 
-             if(parity[sum % 11] != code[17]){
 
-                 tip = "校验位错误";
 
-                 pass =false;
 
-             }
 
-         }
 
-     }
 
-     if(!pass){
 
-         dialog({
 
-             contentType: 'tipsbox',
 
-             skin: 'bk-popup',
 
-             content: "请输入正确的身份证号",
 
-             closeTime: 2000
 
-         }).showModal();
 
-     }
 
-     return pass;
 
- };
 
- // 页面业务处理流程开始
 
- new Promise(function(resolve, reject) {
 
- 	mui.plusReady(function() {
 
- 		// hrefhrefplus已经准备好,可以往下执行
 
- 		resolve(true);
 
- 	});
 
- }).then(function() {
 
- 	
 
- 	// 获取基础环境信息
 
- 	return getBaseEnvPromise().then(function(env) {
 
- 		baseEnv = env;
 
- 	}).then(function() {
 
- 		// 获取登录基本信息
 
- 		baseInfo = getBaseInfo();
 
- 		lastTeamId = plus.storage.getItem("selectedTeamId");
 
- 		$searchbar.searchBar();
 
- 		historyList();
 
- 		if(historyData.length){
 
- 			$history.show();
 
- 		}
 
- //		openSoftKeyboard();
 
- 		$searchbarInput.focus();
 
- 		// 绑定页面事件
 
- 		bindEvents();
 
- 	})
 
- }).catch(function(e) {
 
- 	plus.nativeUI.closeWaiting();
 
- 	console && console.error(e);
 
- });
 
 
  |