jianchajianyan-detail.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. var request = getRequest(),
  2. patient = request.patient,
  3. rowInfo = JSON.parse(window.localStorage.getItem('checkRow'));
  4. var Profile = {
  5. url: '',
  6. link: '',
  7. thatBaseInfo: '',
  8. thatPlus: null,
  9. thatMui: null,
  10. thatPromise: null,
  11. thatTempalteCode: '',
  12. thatSerial: '',
  13. thatPageContent: null,
  14. index: 0,
  15. firstCode: '',
  16. profileRes: [],
  17. dc: [],
  18. htmlStr:['<div id="no_result_wrap">',
  19. '<img class="no-result-img" src="img/shujuweikong_img.png" />',
  20. '<div class="f-fs14 c-323232 c-t-center" style="text-align:center">抱歉,暂未找到符合条件的结果。</div>',
  21. '</div>'].join(''),
  22. init: function (ops) {
  23. var me = this;
  24. if (!(!!ops && typeof ops === 'object')) {
  25. alert('参数有误!');
  26. return;
  27. }
  28. ops.cb && ops.cb.call(me);
  29. me.url = ops.url;
  30. me.link = ops.link;
  31. me.thatMui = ops.thatMui;
  32. me.thatPlus = ops.thatPlus;
  33. me.thatPromise = ops.thatPromise;
  34. me.thatBaseInfo = ops.thatBaseInfo;
  35. me.thatTempalteCode = ops.thatTempalteCode;
  36. me.thatSerial = ops.thatSerial;
  37. me.thatPageContent = ops.thatPageContent;
  38. me.index = 0;
  39. me.firstCode = '';
  40. me.profileRes = [];
  41. me.dc = [];
  42. window['dataCode']=[];
  43. },
  44. //获取模板
  45. templateRequest: function () {
  46. var me = this;
  47. return new me.thatPromise(function(resolve, reject) {
  48. me.thatMui.ajax( me.link,
  49. { dataType: 'html',
  50. type:'GET',
  51. error: function(xht, type, throwErr) {
  52. me.thatMui.toast("档案模板获取失败。");
  53. me.thatPlus.nativeUI.closeWaiting();
  54. },
  55. success: function(html) {
  56. resolve(html);
  57. }
  58. })
  59. }).catch(function(e) {
  60. console.error(e)
  61. })
  62. },
  63. //根据thatTempalteCode获取数据
  64. profileDataRequest: function () {
  65. return new Promise(function(resolve, reject) {
  66. var healthData = {
  67. event: rowInfo.id,
  68. patient: patient,
  69. catalog: rowInfo.catalogCode,
  70. serial: rowInfo.serial || '1'
  71. }
  72. return janchaAPI.getHealthData({data: healthData}).then(function(res) {
  73. resolve(res)
  74. })
  75. }).catch(function(e) {
  76. console.error(e)
  77. })
  78. },
  79. promiseAll: function () {
  80. var me = this,
  81. fistDc = me.thatTempalteCode;
  82. me.thatPromise.all([ me.templateRequest(), me.profileDataRequest()]).then(function (datas) {
  83. var html = datas[0];
  84. me.profileRes.push(datas[1]);
  85. me.thatPageContent.html(html);
  86. me.firstCode = me.thatTempalteCode;
  87. me.dc = window['dataCode'];
  88. if (me.dc.length > 0) {
  89. me.reqDataMore(me);
  90. } else {
  91. me.changeData(fistDc);
  92. }
  93. }).catch(function(e) {
  94. console.error(e)
  95. })
  96. },
  97. //获取多个数据
  98. reqDataMore: function (me) {
  99. me.thatTempalteCode = me.dc[me.index];
  100. Promise.all([ me.profileDataRequest()]).then(function (datas) {
  101. me.profileRes.push(datas[0]);
  102. me.index++;
  103. if (me.dc.length > me.index) {
  104. me.reqDataMore(me);
  105. } else {
  106. me.changeData(me.firstCode);
  107. }
  108. });
  109. },
  110. changeData: function (fistDc) {
  111. var me = this,
  112. jsonData = [];
  113. me.dc.unshift(me.firstCode);
  114. $.each( me.profileRes, function (index) {
  115. jsonData.push(me.selectXmlDom(me.profileRes[index],me.dc[index]));
  116. });
  117. console.log(jsonData);
  118. if (jsonData.length > 0) {
  119. if (jsonData.length === 1 && !!!jsonData[0]) {
  120. me.thatPageContent.html(me.htmlStr);
  121. } else {
  122. me.renderProfileTemplate($.extend(true,{},me.mosaicData(jsonData)));
  123. }
  124. } else {
  125. me.thatPageContent.html(me.htmlStr);
  126. }
  127. // plus.nativeUI.closeWaiting();
  128. },
  129. //渲染模板
  130. renderProfileTemplate: function (data) {
  131. this.thatPageContent.removeAttr('avalonctrl').attr('ms-controller',"viewController");
  132. var vm = avalon.define($.extend({},{"$id": "viewController"},data));
  133. avalon.scan();
  134. },
  135. //获取xml数据
  136. selectXmlDom: function (profileRes,tempalteCode) {
  137. var me = this,
  138. $dom = $(profileRes.data.replace(/<\?xml .*\?>/,'')),
  139. version = $dom.find(">version").length?$dom.find(">version").attr("code"):$dom.attr('version');
  140. $.trim(version) || (function () {
  141. version = $dom.find(">ClinicalDocument").length? '2.0.0.1' : '';
  142. })();
  143. if($.trim(version)) {
  144. var verNum = version.split('.')[0];
  145. var xmlToJson = window["dsXmlToJson"+tempalteCode+'_'+verNum],
  146. jsonData = {};
  147. if(xmlToJson && $.isFunction(xmlToJson)) {
  148. if(!profileRes.data || profileRes.data=="[]") {
  149. if(version=2) {
  150. profileRes.data = '<?xml version="1.0" encoding="utf-8"?><ClinicalDocument></ClinicalDocument>';
  151. } else {
  152. profileRes.data = '<?xml version="1.0" encoding="utf-8"?><root></root>';
  153. }
  154. }
  155. // xml 转 json
  156. if((typeof profileRes.data=='string')&&profileRes.data.constructor==String) {
  157. // 去除携带的脚本内容
  158. profileRes.data = profileRes.data.replace(/<script[^>]*?>[\s\S]*?<\/script>/ig,'');
  159. jsonData = xmlToJson(profileRes.data.replace(/<\?xml .*\?>/,''));
  160. }
  161. }
  162. return jsonData;
  163. }
  164. },
  165. //数据拼接
  166. mosaicData: function (data) {
  167. for (var i = 1; i < data.length; i++) {
  168. data[i] && (function () {
  169. for (key in data[i]['data']) {
  170. data[0]['data'][key] = data[i]['data'][key];
  171. }
  172. })();
  173. }
  174. return data[0];
  175. }
  176. };
  177. var dataCode = [];
  178. // 基本信息(包括userAgent、上个页面传递的数据)
  179. var baseInfo = null,
  180. // 基础环境信息(包括当前webview)
  181. baseEnv = null;
  182. var $profileItemList = $('.lin-sel-group'),
  183. // 搜索无结果时显示
  184. $noResultWrap = $('#no_result_wrap'),
  185. $selectedProfileName = $('#selected_profile_name'),
  186. $pageContent = $('.page-content');
  187. // 分页查询当前页数
  188. var curPage = 1,
  189. // iscroll 滚动条实例
  190. iscroller,
  191. catalogs = [];
  192. var getCatalog = function() {
  193. var catalog = "";
  194. if(rowInfo && rowInfo.catalogCode) {
  195. catalog = rowInfo.catalogCode;
  196. }
  197. return catalog;
  198. },
  199. getCatalogName = function() {
  200. var name = "";
  201. if(rowInfo && rowInfo.label) {
  202. name = rowInfo.label;
  203. }else if(rowInfo && rowInfo.type){
  204. name = rowInfo.type;
  205. }
  206. return name;
  207. },
  208. // 初始化就诊事件列表
  209. initProfileList = function() {
  210. $selectedProfileName.text(getCatalogName());
  211. var tempalteCode = getCatalog();
  212. if(tempalteCode) {
  213. getProfileTemplateHtml(tempalteCode);
  214. }
  215. },
  216. getProfileTemplateHtml = function(tempalteCode,serial){
  217. Profile.init({
  218. url: "http://www.xmtyw.cn/wlyy/doctor/archives/event/healthData",
  219. link: 'template/'+tempalteCode+'.html',
  220. thatMui: jQuery,
  221. thatPromise: Promise,
  222. thatBaseInfo: baseInfo,
  223. thatTempalteCode: tempalteCode,
  224. thatSerial: serial,
  225. thatPageContent: $pageContent,
  226. });
  227. Profile.promiseAll();
  228. };
  229. // 获取异步请求处理Promise对象
  230. function getReqPromise(url, data,reqType,newWay) {
  231. return new Promise(function(resolve, reject) {
  232. sendPost(url, data,
  233. function queryFailed (xht, type, throwErr) {
  234. // dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败'}).show();
  235. // mui.toast("程序开了点小差, 请稍后重试!");
  236. if(type == "error" || type == "parsererror" || type == "null") {
  237. //mui.toast("程序开了点小差, 请稍后重试!");
  238. //throw new Error("加载失败");
  239. showErrorPage("程序开了点小差, 请稍后重试!");
  240. }
  241. return true;
  242. }
  243. , function success(res) {
  244. resolve(res);
  245. },reqType, '', (newWay===false?false:true));
  246. });
  247. }
  248. $(function(){
  249. initProfileList();
  250. });