123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 |
- var Profile = {
- url: '',
- link: '',
- thatEventId: '',
- thatPromise: null,
- thatTempalteCode: '',
- thatSerial: '',
- thatPageContent: null,
- index: 0,
- firstCode: '',
- profileRes: [],
- dc: [],
- htmlStr:['<div id="no_result_wrap" style="margin-top: 85px;">',
- '<img class="no-result-img" src="../../../images/shujuweikong_img.png" />',
- '<div class="f-fs14 c-323232 c-t-center" style="text-align:center">抱歉,暂未找到符合条件的结果。</div>',
- '</div>'].join(''),
- init: function (ops) {
- var me = this;
- if (!(!!ops && typeof ops === 'object')) {
- showTip('参数有误!');
- return;
- }
- ops.cb && ops.cb.call(me);
- me.url = ops.url;
- me.link = ops.link;
- me.thatPromise = ops.thatPromise;
- me.thatEventId = ops.thatEventId;
- me.thatTempalteCode = ops.thatTempalteCode;
- me.thatSerial = ops.thatSerial;
- me.thatPageContent = ops.thatPageContent;
- me.index = 0;
- me.firstCode = '';
- me.profileRes = [];
- me.dc = [];
- window['dataCode']=[];
- },
- //获取模板
- templateRequest: function () {
- var me = this;
- return new me.thatPromise(function(resolve, reject) {
- $.ajax('../template/'+me.thatTempalteCode+'.html',
- { dataType: 'html',
- type:'GET',
- error: function(xht, type, throwErr) {
- showTip("档案模板获取失败。");
- },
- success: function(html) {
- resolve(html);
- }
- })
- })
- },
- //根据thatTempalteCode获取数据
- profileDataRequest: function () {
- var me = this;
- return getReqPromise( me.url,{
- event: me.thatEventId , // 事件ID
- catalog: me.thatTempalteCode, // 档案类型
- serial: me.thatSerial || "1" // 该类别顺序号,默认填1
- },'JSON','GET');
- },
- promiseAll: function () {
- var me = this,
- fistDc = me.thatTempalteCode;
- Promise.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('档案数据为空');
- }
- }).catch(function(e) {d.close();console && console.error(e);});
- },
- //获取多个数据
- 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);
- $.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 {
- var data = me.mosaicData(jsonData);
- me.renderProfileTemplate($.extend(true,{},data));
- }
- } else {
- me.thatPageContent.html(me.htmlStr);
- }
- d.close();
- },
- //渲染模板
- 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 = '<?xml version="1.0" encoding="utf-8"?><ClinicalDocument></ClinicalDocument>';
- } else {
- profileRes.data = '<?xml version="1.0" encoding="utf-8"?><root></root>';
- }
- }
- // 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 .*\?>/,''));
- }
- }
- }
- }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 = [];
- var Request = GetRequest(),
- eventId = Request.event,type=Request.type; //cy
- var d = dialog({contentType:'load', skin:'bk-popup'});
- var $profileItemList = $('.lin-sel-group'),
- // 搜索无结果时显示
- $noResultWrap = $('#no_result_wrap'),
- $selectedProfileName = $('#selected_profile_name'),
- $pageContent = $('.page-content');
- // 分页查询当前页数
- var curPage = 1,
- // iscroll 滚动条实例
- iscroller,
- catalogs = [];
-
- // 初始化就诊事件列表
- initProfileList = function() {
- var list = [],
- list2 = [];
- if(catalogs) {
- var inspection = [],
- check = [],
- index = [],
- operation = [];
- _.map(catalogs,function(item){
- switch (item.catalog){
- case '0131': check.push(item); break;
- case '0121': inspection.push(item); break;
- case '0231': check.push(item); break;
- case '0221': inspection.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] = check;
- list2[8] = inspection;
- 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){
- if(!(/^0[12]\d{2}/.test(tempalteCode))) {
- dialog({
- content: '对不起,因数据对接问题,暂不支持本记录的展示,请查看其他就诊记录。',
- okValue:'我知道了',
- ok: function (){
- window.history.go(-1);
- }
- }).showModal();
- return ;
- }
- d.show();
- Profile.init({
- url: "patient/archives/event/healthData",
- link: '../template/'+tempalteCode+'.html',
- thatPromise: Promise,
- thatEventId: eventId,
- 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);
- }
- }
- })
- },
- showTip = function(msg) {
- if(msg) {
- var d = dialog({contentType:'', skin:'bk-popup',content: msg}).show();
- setTimeout(function() {
- d.close();
- },1000)
- }
- };
- //// 页面业务处理流程开始
- getReqPromise('patient/archives/event/catalog',{event: eventId,type:type},'JSON','GET')
- .then(function(res) {
- if(res.status==200) {
- catalogs = res.data
- } else {
- showTip('档案类型获取失败。');
- }
- },function() {
- showTip('档案类型获取失败。');
- }).then(function() {
-
- initProfileList();
- // 绑定页面事件
- bindEvents();
- }).catch(function(e) {
- console && console.error(e);
- });
|