medical-examination-result.js 6.2 KB

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