body-record.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. (function() {
  2. var request = getRequest(),
  3. patient = request.patiCode || '';
  4. var tabIndex = 0,
  5. dayIndex = 0;
  6. $('.tab-record span').click(function() {
  7. tabIndex = $(this).index();
  8. dataCanvas.labels = [];
  9. dataCanvas.datasets[0].data = [];
  10. dataCanvas.datasets[1].data = [];
  11. indexHover(this);
  12. dayIndex = 0;
  13. var ele = $('.day-record span').get(0)
  14. indexHover(ele);
  15. // 切换数据
  16. getBodyRecord(tabIndex, dayIndex);
  17. });
  18. $('.day-record span').click(function() {
  19. dayIndex = $(this).index();
  20. indexHover(this);
  21. // 切换数据
  22. getBodyRecord(tabIndex, dayIndex);
  23. });
  24. function indexHover(ele) {
  25. $(ele).siblings().removeClass('f-hover');
  26. $(ele).addClass('f-hover');
  27. }
  28. // 时间推算
  29. function getDateFromCurrentDate(fromDate, dayInterval) {
  30. var curDate = new Date(Date.parse(fromDate.replace(/-/g, "/")));
  31. curDate.setDate(curDate.getDate() + dayInterval);
  32. var year = curDate.getFullYear();
  33. var month = (curDate.getMonth() + 1) < 10 ? "0" + (curDate.getMonth() + 1) : (curDate.getMonth() + 1);
  34. var day = curDate.getDate() < 10 ? "0" + curDate.getDate() : curDate.getDate();
  35. return year + "-" + month + "-" + day + " 00:00:00";
  36. };
  37. // 获取最后一条数据
  38. var dataLast = {patient: patient};
  39. var lastXT = '',
  40. lastXY = '';
  41. bodyRecordApis.getBodyRecoredLast({data: dataLast}).then(function(res){
  42. if(res.status == 200){
  43. if(!res.data.xt || !res.data.xy) {
  44. showWarningMsg("该居民无体征记录");
  45. return;
  46. }
  47. lastXT = res.data.xt.recordDate;
  48. lastXY = res.data.xy.recordDate;
  49. // 初始化执行
  50. getBodyRecord(tabIndex, dayIndex);
  51. }else{
  52. showWarningMsg(res.msg)
  53. }
  54. })
  55. // 绘制折线图初始定义
  56. var ctx = document.getElementById('canvas').getContext("2d");
  57. var dataCanvas = {
  58. labels : [],
  59. datasets : [
  60. {
  61. fillColor : "rgba(220,220,220,0.5)",
  62. strokeColor : "rgba(220,220,220,1)",
  63. pointColor : "rgba(220,220,220,1)",
  64. pointStrokeColor : "#fff",
  65. data : []
  66. },
  67. {
  68. fillColor : "rgba(151,187,205,0.5)",
  69. strokeColor : "rgba(151,187,205,1)",
  70. pointColor : "rgba(151,187,205,1)",
  71. pointStrokeColor : "rgba(151,187,205,1)",
  72. data : []
  73. }
  74. ]
  75. };
  76. var defaults = {
  77. scaleStartValue : 0,
  78. scaleShowLabels : true,
  79. datasetFill : false, // 是否填充数据集
  80. animation : true, // 是否执行动画
  81. animationSteps : 60, // 动画的时间
  82. animationEasing : "easeOutQuart", // 动画的特效
  83. onAnimationComplete : null // 动画完成时的执行函数
  84. }
  85. var myLineChart = null;
  86. // new Chart(ctx).Line(dataCanvas, defaults);
  87. // 获取数据
  88. function getBodyRecord(tab, day) {
  89. if(!lastXT || !lastXY) {
  90. showWarningMsg("该居民无体征记录");
  91. return;
  92. }
  93. $('.danwei').html(tab == 0 ? '单位(mmol/L)' : '单位(mmHg)');
  94. var dayNum = 0;
  95. switch(day) {
  96. case 0:
  97. dayNum = 7;break;
  98. case 1:
  99. dayNum = 30;break;
  100. case 2:
  101. dayNum = 90;break;
  102. case 3:
  103. dayNum = 365 / 2;break;
  104. }
  105. var type = (tab == 0 ? 1 : 2),
  106. startdate = (tab == 0 ? lastXT : lastXY),
  107. enddate = getDateFromCurrentDate(startdate, -dayNum),
  108. gi_type = (tab == 0 ? 1 : 0);// 字段不清楚暂时不处理
  109. $('.data-record').html(enddate.substr(0, 11) + '至' + startdate.substr(0,11));
  110. var recordData = {
  111. type: type,
  112. begin: enddate,
  113. end: startdate,
  114. gi_type: gi_type,
  115. patient: patient
  116. }
  117. // 获取体征记录
  118. bodyRecordApis.getBodyRecordData({data: recordData}).then(function(res){
  119. if(res.status == 200){
  120. var list = res.list,
  121. len = list.length;
  122. list.reverse();
  123. for(var i = 0; i < len; i++) {
  124. if(len == 1) {
  125. dataCanvas.labels = [enddate.substr(5, 5), list[i].date.substr(5, 5)];
  126. dataCanvas.datasets[0].data = [null, list[i].value1];
  127. } else {
  128. dataCanvas.labels[i] = list[i].date.substr(5, 5);
  129. dataCanvas.datasets[0].data[i] = list[i].value1;
  130. }
  131. if(tabIndex == 1) {
  132. if(len == 1) {
  133. dataCanvas.datasets[1].data = [null, list[i].value2];
  134. } else {
  135. dataCanvas.datasets[1].data[i] = list[i].value2;
  136. }
  137. } else {
  138. dataCanvas.datasets[1].data[i] = []
  139. }
  140. }
  141. // 绘制图
  142. if(myLineChart) {// 如果构造过,解析
  143. myLineChart.destroy();
  144. }
  145. myLineChart = new Chart(ctx).Line(dataCanvas, defaults);
  146. }else{
  147. showWarningMsg(res.msg)
  148. }
  149. })
  150. }
  151. })(jQuery)