health-index-waistline-chart.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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(4, 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. // plus.nativeUI.closeWaiting();
  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. for (var i = 0; i < list.length; i++) {
  114. var data = list[i];
  115. if (!data) {
  116. continue;
  117. }
  118. xAxisArray.push(data.date.substr(5, 5));
  119. data1.push(data.value1);
  120. }
  121. allDatas.push(data1);
  122. for (var i = 0; i < 1; i++) {
  123. var series = {
  124. name: legendArray[i],
  125. type: 'line',
  126. symbol: 'emptyCircle',
  127. layerPadding: 0,
  128. nodePadding: 0,
  129. itemStyle: {
  130. normal: {
  131. borderWidth: 8,
  132. color: '#0ad800',
  133. lineStyle: { // 系列级个性化折线样式,横向渐变描边
  134. borderWidth: 2,
  135. color: '#5dd1d2',
  136. width: 4
  137. },
  138. nodeStyle: {
  139. borderWidth: 2,
  140. color: '#93DB70',
  141. borderColor: '#93DB70'
  142. }
  143. },
  144. emphasis: {
  145. label: {
  146. show: true
  147. }
  148. }
  149. },
  150. data: allDatas[i]
  151. };
  152. seriesArray.push(series);
  153. }
  154. // 路径配置
  155. require.config({
  156. paths: {
  157. echarts: 'http://echarts.baidu.com/build/dist'
  158. }
  159. });
  160. // 使用
  161. require(
  162. [
  163. 'echarts',
  164. 'echarts/chart/line' // 使用柱状图就加载bar模块,按需加载
  165. ],
  166. function(ec, num) {
  167. for (var i = 0; i < seriesArray.length; i++) {
  168. // 基于准备好的dom,初始化echarts图表
  169. var myChart = ec.init(document.getElementById('chart' + (i + 1)));
  170. console.log(myChart);
  171. var option = {
  172. tooltip: {
  173. trigger: 'axis'
  174. },
  175. grid: {
  176. x: 30,
  177. y: 20,
  178. x2: 25,
  179. y2: 20
  180. },
  181. legend: {
  182. show: false,
  183. data: legendArray
  184. },
  185. toolbox: {
  186. show: false
  187. },
  188. calculable: false,
  189. xAxis: [{
  190. type: 'category',
  191. boundaryGap: false,
  192. data: xAxisArray,
  193. axisLabel: {
  194. margin: 6
  195. }
  196. }],
  197. yAxis: [{
  198. type: 'value'
  199. }],
  200. series: [seriesArray[i]]
  201. };
  202. // 为echarts对象加载数据
  203. myChart.setOption(option);
  204. }
  205. }
  206. );
  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. });
  229. //添加数据添加监听
  230. window.addEventListener("refleshList", function(e) {
  231. //刷新列表
  232. if (curDays == 7) {
  233. //7天内
  234. queryChat(getDateBefore(6), getNowDate());
  235. } else if (curDays == 30) {
  236. //30天内
  237. queryChat(getDateBefore(29), getNowDate());
  238. } else {
  239. var date_begin = $("#date_begin").val();
  240. var date_end = $("#date_end").val();
  241. if (date_begin == null || date_begin.length == 0) {
  242. return;
  243. }
  244. if (date_end == null || date_end.length == 0) {
  245. return;
  246. }
  247. queryChat(date_begin, date_end);
  248. }
  249. });