| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 | 
							- // 基本信息(包括userAgent、上个页面传递的数据)
 
- var baseInfo = null,
 
- 	// 基础环境信息(包括当前webview)
 
- 	baseEnv = null;
 
- var $profileItemList = $('.lin-sel-group'),
 
- 	// 搜索无结果时显示
 
- 	$noResultWrap = $('#no_result_wrap'),
 
- 	$selectedProfileName = $('#selected_profile_name'),
 
- 	$pageContent = $('.page-content');
 
- // 分页查询当前页数
 
- var curPage = 1,
 
- 	// iscroll 滚动条实例
 
- 	iscroller;
 
- // 获取基本信息(包括userAgent、上个页面传递的数据)
 
- var getBaseInfoPromise = function() {
 
- 		// 登录的相关信息
 
- 	var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent"))
 
- 	return {
 
- 		userAgent: userAgent,
 
- 		eventInfo: baseEnv.webview.eventInfo,
 
- 		patiInfo: baseEnv.webview.patiInfo
 
- 	}
 
- },
 
- // 获取基础环境信息
 
- getBaseEnvPromise = function () {
 
- 	
 
- 	var env = {
 
- 		webview: plus&&plus.webview.currentWebview()
 
- 	};
 
- 	return Promise.resolve().then(function(res) {
 
- 		return env;
 
- 	});
 
- },
 
- // 初始化就诊事件列表
 
- initProfileList = function() {
 
- 	var catalog = baseInfo.eventInfo.CATALOG,
 
- 		list = [];
 
- 	
 
- 	// TODO 临时排除
 
- 	var except = ["0102","0111","0132","0116"];
 
- 	if(catalog) {
 
- 		_.mapObject(catalog, function(name, key) {
 
- 			if(!_.contains(except,$.trim(key))) {
 
- 				list.push({code: key, name: name})
 
- 			}
 
- 		});
 
- 		
 
- 		// TODO 临时添加档案类型列表
 
- 		list.push({code: '0201', name: "住院诊疗基本信息"},{code: '0211', name: "住院病案首页"},{code: '0214', name: "长期医嘱"},{code: '0215', name: "临时医嘱"},{code: '0216', name: "住院手术记录"},{code: '0213', name: "出院小结"},{code: '0212', name: "入院病历记录"})
 
- 		
 
- 		var html = template("profile_item_tmpl", {list: list});
 
- 		$profileItemList.append(html);
 
- 	}
 
- 	var $first = $profileItemList.find("li").eq(0),
 
- 		name = $.trim($first.attr("data-name")),
 
- 		code = $.trim($first.attr("data-code"));
 
- 	$first.addClass('checked');
 
- 	if(name&&code) {
 
- 		$selectedProfileName.text(name);
 
- 		getProfileTemplateHtml(code);
 
- 	}
 
- 	
 
- },
 
- showProfileItemSel = function() {
 
- 	var isShow = isShow || $('.lin-mask:hidden').length != 0;
 
- 	$('.lin-mask').toggle(isShow);
 
- 	$profileItemList.toggle(isShow);
 
- },
 
- getProfileTemplateHtml = function(tempalteCode){
 
- 	plus.nativeUI.showWaiting();
 
- 	
 
- 	var patiInfo = baseInfo.patiInfo,
 
- 		eventInfo = baseInfo.eventInfo;
 
- 	var templateRequest = new Promise(function(resolve, reject) {
 
- 			mui.ajax('../template/'+tempalteCode+'.html', 
 
- 			{ dataType: 'html',
 
- 			  type:'GET', 
 
- 			  error: function(xht, type, throwErr) {
 
- 			  	mui.toast("档案模板获取失败。");
 
- 			  	plus.nativeUI.closeWaiting();
 
- 			  },
 
- 			  success: function(html) {
 
- 			  	resolve(html);
 
- 			  }
 
- 			})
 
- 		}),
 
- 		profileDataRequest = getReqPromise(healthProfileServer+"wlyy_service/record/healthData",{
 
- 								strSSID: patiInfo.ssc, // 健康卡号
 
- 								strEvent: eventInfo.EVENT, 	// 事件ID
 
- 								strCatalog: tempalteCode, // 档案类型
 
- 								strSerial: "1"  // 该类别顺序号,默认填1
 
- 							},'GET');
 
- 							
 
- 	Promise.all([templateRequest,profileDataRequest]).then(function(datas){
 
- 		plus.nativeUI.closeWaiting();
 
- 		var html = datas[0],
 
- 			profileRes = datas[1];
 
- 			$pageContent.html(html);
 
- 		if(profileRes.status == 200) {
 
- 			var xmlToJson = window["dsXmlToJson"+tempalteCode],
 
- 				jsonData = {};
 
- 			if(xmlToJson && $.isFunction(xmlToJson)) {
 
- 				// xml 转 json
 
- 				if((typeof profileRes.data=='string')&&profileRes.data.constructor==String) {
 
- 					// 去除携带的脚本内容
 
- 					profileRes.data = profileRes.data.replace(/<script[^>]*?>[\s\S]*?<\/script>/ig,'');
 
- 					jsonData = xmlToJson(profileRes.data.replace(/<\?xml .*\?>/,''));
 
- 				}
 
- 			}
 
- 			renderProfileTemplate($.extend(true,{},jsonData));
 
- 		} else {
 
- 			mui.toast(profileRes.msg);
 
- 		}
 
- 		
 
- 	}).catch(function(e) { console && console.error(e); plus.nativeUI.closeWaiting(); });
 
- },
 
- renderProfileTemplate = function(data) {
 
- 	$pageContent.removeAttr('avalonctrl').attr('ms-controller',"viewController");
 
- 	var vm = avalon.define($.extend({},{"$id": "viewController"},data));
 
- 	avalon.scan();
 
- },
 
- // 绑定页面事件
 
- bindEvents = function () {
 
- 	$('.demo-comtop h1').on('click', showProfileItemSel);
 
- 	$('.lin-mask').on('click', showProfileItemSel);
 
- 	$profileItemList.on('click', 'li', function(){
 
- 		var code = $.trim($(this).attr("data-code")),
 
- 			name = $.trim($(this).attr("data-name"));
 
- 		getProfileTemplateHtml(code);
 
- 		$selectedProfileName.text(name);
 
- 		showProfileItemSel(undefined, false);
 
- 		if(!$(this).hasClass('checked')){
 
- 			$(this).addClass('checked').siblings().removeClass('checked');
 
- 		}
 
- 	});
 
- };
 
- // 页面业务处理流程开始
 
- new Promise(function(resolve, reject) {
 
- 	mui.plusReady(function() {
 
- 		// plus已经准备好,可以往下执行
 
- 		resolve(true);
 
- 	});
 
- }).then(function() {
 
- 	
 
- 	// 获取基础环境信息
 
- 	return getBaseEnvPromise().then(function(env) {
 
- 		baseEnv = env;
 
- 	}).then(function() {
 
- 		// 获取登录医生信息
 
- 		baseInfo = getBaseInfoPromise();
 
- 		initProfileList();
 
- 		// 绑定页面事件
 
- 		bindEvents();
 
- 		
 
- 	})
 
- }).catch(function(e) {
 
- 	plus.nativeUI.closeWaiting();
 
- 	console && console.error(e);
 
- });
 
 
  |