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. lastXT = res.data.xt.recordDate;
  44. lastXY = res.data.xy.recordDate;
  45. if(lastXT || lastXY) {
  46. // 初始化执行
  47. getBodyRecord(tabIndex, dayIndex);
  48. } else {
  49. showWarningMsg("没有可查阅的体征记录");
  50. }
  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. $('.danwei').html(tab == 0 ? '单位(mmol/L)' : '单位(mmHg)');
  90. var dayNum = 0;
  91. switch(day) {
  92. case 0:
  93. dayNum = 7;break;
  94. case 1:
  95. dayNum = 30;break;
  96. case 2:
  97. dayNum = 90;break;
  98. case 3:
  99. dayNum = 365 / 2;break;
  100. }
  101. var type = (tab == 0 ? 1 : 2),
  102. startdate = (tab == 0 ? lastXT : lastXY),
  103. enddate = getDateFromCurrentDate(startdate, -dayNum),
  104. gi_type = (tab == 0 ? 1 : 0);// 字段不清楚暂时不处理
  105. $('.data-record').html(enddate.substr(0, 11) + '至' + startdate.substr(0,11));
  106. var recordData = {
  107. type: type,
  108. begin: enddate,
  109. end: startdate,
  110. gi_type: gi_type,
  111. patient: patient
  112. }
  113. // 获取体征记录
  114. bodyRecordApis.getBodyRecordData({data: recordData}).then(function(res){
  115. if(res.status == 200){
  116. var list = res.list,
  117. len = list.length;
  118. list.reverse();
  119. if(len < 1) {
  120. showWarningMsg("该居民无体征记录");return;
  121. }
  122. for(var i = 0; i < len; i++) {
  123. if(len == 1) {
  124. dataCanvas.labels = [enddate.substr(5, 5), list[i].date.substr(5, 5)];
  125. dataCanvas.datasets[0].data = [null, list[i].value1];
  126. } else {
  127. dataCanvas.labels[i] = list[i].date.substr(5, 5);
  128. dataCanvas.datasets[0].data[i] = list[i].value1;
  129. }
  130. if(tabIndex == 1) {
  131. if(len == 1) {
  132. dataCanvas.datasets[1].data = [null, list[i].value2];
  133. } else {
  134. dataCanvas.datasets[1].data[i] = list[i].value2;
  135. }
  136. } else {
  137. dataCanvas.datasets[1].data[i] = []
  138. }
  139. }
  140. // 绘制图
  141. if(myLineChart) {// 如果构造过,解析
  142. myLineChart.destroy();
  143. }
  144. myLineChart = new Chart(ctx).Line(dataCanvas, defaults);
  145. }else{
  146. showWarningMsg(res.msg)
  147. }
  148. })
  149. }
  150. })(jQuery)