health-index-weigth-chart.js 4.8 KB

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