scale.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. import {post,getUrlArgObject} from './promise.js';
  2. $(function(){
  3. // 从地址栏获取参数,请求量表内容
  4. function GetQueryString(name){     
  5. var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");     
  6. var r = window.location.search.substr(1).match(reg);     
  7. if(r!=null)return  unescape(r[2]); return null;
  8. }
  9. var scaleInfo;
  10. var id = GetQueryString('id') || 40743;
  11. var name = GetQueryString('name') || "危重病人APACHEII评分表";
  12. var url = "http://192.168.2.236:5050/api/icss/push/pushInner";
  13. var urlParam = parseUrlParams(); //参数
  14. // console.log('urlParam', urlParam.lis)
  15. // 用GetQueryString方法从地址栏获取参数,暂时写死
  16. var params = {
  17. "age": getUrlArgObject('age') || 28,
  18. "featureType": getUrlArgObject('featureType') ||'21',
  19. "scaleId": getUrlArgObject('scaleId') ||40744,
  20. "scaleName": getUrlArgObject('scaleName') || "密西根糖尿病周围神经病评分(MDNS)",
  21. "sex": getUrlArgObject('sex') || 1,
  22. "diag": getUrlArgObject('diag') || "肺结核(复诊); ",
  23. "lis": getUrlArgObject('lis')?JSON.parse(getUrlArgObject('lis')) : []
  24. // "age": 28,
  25. // "featureType": '21',
  26. // "scaleId": id,
  27. // "scaleName": name,
  28. // "sex": 1,
  29. // "diag": "肺结核(复诊); ",
  30. // "lis": []
  31. }
  32. if(id){
  33. post(url, params).then((res) => {
  34. const data = res.data.data
  35. if(res.data.code==0){
  36. scaleInfo = data.scale;
  37. // console.log('量表数据为:',scaleInfo);
  38. for (var i = 0; i < scaleInfo.length; i++) {
  39. if( scaleInfo[i].type == 1) {
  40. var scaleList = JSON.parse(scaleInfo[i].content)
  41. console.log('scaleList', scaleList)
  42. renderCalcu(scaleList)
  43. } else {
  44. $('.content').append(scaleInfo[i].content)
  45. }
  46. $('input').on('change', function(e) {
  47. var indexList = $(this).attr('data-index').split(',')
  48. for (var i = 0; i < scaleList.group[indexList[0]].rows[indexList[1]].row[indexList[2]].details.length; i++) {
  49. scaleList.group[indexList[0]].rows[indexList[1]].row[indexList[2]].details[i].select = 0
  50. }
  51. scaleList.group[indexList[0]].rows[indexList[1]].row[indexList[2]].details[indexList[3]].select = 1
  52. // console.log('this',$(this).parent().parent().parent().attr('class'))
  53. const className = $(this).parent().parent().parent().attr('data-group')
  54. for(let i = 0; i < $('.'+className).length; i++) {
  55. $('.'+className).eq(i).removeClass('noSelect')
  56. }
  57. // for(let i = 0; i < $(this).parent().parent().parent().parent().find(className).length; i++) {
  58. // $(this).parent().parent().parent().parent().find(className).eq(i).removeClass('noSelect')
  59. // }
  60. // $(this).parent().parent().parent().removeClass('noSelect')
  61. })
  62. $('.calcuBtn').on('click', function() {
  63. // console.log('scaleList', scaleList)
  64. let allSelect = true
  65. for (let i = 0; i < scaleList.group.length; i++) {
  66. for (let j = 0; j < scaleList.group[i].rows.length; j++) {
  67. if(scaleList.group[i].rows[j].required == 1) {
  68. let itemSelect = false
  69. for (let x = 0; x < scaleList.group[i].rows[j].row.length; x++) {
  70. // console.log('scaleList.group[i].rows[j].row[x].details', scaleList.group[i].rows[j].row[x].details)
  71. for (let y = 0; y < scaleList.group[i].rows[j].row[x].details.length; y++) {
  72. if (scaleList.group[i].rows[j].row[x].details[y].select == 1) {
  73. itemSelect = true
  74. }
  75. }
  76. }
  77. if(!itemSelect) {
  78. allSelect = false
  79. $('.' + i + j).addClass('noSelect')
  80. }
  81. }
  82. }
  83. }
  84. if(allSelect) {
  85. getCalcuResult(scaleList)
  86. }
  87. })
  88. }
  89. }
  90. })
  91. }
  92. })
  93. function renderCalcu(scaleList) {
  94. console.log(scaleList)
  95. $("h1").html(scaleList.scaleName);
  96. var str = ''
  97. for(var j = 0; j < scaleList.group.length; j++) {
  98. str += '<div class="groupBox"> <div class="groupName">' + scaleList.group[j].groupName + '</div>';
  99. for (var x = 0; x < scaleList.group[j].rows.length; x++) {
  100. for (var y = 0; y < scaleList.group[j].rows[x].row.length; y++) {
  101. var str2 = ''
  102. for(var z = 0; z < scaleList.group[j].rows[x].row[y].details.length; z++) {
  103. str2 += '<span class="groupRowRadio"><input type=radio data-index='+ j +',' + x+',' + y +',' + z +' name='+ j + x + y +' id=' + j + x + y + z
  104. if (scaleList.group[j].rows[x].row[y].details[z].select == 1) {
  105. str2 += ' checked="checked"'
  106. }
  107. str2 += ' />'+'<label for="'+ j + x + y + z+'">' + scaleList.group[j].rows[x].row[y].details[z].detailName + '('+scaleList.group[j].rows[x].row[y].details[z].score +')'+'</label>'
  108. if (scaleList.group[j].rows[x].row[y].name+scaleList.group[j].rows[x].row[y].details[z].state == 1) {
  109. str2 += '<span class="groupRowRecommend">智能推荐</span>'
  110. }
  111. str2 += '</span>'
  112. }
  113. str +='<div class="groupRowWrapper '+ j + x +'" data-group='+ j + x +' id="'+ j + x + y +'"><div class="groupRowName"> <span class="groupRowIndex">'
  114. if(y==0) {
  115. str += (x+1)+'.'
  116. }
  117. str +='</span>' +scaleList.group[j].rows[x].row[y].name + '</div><div class="groupRowBox">' + str2 + '</div>' + '</div>'
  118. }
  119. }
  120. if(scaleList.group[j].groupCalculate.isShow == 1) {
  121. str += '<div class="calcu">记分:'+ scaleList.group[j].groupCalculate.result.value +' '+ scaleList.group[j].groupCalculate.result.text +'</div>'
  122. }
  123. str += '</div>'
  124. }
  125. var calcuStr = '<div class="allCalcuBox"><span class="allCalcu">总分:'
  126. if(scaleList.calculate && scaleList.calculate.result) {
  127. calcuStr += scaleList.calculate.result.value + ' ' + scaleList.calculate.result.text
  128. }
  129. calcuStr += '</span><span class="calcuBtn">计算<span></div>'
  130. var allStr = '<div class="calcuWrapper">' + str + calcuStr + '</div>'
  131. $('.content').append(allStr)
  132. }
  133. function parseUrlParams(){
  134. // var url = 'http://localhost:8082/scale.html?age=28&featureType=21&scaleId=40744&scaleName=密西根糖尿病周围神经病评分(MDNS)&sex=1&diag=肺结核(复诊);&lis=[{detailName: "HGB*3/HCT",maxValue: "",minValue: "",name: "血常规",otherValue: "",source: "0",time: "2019-05-07 17:11",uniqueName: "血常规-HGB*3/HCT",units: "",value: "4"}]'
  135. var url = window.location.search;
  136. var params = url.substring(url.indexOf('?')+1).split("&");
  137. var tmp = '',obj = {},it={};
  138. for(var i=0;i<params.length;i++) {
  139. it = params[i];
  140. tmp = it.split("=");
  141. if (tmp[0] && tmp[1]) {
  142. obj[tmp[0]] = tmp[1];
  143. }
  144. }
  145. return obj;
  146. // var obj={};
  147. // url.replace(/([^?&=]+)=([^&]+)/g,(_,k,v)=>q[k]=v);
  148. // return obj;
  149. }
  150. function getCalcuResult(data) {
  151. var url = "http://192.168.2.236:5050/api/icss/calc/calculate";
  152. const param = {
  153. type: 1,
  154. data: data
  155. }
  156. post(url, param).then((res) => {
  157. const data = res.data.data
  158. if (res.data.code == 0) {
  159. data.calculate.result = data.calcalculate.result
  160. for(let i = 0; i < data.group.length; i++) {
  161. for(let j = 0; j < data.group.length; j++) {
  162. if (data.group[i].groupName == data.group[j].groupName) {
  163. data.group[j].groupCalculate.result = data.group[i].groupCalculate.result
  164. }
  165. }
  166. }
  167. if($('.calcu')) {
  168. for (let i = 0; i < $('.calcu').length; i++) {
  169. let calcuItemName = $('.calcu').eq(i).prev().find('.groupName').html();
  170. let calcuItem = data.group.filter(function(item) {
  171. return item.groupName == calcuItemName
  172. })[0]
  173. $('.calcu').eq(i).html('记分:' + calcuItem.groupCalculate.result.value + ' ' + calcuItem.groupCalculate.result.text)
  174. }
  175. }
  176. $('.allCalcu').eq(0).html('总分:' + data.calculate.result.value + ' ' + data.calculate.result.text)
  177. } else {
  178. alert(res.msg)
  179. }
  180. })
  181. }