health-index-bloodsugar-chart.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. var curDays = 7;
  2. $('input[data-time=date]').val('7天内');
  3. $(function() {
  4. queryChat(getDateBefore(6), getNowDate());
  5. /* 选择日期 */
  6. var opt1 = {
  7. preset: 'date',
  8. theme: 'ios',
  9. lang: 'zh',
  10. dateFormat: 'yy-mm-dd',
  11. minDate: new Date(1900, 01, 01),
  12. onSelect: function(valueText, inst) {
  13. var date_begin = $("#date_begin").val();
  14. var date_end = $("#date_end").val();
  15. if (date_begin == null || date_begin.length == 0) {
  16. return;
  17. }
  18. if (date_end == null || date_end.length == 0) {
  19. return;
  20. }
  21. queryChat(date_begin, date_end);
  22. }
  23. };
  24. $('input[data-time=date1]').mobiscroll(opt1);
  25. $('input[data-time=date2]').mobiscroll(opt1);
  26. var swiper = new Swiper('.swiper-container', {
  27. pagination: '.swiper-pagination',
  28. paginationClickable: false
  29. });
  30. //咨询药店
  31. $('input[data-time=date]').mobiscroll({
  32. theme: 'ios',
  33. lang: 'zh',
  34. formatValue: function(d) {
  35. return d.join('-');
  36. },
  37. customWheels: true,
  38. wheels: [
  39. [{
  40. keys: ['1', '2', '3'],
  41. values: ['7天内', '30天内', '自定义时间']
  42. }]
  43. ],
  44. onSelect: function(valueText, inst) {
  45. var dd = eval("[" + valueText + "]");
  46. $('input[data-time=date]').val(dd[0].values);
  47. if (dd[0].keys == "3") {
  48. $(".time-began").show();
  49. } else {
  50. $(".time-began").hide();
  51. }
  52. if (dd[0].keys == 1) {
  53. //7天内
  54. if (curDays == 7) {
  55. return;
  56. }
  57. curDays = 7;
  58. queryChat(getDateBefore(6), getNowDate());
  59. } else if (dd[0].keys == 2) {
  60. //30天内
  61. if (curDays == 30) {
  62. return;
  63. }
  64. curDays = 30;
  65. queryChat(getDateBefore(29), getNowDate());
  66. } else {
  67. curDays = 99;
  68. }
  69. }
  70. });
  71. });
  72. function queryChat(date_begin, date_end) {
  73. if (parseFloat(date_begin.replace(/-/g, "")) > parseFloat(date_end.replace(/-/g, ""))) {
  74. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'开始时间不能晚于结束时间'}).show();
  75. return;
  76. }
  77. //发送请求
  78. queryChatByType(1, date_begin, date_end, queryChartSuccesss);
  79. }
  80. /**
  81. * 健康指标图表查询成功处理方法
  82. */
  83. function queryChartSuccesss(res) {
  84. if (res.status == 200) {
  85. d.close();
  86. //成功
  87. showChart(res.list);
  88. } else {
  89. //非200则为失败
  90. queryChartFailed(res);
  91. }
  92. }
  93. function buildData(value, max, min) {
  94. if ((value > 0 && value < min) || value > max) {
  95. return {
  96. value: value,
  97. itemStyle: {
  98. normal: {
  99. color: '#f00'
  100. }
  101. }
  102. }
  103. }else{
  104. return value;
  105. }
  106. }
  107. function showChart(list) {
  108. var legendArray = ['早餐前血糖', '早餐后血糖', '午餐前血糖', '午餐后血糖', '晚餐前血糖', '晚餐后血糖', '睡前血糖'];
  109. var xAxisArray = new Array();
  110. var seriesArray = new Array();
  111. var allDatas = new Array();
  112. var data1 = new Array();
  113. var data2 = new Array();
  114. var data3 = new Array();
  115. var data4 = new Array();
  116. var data5 = new Array();
  117. var data6 = new Array();
  118. var data7 = new Array();
  119. for (var i = 0; i < list.length; i++) {
  120. var data = list[i];
  121. if (!data) {
  122. continue;
  123. }
  124. xAxisArray.push(data.date.substr(5, 5));
  125. data1.push(buildData(data.value1, 6.1, 3.9));
  126. data2.push(buildData(data.value2, 7.8, 4.4));
  127. data3.push(buildData(data.value3, 6.1, 3.9));
  128. data4.push(buildData(data.value4, 7.8, 4.4));
  129. data5.push(buildData(data.value5, 6.1, 3.9));
  130. data6.push(buildData(data.value6, 7.8, 4.4));
  131. data7.push(buildData(data.value7, 6.1, 3.9));
  132. }
  133. allDatas.push(data1);
  134. allDatas.push(data2);
  135. allDatas.push(data3);
  136. allDatas.push(data4);
  137. allDatas.push(data5);
  138. allDatas.push(data6);
  139. allDatas.push(data7);
  140. for (var i = 0; i < 7; i++) {
  141. var series = {
  142. name: legendArray[i],
  143. type: 'line',
  144. symbol: 'emptyCircle',
  145. layerPadding: 0,
  146. nodePadding: 0,
  147. itemStyle: {
  148. normal: {
  149. borderWidth: 8,
  150. color: '#0ad800',
  151. lineStyle: { // 系列级个性化折线样式,横向渐变描边
  152. borderWidth: 2,
  153. color: '#5dd1d2',
  154. width: 4
  155. },
  156. nodeStyle: {
  157. borderWidth: 2,
  158. color: '#93DB70',
  159. borderColor: '#93DB70'
  160. }
  161. },
  162. emphasis: {
  163. label: {
  164. show: true
  165. }
  166. }
  167. },
  168. data: allDatas[i]
  169. };
  170. seriesArray.push(series);
  171. }
  172. // 路径配置
  173. require.config({
  174. paths: {
  175. echarts: 'http://echarts.baidu.com/build/dist'
  176. }
  177. });
  178. // 使用
  179. require(
  180. [
  181. 'echarts',
  182. 'echarts/chart/line' // 使用柱状图就加载bar模块,按需加载
  183. ],
  184. function(ec, num) {
  185. for (var i = 0; i < seriesArray.length; i++) {
  186. // 基于准备好的dom,初始化echarts图表
  187. var myChart = ec.init(document.getElementById('chart' + (i + 1)));
  188. // console.log(myChart);
  189. var option = {
  190. tooltip: {
  191. trigger: 'axis'
  192. },
  193. grid: {
  194. x: 30,
  195. y: 20,
  196. x2: 25,
  197. y2: 20
  198. },
  199. legend: {
  200. show: false,
  201. data: legendArray
  202. },
  203. toolbox: {
  204. show: false
  205. },
  206. calculable: false,
  207. xAxis: [{
  208. type: 'category',
  209. boundaryGap: false,
  210. data: xAxisArray,
  211. axisLabel: {
  212. margin: 6
  213. }
  214. }],
  215. yAxis: [{
  216. type: 'value'
  217. }],
  218. series: [seriesArray[i]]
  219. };
  220. // 为echarts对象加载数据
  221. myChart.setOption(option);
  222. }
  223. }
  224. );
  225. }
  226. //添加数据添加监听
  227. window.addEventListener("refleshList", function(e) {
  228. //刷新列表
  229. if (curDays == 7) {
  230. //7天内
  231. queryChat(getDateBefore(6), getNowDate());
  232. } else if (curDays == 30) {
  233. //30天内
  234. queryChat(getDateBefore(29), getNowDate());
  235. } else {
  236. var date_begin = $("#date_begin").val();
  237. var date_end = $("#date_end").val();
  238. if (date_begin == null || date_begin.length == 0) {
  239. return;
  240. }
  241. if (date_end == null || date_end.length == 0) {
  242. return;
  243. }
  244. queryChat(date_begin, date_end);
  245. }
  246. });