var curDays = 7; $('input[data-time=date]').val('7天内'); $(function() { queryChat(getDateBefore(6), getNowDate()); /* 选择日期 */ var opt1 = { preset: 'date', theme: 'ios', lang: 'zh', dateFormat: 'yy-mm-dd', minDate: new Date(1900, 01, 01), onSelect: function(valueText, inst) { var date_begin = $("#date_begin").val(); var date_end = $("#date_end").val(); if (date_begin == null || date_begin.length == 0) { return; } if (date_end == null || date_end.length == 0) { return; } queryChat(date_begin, date_end); } }; $('input[data-time=date1]').mobiscroll(opt1); $('input[data-time=date2]').mobiscroll(opt1); var swiper = new Swiper('.swiper-container', { pagination: '.swiper-pagination', paginationClickable: false }); //咨询药店 $('input[data-time=date]').mobiscroll({ theme: 'ios', lang: 'zh', formatValue: function(d) { return d.join('-'); }, customWheels: true, wheels: [ [{ keys: ['1', '2', '3'], values: ['7天内', '30天内', '自定义时间'] }] ], onSelect: function(valueText, inst) { var dd = eval("[" + valueText + "]"); $('input[data-time=date]').val(dd[0].values); if (dd[0].keys == "3") { $(".time-began").show(); } else { $(".time-began").hide(); } if (dd[0].keys == 1) { //7天内 if (curDays == 7) { return; } curDays = 7; queryChat(getDateBefore(6), getNowDate()); } else if (dd[0].keys == 2) { //30天内 if (curDays == 30) { return; } curDays = 30; queryChat(getDateBefore(29), getNowDate()); } else { curDays = 99; } } }); }); function queryChat(date_begin, date_end) { if (parseFloat(date_begin.replace(/-/g, "")) > parseFloat(date_end.replace(/-/g, ""))) { dialog({contentType:'tipsbox', skin:'bk-popup' , content:'开始时间不能晚于结束时间'}).show(); return; } //发送请求 queryChatByType(1, date_begin, date_end, queryChartSuccesss); } /** * 健康指标图表查询成功处理方法 */ function queryChartSuccesss(res) { if (res.status == 200) { d.close(); //成功 showChart(res.list); } else { //非200则为失败 queryChartFailed(res); } } function buildData(value, max, min) { if ((value > 0 && value < min) || value > max) { return { value: value, itemStyle: { normal: { color: '#f00' } } } }else{ return value; } } function showChart(list) { var legendArray = ['早餐前血糖', '早餐后血糖', '午餐前血糖', '午餐后血糖', '晚餐前血糖', '晚餐后血糖', '睡前血糖']; var xAxisArray = new Array(); var seriesArray = new Array(); var allDatas = new Array(); var data1 = new Array(); var data2 = new Array(); var data3 = new Array(); var data4 = new Array(); var data5 = new Array(); var data6 = new Array(); var data7 = new Array(); for (var i = 0; i < list.length; i++) { var data = list[i]; if (!data) { continue; } xAxisArray.push(data.date.substr(5, 5)); data1.push(buildData(data.value1, 6.1, 3.9)); data2.push(buildData(data.value2, 7.8, 4.4)); data3.push(buildData(data.value3, 6.1, 3.9)); data4.push(buildData(data.value4, 7.8, 4.4)); data5.push(buildData(data.value5, 6.1, 3.9)); data6.push(buildData(data.value6, 7.8, 4.4)); data7.push(buildData(data.value7, 6.1, 3.9)); } allDatas.push(data1); allDatas.push(data2); allDatas.push(data3); allDatas.push(data4); allDatas.push(data5); allDatas.push(data6); allDatas.push(data7); for (var i = 0; i < 7; i++) { var series = { name: legendArray[i], type: 'line', symbol: 'emptyCircle', layerPadding: 0, nodePadding: 0, itemStyle: { normal: { borderWidth: 8, color: '#0ad800', lineStyle: { // 系列级个性化折线样式,横向渐变描边 borderWidth: 2, color: '#5dd1d2', width: 4 }, nodeStyle: { borderWidth: 2, color: '#93DB70', borderColor: '#93DB70' } }, emphasis: { label: { show: true } } }, data: allDatas[i] }; seriesArray.push(series); } // 路径配置 require.config({ paths: { echarts: 'http://echarts.baidu.com/build/dist' } }); // 使用 require( [ 'echarts', 'echarts/chart/line' // 使用柱状图就加载bar模块,按需加载 ], function(ec, num) { for (var i = 0; i < seriesArray.length; i++) { // 基于准备好的dom,初始化echarts图表 var myChart = ec.init(document.getElementById('chart' + (i + 1))); // console.log(myChart); var option = { tooltip: { trigger: 'axis' }, grid: { x: 30, y: 20, x2: 25, y2: 20 }, legend: { show: false, data: legendArray }, toolbox: { show: false }, calculable: false, xAxis: [{ type: 'category', boundaryGap: false, data: xAxisArray, axisLabel: { margin: 6 } }], yAxis: [{ type: 'value' }], series: [seriesArray[i]] }; // 为echarts对象加载数据 myChart.setOption(option); } } ); } //添加数据添加监听 window.addEventListener("refleshList", function(e) { //刷新列表 if (curDays == 7) { //7天内 queryChat(getDateBefore(6), getNowDate()); } else if (curDays == 30) { //30天内 queryChat(getDateBefore(29), getNowDate()); } else { var date_begin = $("#date_begin").val(); var date_end = $("#date_end").val(); if (date_begin == null || date_begin.length == 0) { return; } if (date_end == null || date_end.length == 0) { return; } queryChat(date_begin, date_end); } });