medical-examination-result.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. (function($) {
  2. function Page(option) {
  3. this.init();
  4. }
  5. function getWechatInfo(){
  6. //从后台那边获取签名等信息
  7. var params = {};
  8. var url1 = window.location.href;
  9. params.pageUrl = url1;
  10. $.ajax("/wlyy/weixin/getSign", {
  11. data: params,
  12. dataType: "json",
  13. type: "post",
  14. success: function(res){
  15. if (res.status == 200) {
  16. var t = res.data.timestamp;
  17. var noncestr = res.data.noncestr;
  18. var signature = res.data.signature;
  19. wx.config({
  20. appId: appId, // 必填,公众号的唯一标识
  21. timestamp: t, // 必填,生成签名的时间戳
  22. nonceStr: noncestr, // 必填,生成签名的随机串
  23. signature: signature,// 必填,签名,见附录1
  24. jsApiList: [
  25. 'chooseImage',
  26. 'uploadImage',
  27. 'startRecord',
  28. 'stopRecord',
  29. 'onVoiceRecordEnd',
  30. 'playVoice',
  31. 'pauseVoice',
  32. 'stopVoice',
  33. 'onVoicePlayEnd',
  34. 'uploadVoice',
  35. 'getNetworkType'
  36. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  37. });
  38. // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
  39. wx.ready(function(){
  40. wx.getNetworkType({
  41. success: function (res) {
  42. networkStatus = res.networkType; // 返回网络类型2g,3g,4g,wifi
  43. }
  44. });
  45. });
  46. }
  47. }
  48. });
  49. }
  50. Page.prototype = {
  51. //初始化
  52. init: function() {
  53. this.initEvent();
  54. this.getReport();
  55. getWechatInfo();
  56. },
  57. //事件相关处理
  58. initEvent: function() {
  59. var self = this;
  60. $('#textContent').on('click','img',function() {
  61. var src= $(this).attr('src');
  62. var imglist = $('textContent img');
  63. var srcs= _.map(imglist,function(img){
  64. return $(img).attr('src')
  65. })
  66. wx.ready(function(){
  67. wx.previewImage({
  68. current: src, // 当前显示图片的http链接
  69. urls: srcs // 需要预览的图片http链接列表
  70. });
  71. });
  72. })
  73. },
  74. //获取报告
  75. getReport: function() {
  76. var code = JSON.parse(localStorage.getItem(agentName)).uid;
  77. var ct_id = this.GetQueryString('ctId');
  78. var loading = dialog({
  79. contentType: 'load',
  80. skin: 'bk-popup'
  81. });
  82. var self = this;
  83. loading.show();
  84. sendPost(server_jm + "/medicine/physicalExamination/showDetail", {
  85. patientCode: 'P20161011001',
  86. ct_id: ct_id
  87. }, "json", "get", function(res) {
  88. loading.close();
  89. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg||"数据请求失败",bottom:true}).show();
  90. }, function(res) {
  91. loading.close();
  92. if(res.status == 200) {
  93. self.showConclusionByType(res.recordset)
  94. self.showConclusionChart(res.recordset)
  95. self.showNatureChart(res.recordset)
  96. } else {
  97. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg,bottom:true}).show();
  98. }
  99. });
  100. },
  101. //获取浏览器参数
  102. GetQueryString: function(name) {
  103. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  104. var r = window.location.search.substr(1).match(reg);
  105. if(r != null) return unescape(r[2]);
  106. return null;
  107. },
  108. // 根据类型显示体检结论
  109. showConclusionByType: function(data) {
  110. var reports = [];
  111. var _sort = function(chain) {
  112. return chain.map(function(r) {
  113. if(r.cl_template) { // 去除所有内嵌样式
  114. r.cl_template = r.cl_template.replace(/style='[^']*'/ig, '')
  115. }
  116. return r;
  117. }).sortBy(function(r) {
  118. return (r.cl_sort||0)*1
  119. }).value()
  120. }
  121. if(data) {
  122. reports = [];
  123. // 去除cl_template中可能含有的js脚本
  124. _.each(data.report||[],function(r) {
  125. if(r.cl_template) {
  126. r.cl_template = r.cl_template.replace(/<script.*?>.*?<\/script>/ig, '')
  127. }
  128. reports.push(r)
  129. })
  130. var results = _.chain(reports).groupBy(function(r) {
  131. // 根据cl_type分组
  132. return r.cl_type
  133. }).map(function(rs,k) {
  134. // 将分组后的结果{"类型名(cl_type)": report}转换成数组
  135. if(k == "状态采集/四诊采集") {
  136. var images = [], videos = [];
  137. _.each(rs, function(r) {
  138. $temp = $('<div>'+r.cl_template+'</div>');
  139. _.each($temp.find('img'),function(img) {
  140. images.push($(img).attr('src'))
  141. });
  142. _.each($temp.find('video'),function(v) {
  143. videos.push($(v).attr('src'))
  144. });
  145. })
  146. return {
  147. type: k,
  148. images: images,
  149. videos: videos
  150. }
  151. } else if(k == "健康状态要素积分") {
  152. return {
  153. type: k,
  154. rows: _sort(_.chain(rs).filter(function(r) {
  155. return /^<tr>/.test(r.cl_template)
  156. })),
  157. others: _sort(_.chain(rs).filter(function(r) {
  158. return !(/^<tr>/.test(r.cl_template))
  159. }))
  160. }
  161. } else {
  162. return {
  163. type: k,
  164. reports: _sort(_.chain(rs))
  165. }
  166. }
  167. }).value();
  168. var html = template('reportsTmpl',{reports: results});
  169. $('#textContent').html(html);
  170. $('#textContent *:hidden').show();
  171. }
  172. },
  173. showConclusionChart: function(data) {
  174. data.reportDetail && conclusionChart.init(data.reportDetail.conclusion)
  175. },
  176. showNatureChart: function(data) {
  177. data.reportDetail && natureChart.init(data.reportDetail.nature)
  178. }
  179. };
  180. $(document).ready(function() {
  181. var page = new Page();
  182. });
  183. })(jQuery);
  184. template.helper("setPhoto", function(p) {
  185. return getImgUrl(p);
  186. });