single-profile.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. var Profile = {
  2. url: '',
  3. link: '',
  4. thatEventId: '',
  5. thatPromise: null,
  6. thatTempalteCode: '',
  7. thatSerial: '',
  8. thatPageContent: null,
  9. index: 0,
  10. firstCode: '',
  11. profileRes: [],
  12. dc: [],
  13. htmlStr:['<div id="no_result_wrap" style="margin-top: 85px;">',
  14. '<img class="no-result-img" src="../../../images/shujuweikong_img.png" />',
  15. '<div class="f-fs14 c-323232 c-t-center" style="text-align:center">抱歉,暂未找到符合条件的结果。</div>',
  16. '</div>'].join(''),
  17. init: function (ops) {
  18. var me = this;
  19. if (!(!!ops && typeof ops === 'object')) {
  20. showTip('参数有误!');
  21. return;
  22. }
  23. ops.cb && ops.cb.call(me);
  24. me.url = ops.url;
  25. me.link = ops.link;
  26. me.thatPromise = ops.thatPromise;
  27. me.thatEventId = ops.thatEventId;
  28. me.thatTempalteCode = ops.thatTempalteCode;
  29. me.thatSerial = ops.thatSerial;
  30. me.thatPageContent = ops.thatPageContent;
  31. me.index = 0;
  32. me.firstCode = '';
  33. me.profileRes = [];
  34. me.dc = [];
  35. window['dataCode']=[];
  36. },
  37. //获取模板
  38. templateRequest: function () {
  39. var me = this;
  40. return new me.thatPromise(function(resolve, reject) {
  41. $.ajax('../template/'+me.thatTempalteCode+'.html',
  42. { dataType: 'html',
  43. type:'GET',
  44. error: function(xht, type, throwErr) {
  45. showTip("档案模板获取失败。");
  46. },
  47. success: function(html) {
  48. resolve(html);
  49. }
  50. })
  51. })
  52. },
  53. //根据thatTempalteCode获取数据
  54. profileDataRequest: function () {
  55. var me = this;
  56. return getReqPromise( me.url,{
  57. event: me.thatEventId , // 事件ID
  58. catalog: me.thatTempalteCode, // 档案类型
  59. serial: me.thatSerial || "1" // 该类别顺序号,默认填1
  60. },'JSON','GET');
  61. },
  62. promiseAll: function () {
  63. var me = this,
  64. fistDc = me.thatTempalteCode;
  65. Promise.all([ me.templateRequest(), me.profileDataRequest()]).then(function (datas) {
  66. var html = datas[0];
  67. me.profileRes.push(datas[1]);
  68. me.thatPageContent.html(html);
  69. me.firstCode = me.thatTempalteCode;
  70. me.dc = window['dataCode'];
  71. if (me.dc.length > 0) {
  72. me.reqDataMore(me);
  73. } else {
  74. me.changeData(fistDc);
  75. }
  76. }).catch(function(e) {d.close();console && console.error(e);});
  77. },
  78. //获取多个数据
  79. reqDataMore: function (me) {
  80. me.thatTempalteCode = me.dc[me.index];
  81. Promise.all([ me.profileDataRequest()]).then(function (datas) {
  82. me.profileRes.push(datas[0]);
  83. me.index++;
  84. if (me.dc.length > me.index) {
  85. me.reqDataMore(me);
  86. } else {
  87. me.changeData(me.firstCode);
  88. }
  89. });
  90. },
  91. changeData: function (fistDc) {
  92. var me = this,
  93. jsonData = [];
  94. me.dc.unshift(me.firstCode);
  95. $.each( me.profileRes, function (index) {
  96. jsonData.push(me.selectXmlDom(me.profileRes[index],me.dc[index]));
  97. });
  98. if (jsonData.length > 0) {
  99. if (jsonData.length === 1 && !!!jsonData[0]) {
  100. me.thatPageContent.html(me.htmlStr);
  101. } else {
  102. var data = me.mosaicData(jsonData);
  103. me.renderProfileTemplate($.extend(true,{},data));
  104. }
  105. } else {
  106. me.thatPageContent.html(me.htmlStr);
  107. }
  108. d.close();
  109. },
  110. //渲染模板
  111. renderProfileTemplate: function (data) {
  112. this.thatPageContent.removeAttr('avalonctrl').attr('ms-controller',"viewController");
  113. var vm = avalon.define($.extend({},{"$id": "viewController"},data));
  114. avalon.scan();
  115. },
  116. //获取xml数据
  117. selectXmlDom: function (profileRes,tempalteCode) {
  118. var me = this,
  119. $dom = $(profileRes.data.replace(/<\?xml .*\?>/,'')),
  120. version = $dom.find(">version").length?$dom.find(">version").attr("code"):$dom.attr('version');
  121. $.trim(version) || (function () {
  122. version = $dom.find(">ClinicalDocument").length? '2.0.0.1' : '';
  123. })();
  124. if($.trim(version)) {
  125. var verNum = version.split('.')[0];
  126. var xmlToJson = window["dsXmlToJson"+tempalteCode+'_'+verNum],
  127. jsonData = {};
  128. if(xmlToJson && $.isFunction(xmlToJson)) {
  129. if(!profileRes.data || profileRes.data=="[]") {
  130. if(version=2) {
  131. profileRes.data = '<?xml version="1.0" encoding="utf-8"?><ClinicalDocument></ClinicalDocument>';
  132. } else {
  133. profileRes.data = '<?xml version="1.0" encoding="utf-8"?><root></root>';
  134. }
  135. }
  136. // xml 转 json
  137. if((typeof profileRes.data=='string')&&profileRes.data.constructor==String) {
  138. // 去除携带的脚本内容
  139. profileRes.data = profileRes.data.replace(/<script[^>]*?>[\s\S]*?<\/script>/ig,'');
  140. // console.log(profileRes.data.replace(/<\?xml .*\?>/,''))
  141. jsonData = xmlToJson(profileRes.data.replace(/<\?xml .*\?>/,''));
  142. }
  143. }
  144. return jsonData;
  145. }
  146. },
  147. //数据拼接
  148. mosaicData: function (data) {
  149. for (var i = 1; i < data.length; i++) {
  150. data[i] && (function () {
  151. for (key in data[i]['data']) {
  152. data[0]['data'][key] = data[i]['data'][key];
  153. }
  154. })();
  155. }
  156. return data[0];
  157. }
  158. };
  159. var dataCode = [];
  160. var Request = GetRequest(),
  161. eventId = Request.event,
  162. typeName = decodeURIComponent(Request.typeName),
  163. serial = Request.serial,
  164. catalog = Request.catalog;
  165. var d = dialog({contentType:'load', skin:'bk-popup'});
  166. var $profileItemList = $('.lin-sel-group'),
  167. // 搜索无结果时显示
  168. $noResultWrap = $('#no_result_wrap'),
  169. $selectedProfileName = $('#selected_profile_name'),
  170. $pageContent = $('.page-content');
  171. // 分页查询当前页数
  172. var curPage = 1,
  173. // iscroll 滚动条实例
  174. iscroller;
  175. // 初始化就诊事件列表
  176. initProfileList = function() {
  177. $selectedProfileName.text(typeName);
  178. if(catalog) {
  179. getProfileTemplateHtml(catalog);
  180. }
  181. },
  182. getProfileTemplateHtml = function(tempalteCode){
  183. if(!(/^0[12]\d{2}/.test(tempalteCode))) {
  184. dialog({
  185. content: '对不起,因数据对接问题,暂不支持本记录的展示,请查看其他就诊记录。',
  186. okValue:'我知道了',
  187. ok: function (){
  188. window.history.go(-1);
  189. }
  190. }).showModal();
  191. return ;
  192. }
  193. d.show();
  194. Profile.init({
  195. url: "patient/archives/event/healthData",
  196. link: '../template/'+tempalteCode+'.html',
  197. thatPromise: Promise,
  198. thatEventId: eventId,
  199. thatTempalteCode: tempalteCode,
  200. thatSerial: serial,
  201. thatPageContent: $pageContent,
  202. });
  203. Profile.promiseAll();
  204. },
  205. showTip = function(msg) {
  206. if(msg) {
  207. var d = dialog({contentType:'', skin:'bk-popup',content: msg}).show();
  208. setTimeout(function() {
  209. d.close();
  210. },1000)
  211. }
  212. },
  213. // 绑定页面事件
  214. bindEvents = function () {
  215. $('#xiangqing_btn').on('click',function() {
  216. window.location.href = 'event-profile.html?event='+eventId+'&catalog='+catalog+'&type=1' //cy
  217. });
  218. };
  219. // 页面业务处理流程开始
  220. getReqPromise('patient/archives/event/catalog',{event: eventId},'JSON','GET')
  221. .then(function(res) {
  222. if(res.status==200) {
  223. catalogs = res.data
  224. } else {
  225. showTip('档案类型获取失败。');
  226. }
  227. },function() {
  228. showTip('档案类型获取失败。');
  229. }).then(function() {
  230. initProfileList();
  231. // 绑定页面事件
  232. bindEvents();
  233. }).catch(function(e) {
  234. console && console.error(e);
  235. });