event-profile.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. if(datas[1].data){
  67. var html = datas[0];
  68. me.profileRes.push(datas[1]);
  69. me.thatPageContent.html(html);
  70. me.firstCode = me.thatTempalteCode;
  71. me.dc = window['dataCode'];
  72. if (me.dc.length > 0) {
  73. me.reqDataMore(me);
  74. } else {
  75. me.changeData(fistDc);
  76. }
  77. }else{
  78. plus.nativeUI.closeWaiting();
  79. mui.toast('档案数据为空');
  80. }
  81. }).catch(function(e) {d.close();console && console.error(e);});
  82. },
  83. //获取多个数据
  84. reqDataMore: function (me) {
  85. me.thatTempalteCode = me.dc[me.index];
  86. Promise.all([ me.profileDataRequest()]).then(function (datas) {
  87. me.profileRes.push(datas[0]);
  88. me.index++;
  89. if (me.dc.length > me.index) {
  90. me.reqDataMore(me);
  91. } else {
  92. me.changeData(me.firstCode);
  93. }
  94. });
  95. },
  96. changeData: function (fistDc) {
  97. var me = this,
  98. jsonData = [];
  99. me.dc.unshift(me.firstCode);
  100. $.each( me.profileRes, function (index) {
  101. jsonData.push(me.selectXmlDom(me.profileRes[index],me.dc[index]));
  102. });
  103. if (jsonData.length > 0) {
  104. if (jsonData.length === 1 && !!!jsonData[0]) {
  105. me.thatPageContent.html(me.htmlStr);
  106. } else {
  107. var data = me.mosaicData(jsonData);
  108. me.renderProfileTemplate($.extend(true,{},data));
  109. }
  110. } else {
  111. me.thatPageContent.html(me.htmlStr);
  112. }
  113. d.close();
  114. },
  115. //渲染模板
  116. renderProfileTemplate: function (data) {
  117. this.thatPageContent.removeAttr('avalonctrl').attr('ms-controller',"viewController");
  118. var vm = avalon.define($.extend({},{"$id": "viewController"},data));
  119. avalon.scan();
  120. },
  121. //获取xml数据
  122. selectXmlDom: function (profileRes,tempalteCode) {
  123. if(profileRes.status == 200){
  124. var me = this,
  125. $dom = $(profileRes.data.replace(/<\?xml .*\?>/,'')),
  126. version = $dom.find(">version").length?$dom.find(">version").attr("code"):$dom.attr('version');
  127. $.trim(version) || (function () {
  128. version = $dom.find(">ClinicalDocument").length? '2.0.0.1' : '';
  129. })();
  130. if($.trim(version)) {
  131. var verNum = version.split('.')[0];
  132. var xmlToJson = window["dsXmlToJson"+tempalteCode+'_'+verNum],
  133. jsonData = {};
  134. if(xmlToJson && $.isFunction(xmlToJson)) {
  135. if(!profileRes.data || profileRes.data=="[]") {
  136. if(version=2) {
  137. profileRes.data = '<?xml version="1.0" encoding="utf-8"?><ClinicalDocument></ClinicalDocument>';
  138. } else {
  139. profileRes.data = '<?xml version="1.0" encoding="utf-8"?><root></root>';
  140. }
  141. }
  142. // xml 转 json
  143. if((typeof profileRes.data=='string')&&profileRes.data.constructor==String) {
  144. // 去除携带的脚本内容
  145. profileRes.data = profileRes.data.replace(/<script[^>]*?>[\s\S]*?<\/script>/ig,'');
  146. jsonData = xmlToJson(profileRes.data.replace(/<\?xml .*\?>/,''));
  147. }
  148. }
  149. }
  150. }else{
  151. jsonData = ''
  152. }
  153. return jsonData;
  154. },
  155. //数据拼接
  156. mosaicData: function (data) {
  157. for (var i = 1; i < data.length; i++) {
  158. data[i] && (function () {
  159. for (key in data[i]['data']) {
  160. data[0]['data'][key] = data[i]['data'][key];
  161. }
  162. })();
  163. }
  164. return data[0];
  165. }
  166. };
  167. var dataCode = [];
  168. var Request = GetRequest(),
  169. eventId = Request.event,type=Request.type; //cy
  170. var d = dialog({contentType:'load', skin:'bk-popup'});
  171. var $profileItemList = $('.lin-sel-group'),
  172. // 搜索无结果时显示
  173. $noResultWrap = $('#no_result_wrap'),
  174. $selectedProfileName = $('#selected_profile_name'),
  175. $pageContent = $('.page-content');
  176. // 分页查询当前页数
  177. var curPage = 1,
  178. // iscroll 滚动条实例
  179. iscroller,
  180. catalogs = [];
  181. // 初始化就诊事件列表
  182. initProfileList = function() {
  183. var list = [],
  184. list2 = [];
  185. if(catalogs) {
  186. var inspection = [],
  187. check = [],
  188. index = [],
  189. operation = [];
  190. _.map(catalogs,function(item){
  191. switch (item.catalog){
  192. case '0131': check.push(item); break;
  193. case '0121': inspection.push(item); break;
  194. case '0231': check.push(item); break;
  195. case '0221': inspection.push(item); break;
  196. case '0216': operation.push(item); break;
  197. default : index.push(item); break;
  198. }
  199. })
  200. list[0] = _.find(index,function(o){ return o.catalog == '0101'});
  201. list[1] = _.find(index,function(o){ return o.catalog == '0141'});
  202. list[2] = check;
  203. list[3] = inspection;
  204. list[4] = _.find(index,function(o){ return o.catalog == '0102'});
  205. list2[0] = _.find(index,function(o){ return o.catalog == '0201'});
  206. list2[1] = _.find(index,function(o){ return o.catalog == '0211'});
  207. list2[2] = _.find(index,function(o){ return o.catalog == '0214'});
  208. list2[3] = _.find(index,function(o){ return o.catalog == '0215'});
  209. list2[4] = _.find(index,function(o){ return o.catalog == '0241'});
  210. list2[5] = _.find(index,function(o){ return o.catalog == '0212'});
  211. list2[6] = _.find(index,function(o){ return o.catalog == '0213'});
  212. list2[7] = check;
  213. list2[8] = inspection;
  214. list2[9] = operation;
  215. list2[10] = _.find(index,function(o){ return o.catalog == '0202'});
  216. var html = template("profile_item_tmpl", {arr:list,arr2:list2});
  217. $profileItemList.append(html);
  218. }
  219. var $first = $profileItemList.find("li.j-hascode").eq(0),
  220. name = $.trim($first.attr("data-name")),
  221. code = $.trim($first.attr("data-code"));
  222. $first.find('a').addClass('active');
  223. if(name&&code) {
  224. $selectedProfileName.text(name);
  225. getProfileTemplateHtml(code);
  226. }
  227. },
  228. getProfileTemplateHtml = function(tempalteCode,serial){
  229. if(!(/^0[12]\d{2}/.test(tempalteCode))) {
  230. dialog({
  231. content: '对不起,因数据对接问题,暂不支持本记录的展示,请查看其他就诊记录。',
  232. okValue:'我知道了',
  233. ok: function (){
  234. window.history.go(-1);
  235. }
  236. }).showModal();
  237. return ;
  238. }
  239. d.show();
  240. Profile.init({
  241. url: "patient/archives/event/healthData",
  242. link: '../template/'+tempalteCode+'.html',
  243. thatPromise: Promise,
  244. thatEventId: eventId,
  245. thatTempalteCode: tempalteCode,
  246. thatSerial: serial,
  247. thatPageContent: $pageContent,
  248. });
  249. Profile.promiseAll();
  250. },
  251. // 绑定页面事件
  252. bindEvents = function () {
  253. var saveCode = '';
  254. var saveSerial = '';
  255. $profileItemList.on('click', 'li.j-hascode', function(){
  256. var $this = $(this);
  257. var code = $.trim($this.attr("data-code")),
  258. name = $.trim($this.attr("data-name")),
  259. serial = $.trim($this.attr("data-serial"));
  260. if(code != saveCode){
  261. getProfileTemplateHtml(code, serial);
  262. saveCode = code;
  263. $selectedProfileName.text(name);
  264. }else{
  265. if(serial != saveSerial){
  266. getProfileTemplateHtml(code, serial);
  267. saveSerial = serial;
  268. $selectedProfileName.text(name);
  269. }
  270. }
  271. })
  272. },
  273. showTip = function(msg) {
  274. if(msg) {
  275. var d = dialog({contentType:'', skin:'bk-popup',content: msg}).show();
  276. setTimeout(function() {
  277. d.close();
  278. },1000)
  279. }
  280. };
  281. //// 页面业务处理流程开始
  282. getReqPromise('patient/archives/event/catalog',{event: eventId,type:type},'JSON','GET')
  283. .then(function(res) {
  284. if(res.status==200) {
  285. catalogs = res.data
  286. } else {
  287. showTip('档案类型获取失败。');
  288. }
  289. },function() {
  290. showTip('档案类型获取失败。');
  291. }).then(function() {
  292. initProfileList();
  293. // 绑定页面事件
  294. bindEvents();
  295. }).catch(function(e) {
  296. console && console.error(e);
  297. });