var Profile = { url: '', link: '', thatBaseInfo: '', thatPlus: null, thatMui: null, thatPromise: null, thatTempalteCode: '', thatSerial: '', thatPageContent: null, index: 0, firstCode: '', profileRes: [], dc: [], htmlStr:['
', '', '
抱歉,暂未找到符合条件的结果。
', '
'].join(''), init: function (ops) { var me = this; if (!(!!ops && typeof ops === 'object')) { alert('参数有误!'); return; } ops.cb && ops.cb.call(me); me.url = ops.url; me.link = ops.link; me.thatMui = ops.thatMui; me.thatPlus = ops.thatPlus; me.thatPromise = ops.thatPromise; me.thatBaseInfo = ops.thatBaseInfo; me.thatTempalteCode = ops.thatTempalteCode; me.thatSerial = ops.thatSerial; me.thatPageContent = ops.thatPageContent; me.thatPlus.nativeUI.showWaiting(); me.index = 0; me.firstCode = ''; me.profileRes = []; me.dc = []; window['dataCode']=[]; }, //获取模板 templateRequest: function () { var me = this; return new me.thatPromise(function(resolve, reject) { me.thatMui.ajax( me.link, { dataType: 'html', type:'GET', error: function(xht, type, throwErr) { me.thatMui.toast("档案模板获取失败。"); me.thatPlus.nativeUI.closeWaiting(); }, success: function(html) { resolve(html); } }) }) }, //根据thatTempalteCode获取数据 profileDataRequest: function () { var me = this; return getReqPromise( me.url,{ patient: me.thatBaseInfo.patiInfo.code, event: me.thatBaseInfo.eventInfo.id, // 事件ID catalog: me.thatTempalteCode, // 档案类型 serial: me.thatSerial || "1" // 该类别顺序号,默认填1 },'GET') }, promiseAll: function () { var me = this, fistDc = me.thatTempalteCode; me.thatPromise.all([ me.templateRequest(), me.profileDataRequest()]).then(function (datas) { if(datas[1].data){ var html = datas[0]; me.profileRes.push(datas[1]); me.thatPageContent.html(html); me.firstCode = me.thatTempalteCode; me.dc = window['dataCode']; if (me.dc.length > 0) { me.reqDataMore(me); } else { me.changeData(fistDc); } }else{ plus.nativeUI.closeWaiting(); mui.toast('档案数据为空'); } }); }, //获取多个数据 reqDataMore: function (me) { me.thatTempalteCode = me.dc[me.index]; Promise.all([ me.profileDataRequest()]).then(function (datas) { me.profileRes.push(datas[0]); me.index++; if (me.dc.length > me.index) { me.reqDataMore(me); } else { me.changeData(me.firstCode); } }); }, changeData: function (fistDc) { var me = this, jsonData = []; me.dc.unshift(me.firstCode); console.log(me.profileRes) $.each( me.profileRes, function (index) { jsonData.push(me.selectXmlDom(me.profileRes[index],me.dc[index])); }); if (jsonData.length > 0) { if (jsonData.length === 1 && !!!jsonData[0]) { me.thatPageContent.html(me.htmlStr); } else { me.renderProfileTemplate($.extend(true,{},me.mosaicData(jsonData))); } } else { me.thatPageContent.html(me.htmlStr); } plus.nativeUI.closeWaiting(); }, //渲染模板 renderProfileTemplate: function (data) { this.thatPageContent.removeAttr('avalonctrl').attr('ms-controller',"viewController"); var vm = avalon.define($.extend({},{"$id": "viewController"},data)); avalon.scan(); }, //获取xml数据 selectXmlDom: function (profileRes,tempalteCode) { if(profileRes.status == 200){ var me = this, $dom = $(profileRes.data.replace(/<\?xml .*\?>/,'')), version = $dom.find(">version").length?$dom.find(">version").attr("code"):$dom.attr('version'); $.trim(version) || (function () { version = $dom.find(">ClinicalDocument").length? '2.0.0.1' : ''; })(); if($.trim(version)) { var verNum = version.split('.')[0]; var xmlToJson = window["dsXmlToJson"+tempalteCode+'_'+verNum], jsonData = {}; if(xmlToJson && $.isFunction(xmlToJson)) { if(!profileRes.data || profileRes.data=="[]") { if(version=2) { profileRes.data = ''; } else { profileRes.data = ''; } } // xml 转 json if((typeof profileRes.data=='string')&&profileRes.data.constructor==String) { // 去除携带的脚本内容 profileRes.data = profileRes.data.replace(/]*?>[\s\S]*?<\/script>/ig,''); console.log(profileRes.data.replace(/<\?xml .*\?>/,'')) jsonData = xmlToJson(profileRes.data.replace(/<\?xml .*\?>/,'')); } } } }else{ jsonData = '' } return jsonData; }, //数据拼接 mosaicData: function (data) { for (var i = 1; i < data.length; i++) { data[i] && (function () { for (key in data[i]['data']) { data[0]['data'][key] = data[i]['data'][key]; } })(); } return data[0]; } }; var dataCode = []; // 基本信息(包括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, catalogs = []; // 获取基本信息(包括userAgent、上个页面传递的数据) var getBaseInfo = function() { // 登录的相关信息 var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent")) return { userAgent: userAgent, eventInfo: baseEnv.webview.eventInfo, patiInfo: baseEnv.webview.patiInfo, type:baseEnv.webview.type //cy } }, // 获取基础环境信息 getBaseEnvPromise = function () { var env = { webview: plus&&plus.webview.currentWebview() }; return Promise.resolve().then(function(res) { return env; }); }, getCatalogPromise = function() { return getReqPromise('doctor/archives/event/catalog',{patient: baseInfo.patiInfo.code,event: baseInfo.eventInfo.id,type:baseInfo.type},'GET') .then(function(res) { if(res.status==200) { catalogs = res.data } else { mui.toast('档案类型获取失败。'); } },function() { mui.toast('档案类型获取失败。'); }) }, // 初始化就诊事件列表 initProfileList = function() { var list = [], list2 = []; if(catalogs) { var inspection = [], check = [], inspection2 = [], check2 = [], index = [], operation = []; _.map(catalogs,function(item){ switch (item.catalog){ case '0131': check.push(item); break; case '0121': inspection.push(item); break; case '0231': check2.push(item); break; case '0221': inspection2.push(item); break; case '0216': operation.push(item); break; default : index.push(item); break; } }) list[0] = _.find(index,function(o){ return o.catalog == '0101'}); list[1] = _.find(index,function(o){ return o.catalog == '0141'}); list[2] = check; list[3] = inspection; list[4] = _.find(index,function(o){ return o.catalog == '0102'}); list2[0] = _.find(index,function(o){ return o.catalog == '0201'}); list2[1] = _.find(index,function(o){ return o.catalog == '0211'}); list2[2] = _.find(index,function(o){ return o.catalog == '0214'}); list2[3] = _.find(index,function(o){ return o.catalog == '0215'}); list2[4] = _.find(index,function(o){ return o.catalog == '0241'}); list2[5] = _.find(index,function(o){ return o.catalog == '0212'}); list2[6] = _.find(index,function(o){ return o.catalog == '0213'}); list2[7] = check2; list2[8] = inspection2; list2[9] = operation; list2[10] = _.find(index,function(o){ return o.catalog == '0202'}); var html = template("profile_item_tmpl", {arr:list,arr2:list2}); $profileItemList.append(html); } var $first = $profileItemList.find("li.j-hascode").eq(0), name = $.trim($first.attr("data-name")), code = $.trim($first.attr("data-code")); $first.find('a').addClass('active'); if(name&&code) { $selectedProfileName.text(name); getProfileTemplateHtml(code); } }, getProfileTemplateHtml = function(tempalteCode,serial){ Profile.init({ url: healthProfileServer+"doctor/archives/event/healthData", link: '../template/'+tempalteCode+'.html', thatMui: mui, thatPlus: plus, thatPromise: Promise, thatBaseInfo: baseInfo, thatTempalteCode: tempalteCode, thatSerial: serial, thatPageContent: $pageContent, }); Profile.promiseAll(); }, // 绑定页面事件 bindEvents = function () { var saveCode = ''; var saveSerial = ''; $profileItemList.on('click', 'li.j-hascode', function(){ var $this = $(this); var code = $.trim($this.attr("data-code")), name = $.trim($this.attr("data-name")), serial = $.trim($this.attr("data-serial")); if(code != saveCode){ getProfileTemplateHtml(code, serial); saveCode = code; $selectedProfileName.text(name); }else{ if(serial != saveSerial){ getProfileTemplateHtml(code, serial); saveSerial = serial; $selectedProfileName.text(name); } } }) }; // 页面业务处理流程开始 new Promise(function(resolve, reject) { mui.plusReady(function() { // plus已经准备好,可以往下执行 resolve(true); }); }).then(function() { // 获取基础环境信息 return getBaseEnvPromise().then(function(env) { baseEnv = env; // 获取登录医生信息 baseInfo = getBaseInfo(); }) }).then(function() { return getCatalogPromise(); }).then(function() { initProfileList(); // 绑定页面事件 bindEvents(); }).catch(function(e) { plus.nativeUI.closeWaiting(); console && console.error(e); });