health-chart.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /* 查询健康指标图表
  2. * @param {Object} type 健康指标类型(1血糖,2血压,3体重,4腰围)
  3. * @param {Object} begin 记录开始时间
  4. * @param {Object} end 记录结束时间
  5. * @param {Object} gi_type 就餐时间段(0:无)
  6. */
  7. function queryChatByTypePromise(charType,begin, end, gi_type, code) {
  8. //拼请求内容
  9. var params = {};
  10. params.type = charType;
  11. params.begin = begin+" 00:00:00";
  12. params.end = end+" 23:59:59";
  13. params.gi_type = gi_type;
  14. params.patient = code;
  15. return new Promise(function(resolve, reject) {
  16. //发送ajax请求
  17. sendPost("doctor/health_index/chart", params, function (res) {
  18. resolve(res)
  19. console.log(res);
  20. }, function(res){
  21. if (res.status == 200) {
  22. resolve(res)
  23. } else {
  24. //非200则为失败
  25. queryChartFailed(res);
  26. }
  27. });
  28. })
  29. }
  30. /**
  31. * 健康指标图表查询失败处理方法
  32. */
  33. function queryChartFailed(res) {
  34. if (res && res.msg) {
  35. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  36. } else {
  37. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载失败'}).show();
  38. }
  39. }
  40. function buildData(value, max, min) {
  41. if (!!!value) {
  42. return;
  43. }
  44. if(value < min) {
  45. return {
  46. value: value,
  47. itemStyle: {
  48. normal: {
  49. color: '#47a8ef'
  50. }
  51. }
  52. }
  53. } else if(value > max) {
  54. return {
  55. value: value,
  56. itemStyle: {
  57. normal: {
  58. color: '#ff6a56'
  59. }
  60. }
  61. }
  62. } else {
  63. return {
  64. value: value,
  65. itemStyle: {
  66. normal: {
  67. color: '#323232'
  68. }
  69. }
  70. }
  71. }
  72. }
  73. function getChartOptions(type,yAxisName,xAxisData,seriesData) {
  74. var options = {
  75. tooltip: {
  76. trigger: 'axis'
  77. },
  78. grid:{
  79. x:40,
  80. y:20,
  81. x2:35,
  82. y2:50
  83. },
  84. toolbox:{show:false},
  85. calculable:false,
  86. xAxis:[{
  87. type:"category",
  88. boundaryGap:false,
  89. data:xAxisData,
  90. axisLabel:{margin:6}
  91. }],
  92. yAxis:[{name:yAxisName,type:"value"}],
  93. series:[{
  94. name: type == 1 ? '血糖' : type == 3 ? '体重' : '腰围',
  95. type:"line",
  96. symbol:"emptyCircle",
  97. itemStyle: {
  98. normal: {
  99. borderWidth: 8,
  100. color: '#0ad800',
  101. lineStyle: { // 系列级个性化折线样式,横向渐变描边
  102. borderWidth: 2,
  103. color: "#5dd1d2",
  104. width: 4
  105. },
  106. nodeStyle: {
  107. borderWidth: 2,
  108. color: '#93DB70',
  109. borderColor: '#93DB70'
  110. }
  111. },
  112. emphasis: {
  113. label: {
  114. show: true
  115. }
  116. }
  117. },
  118. data: seriesData
  119. }]
  120. }
  121. return options;
  122. }
  123. function getChartOptions1(type,yAxisName,xAxisData,seriesData) {
  124. var options = {
  125. tooltip: {
  126. trigger: 'axis'
  127. },
  128. grid: {
  129. x: 40,
  130. y: 30,
  131. x2: 25,
  132. y2: 20
  133. },
  134. legend: {
  135. show: false,
  136. data: ['收缩压','舒张压']
  137. },
  138. toolbox: {
  139. show: false
  140. },
  141. calculable: false,
  142. xAxis: [{
  143. type: 'category',
  144. boundaryGap: false,
  145. data: xAxisData,
  146. axisLabel: {
  147. margin: 6
  148. }
  149. }],
  150. yAxis: [{
  151. name : yAxisName,
  152. type: 'value'
  153. }],
  154. series:seriesData
  155. }
  156. return options;
  157. }
  158. // type 健康指标类型(1血糖,2血压,3体重,4腰围)
  159. function createChartPromise(el,type,yAxisName,xAxisData,seriesData) {
  160. return new Promise(function(resolve, reject) {
  161. // 路径配置
  162. require.config({
  163. paths: {
  164. echarts: 'http://echarts.baidu.com/build/dist'
  165. }
  166. });
  167. require(['echarts',
  168. 'echarts/chart/line'] // 使用柱状图就加载bar模块,按需加载]
  169. ,function(echarts) {
  170. var myChart = echarts.init(el);
  171. // 为echarts对象加载数据
  172. if (type == 1 || type == 3 || type == 4) {
  173. myChart.setOption(getChartOptions(type,yAxisName,xAxisData,seriesData));
  174. resolve(myChart);
  175. }
  176. if (type == 2) {
  177. myChart.setOption(getChartOptions1(type,yAxisName,xAxisData,seriesData));
  178. resolve(myChart);
  179. }
  180. });
  181. })
  182. }