single-profile.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. var Profile = {
  2. url: '',
  3. link: '',
  4. thatBaseInfo: '',
  5. thatPlus: null,
  6. thatMui: null,
  7. thatPromise: null,
  8. thatTempalteCode: '',
  9. thatSerial: '',
  10. thatPageContent: null,
  11. index: 0,
  12. firstCode: '',
  13. profileRes: [],
  14. dc: [],
  15. htmlStr:['<div id="no_result_wrap">',
  16. '<img class="no-result-img" src="../../../images/shujuweikong_img.png" />',
  17. '<div class="f-fs14 c-323232 c-t-center" style="text-align:center">抱歉,暂未找到符合条件的结果。</div>',
  18. '</div>'].join(''),
  19. init: function (ops) {
  20. var me = this;
  21. if (!(!!ops && typeof ops === 'object')) {
  22. alert('参数有误!');
  23. return;
  24. }
  25. ops.cb && ops.cb.call(me);
  26. me.url = ops.url;
  27. me.link = ops.link;
  28. me.thatMui = ops.thatMui;
  29. me.thatPlus = ops.thatPlus;
  30. me.thatPromise = ops.thatPromise;
  31. me.thatBaseInfo = ops.thatBaseInfo;
  32. me.thatTempalteCode = ops.thatTempalteCode;
  33. me.thatSerial = ops.thatSerial;
  34. me.thatPageContent = ops.thatPageContent;
  35. me.thatPlus.nativeUI.showWaiting();
  36. me.index = 0;
  37. me.firstCode = '';
  38. me.profileRes = [];
  39. me.dc = [];
  40. window['dataCode']=[];
  41. },
  42. //获取模板
  43. templateRequest: function () {
  44. var me = this;
  45. return new me.thatPromise(function(resolve, reject) {
  46. me.thatMui.ajax( me.link,
  47. { dataType: 'html',
  48. type:'GET',
  49. error: function(xht, type, throwErr) {
  50. me.thatMui.toast("档案模板获取失败。");
  51. me.thatPlus.nativeUI.closeWaiting();
  52. },
  53. success: function(html) {
  54. resolve(html);
  55. }
  56. })
  57. })
  58. },
  59. //根据thatTempalteCode获取数据
  60. profileDataRequest: function () {
  61. var me = this;
  62. return getReqPromise( me.url,{
  63. patient: me.thatBaseInfo.patiInfo.code,
  64. event: me.thatBaseInfo.eventInfo.id, // 事件ID
  65. catalog: me.thatTempalteCode, // 档案类型
  66. serial: me.thatSerial || "1" // 该类别顺序号,默认填1
  67. },'GET')
  68. },
  69. promiseAll: function () {
  70. var me = this,
  71. fistDc = me.thatTempalteCode;
  72. me.thatPromise.all([ me.templateRequest(), me.profileDataRequest()]).then(function (datas) {
  73. var html = datas[0];
  74. me.profileRes.push(datas[1]);
  75. me.thatPageContent.html(html);
  76. me.firstCode = me.thatTempalteCode;
  77. me.dc = window['dataCode'];
  78. if (me.dc.length > 0) {
  79. me.reqDataMore(me);
  80. } else {
  81. me.changeData(fistDc);
  82. }
  83. });
  84. },
  85. //获取多个数据
  86. reqDataMore: function (me) {
  87. me.thatTempalteCode = me.dc[me.index];
  88. Promise.all([ me.profileDataRequest()]).then(function (datas) {
  89. me.profileRes.push(datas[0]);
  90. me.index++;
  91. if (me.dc.length > me.index) {
  92. me.reqDataMore(me);
  93. } else {
  94. me.changeData(me.firstCode);
  95. }
  96. });
  97. },
  98. changeData: function (fistDc) {
  99. var me = this,
  100. jsonData = [];
  101. me.dc.unshift(me.firstCode);
  102. $.each( me.profileRes, function (index) {
  103. jsonData.push(me.selectXmlDom(me.profileRes[index],me.dc[index]));
  104. });
  105. console.log(jsonData);
  106. if (jsonData.length > 0) {
  107. if (jsonData.length === 1 && !!!jsonData[0]) {
  108. me.thatPageContent.html(me.htmlStr);
  109. } else {
  110. me.renderProfileTemplate($.extend(true,{},me.mosaicData(jsonData)));
  111. }
  112. } else {
  113. me.thatPageContent.html(me.htmlStr);
  114. }
  115. plus.nativeUI.closeWaiting();
  116. },
  117. //渲染模板
  118. renderProfileTemplate: function (data) {
  119. this.thatPageContent.removeAttr('avalonctrl').attr('ms-controller',"viewController");
  120. var vm = avalon.define($.extend({},{"$id": "viewController"},data));
  121. avalon.scan();
  122. },
  123. //获取xml数据
  124. selectXmlDom: function (profileRes,tempalteCode) {
  125. var me = this,
  126. $dom = $(profileRes.data.replace(/<\?xml .*\?>/,'')),
  127. version = $dom.find(">version").length?$dom.find(">version").attr("code"):$dom.attr('version');
  128. $.trim(version) || (function () {
  129. version = $dom.find(">ClinicalDocument").length? '2.0.0.1' : '';
  130. })();
  131. if($.trim(version)) {
  132. var verNum = version.split('.')[0];
  133. var xmlToJson = window["dsXmlToJson"+tempalteCode+'_'+verNum],
  134. jsonData = {};
  135. if(xmlToJson && $.isFunction(xmlToJson)) {
  136. if(!profileRes.data || profileRes.data=="[]") {
  137. if(version=2) {
  138. profileRes.data = '<?xml version="1.0" encoding="utf-8"?><ClinicalDocument></ClinicalDocument>';
  139. } else {
  140. profileRes.data = '<?xml version="1.0" encoding="utf-8"?><root></root>';
  141. }
  142. }
  143. // xml 转 json
  144. if((typeof profileRes.data=='string')&&profileRes.data.constructor==String) {
  145. // 去除携带的脚本内容
  146. profileRes.data = profileRes.data.replace(/<script[^>]*?>[\s\S]*?<\/script>/ig,'');
  147. console.log(profileRes.data.replace(/<\?xml .*\?>/,''))
  148. jsonData = xmlToJson(profileRes.data.replace(/<\?xml .*\?>/,''));
  149. }
  150. }
  151. return jsonData;
  152. }
  153. },
  154. //数据拼接
  155. mosaicData: function (data) {
  156. for (var i = 1; i < data.length; i++) {
  157. data[i] && (function () {
  158. for (key in data[i]['data']) {
  159. data[0]['data'][key] = data[i]['data'][key];
  160. }
  161. })();
  162. }
  163. return data[0];
  164. }
  165. };
  166. var dataCode = [];
  167. // 基本信息(包括userAgent、上个页面传递的数据)
  168. var baseInfo = null,
  169. // 基础环境信息(包括当前webview)
  170. baseEnv = null;
  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. // 获取基本信息(包括userAgent、上个页面传递的数据)
  182. var getBaseInfo = function() {
  183. // 登录的相关信息
  184. var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent"))
  185. return {
  186. userAgent: userAgent,
  187. eventInfo: baseEnv.webview.eventInfo,
  188. patiInfo: baseEnv.webview.patiInfo
  189. }
  190. },
  191. // 获取基础环境信息
  192. getBaseEnvPromise = function () {
  193. var env = {
  194. webview: plus&&plus.webview.currentWebview()
  195. };
  196. return Promise.resolve().then(function(res) {
  197. return env;
  198. });
  199. },
  200. getCatalogPromise = function() {
  201. return getReqPromise('doctor/archives/event/catalog',{patient: baseInfo.patiInfo.code,event: baseInfo.eventInfo.id},'GET')
  202. .then(function(res) {
  203. if(res.status==200) {
  204. catalogs = res.data
  205. } else {
  206. mui.toast('档案类型获取失败');
  207. }
  208. },function() {
  209. mui.toast('档案类型获取失败');
  210. })
  211. },
  212. getCatalog = function() {
  213. var catalog = "";
  214. if(baseInfo.eventInfo && baseInfo.eventInfo.catalogCode) {
  215. catalog = baseInfo.eventInfo.catalogCode;
  216. }
  217. return catalog;
  218. },
  219. getCatalogName = function() {
  220. var name = "";
  221. if(baseInfo.eventInfo && baseInfo.eventInfo.label) {
  222. name = baseInfo.eventInfo.label;
  223. }else if(baseInfo.eventInfo && baseInfo.eventInfo.type){
  224. name = baseInfo.eventInfo.type;
  225. }
  226. return name;
  227. },
  228. // 初始化就诊事件列表
  229. initProfileList = function() {
  230. $selectedProfileName.text(getCatalogName());
  231. var tempalteCode = getCatalog();
  232. if(tempalteCode) {
  233. getProfileTemplateHtml(tempalteCode);
  234. }
  235. },
  236. getProfileTemplateHtml = function(tempalteCode){
  237. Profile.init({
  238. url: healthProfileServer+"doctor/archives/event/healthData",
  239. link: '../template/'+tempalteCode+'.html',
  240. thatMui: mui,
  241. thatPlus: plus,
  242. thatPromise: Promise,
  243. thatBaseInfo: baseInfo,
  244. thatTempalteCode: tempalteCode,
  245. thatSerial: baseInfo.eventInfo.serial,
  246. thatPageContent: $pageContent,
  247. });
  248. Profile.promiseAll();
  249. },
  250. // 绑定页面事件
  251. bindEvents = function () {
  252. };
  253. // 页面业务处理流程开始
  254. new Promise(function(resolve, reject) {
  255. mui.plusReady(function() {
  256. // plus已经准备好,可以往下执行
  257. resolve(true);
  258. });
  259. }).then(function() {
  260. // 获取基础环境信息
  261. return getBaseEnvPromise().then(function(env) {
  262. baseEnv = env;
  263. // 获取登录医生信息
  264. baseInfo = getBaseInfo();
  265. })
  266. //}).then(function() {
  267. // return getCatalogPromise();
  268. }).then(function() {
  269. initProfileList();
  270. // 绑定页面事件
  271. bindEvents();
  272. }).catch(function(e) {
  273. plus.nativeUI.closeWaiting();
  274. console && console.error(e);
  275. });