123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 |
- (function(){
- Vue.component('chart-section', {
- template: '<div class="panel-box4">\
- <h4 class="c-b5e1fc c-f16 c-t-center">{{sectionTitle}}(数据展示)</h4>\
- <div v-show="hasData" id="lineChart" style="height: calc(100% - 0.1rem);"></div>\
- <div v-show="!hasData" class="no-result-panel">\
- <div class="no-result-img">\
- <img src="../images/wushuju_icon.png">\
- </div>\
- <div class="no-result-text">暂无相关体征数据</div>\
- </div>\
- </div>',
- props: ['patient'],
- data: function() {
- return {
- sectionTitle: "血压",
- hasData: true,
- fontSize: 0.007 * window.screen.width,
- dateType: 1
- }
- },
- mounted: function(){
- var vm = this;
- getChartInfo(vm);
- },
- methods: {}
- });
-
- function getChartInfo(vm){
- EventBus.$on('get-chart-data', function(arg){
- vm.dateType = arg.dateType ? arg.dateType : vm.dateType;
- var type = arg.type,
- gi_type = arg.gi_type,
- dateType = vm.dateType,
- startDate = getStartDate(dateType),
- endDate = getEndDate(),
- time = getTimeName(dateType);
- var params = {
- patient: vm.patient,
- type: type, //1-血糖,2-血压,3-体重,4-腰围
- gi_type: gi_type, //就餐类型
- time: time,
- begin: startDate,
- end: endDate
- };
- patientAPI.getChartData(params).then(function(res){
- if(res.status == 200){
- //触发指标分析内容修改
- EventBus.$emit("get-zhibiao-analysis", {content: res.data.content});
- //触发指标统计值
- EventBus.$emit("get-zhibiao-count", {total: res.data.total});
- if(res.data.list.length == 0){
- vm.hasData = false;
- return false;
- }else{
- vm.hasData = true;
- }
- var xData = _.map(res.data.list, function(o){
- return o.date;
- });
-
- // 为echarts对象加载数据
- if (type == 1) {
- var xuetangDuring = ['','早餐前', '早餐后', '午餐前', '午餐后', '晚餐前', '晚餐后', '睡前'],
- labelName = xuetangDuring[gi_type] + "血糖";
- vm.sectionTitle = labelName;
- var seriesData = getSeriesData(res.data.list, labelName, vm.fontSize);
- var legent = {show: false};
- drawLineChart(xData, seriesData, legent, vm.fontSize);
- }
- if (type == 2) {
- var seriesData = getSeriesData2(res.data.list, vm.fontSize);
- var legent = {
- top: 'top',
- data:['舒张压', '收缩压'],
- textStyle: {
- color: "#fff",
- fontSize: vm.fontSize
- }
- };
- drawLineChart(xData, seriesData, legent, vm.fontSize);
- }
- }else{
- console.log(res.msg);
- }
- });
- })
- }
-
- function getSeriesData(data, labelName, fontSize){
- //餐前血糖值: [7.0, 4.0]
- //餐后血糖值: [4.0, 11.1]
- var list = _.map(data, function(o){
- if(o.type == 1){ //血糖
- if(["1", "3", "5", "7"].indexOf(o.value2) > -1){ //餐前数据
- return buildData(parseFloat(o.value1), 7.0, 4.0);
- }else{
- return buildData(parseFloat(o.value1), 11.1, 4.0)
- }
- }else{
- return "";
- }
- });
- var obj = {
- name: labelName+'血糖',
- type: 'line',
- smooth: true,
- symbol: "circle",
- symbolSize: 0.005 * window.screen.width,
- data: list,
- itemStyle:{
- normal: {
- borderWidth: 10,
- color: '#03d95d',
- lineStyle: { // 系列级个性化折线样式,横向渐变描边
- borderWidth: 2,
- color: '#CC66FF',
- width: window.screen.width > 3000 ? 4 : 2
- },
- label:{
- textStyle: {
- fontSize: fontSize
- }
- }
- }
- }
- };
-
- return [obj];
- }
-
- function getSeriesData2(data, fontSize){
- //获取收缩压和舒张压的值
- //舒张压
- var list1 = _.map(data, function(o){
- return buildData(parseFloat(o.value1), 90, 60);
- });
- //收缩压
- var list2 = _.map(data, function(o){
- return buildData(parseFloat(o.value2), 140, 90)
- });
-
- return [{
- name: "舒张压",
- type: 'line',
- smooth: true,
- symbol: "circle",
- symbolSize: 0.005 * window.screen.width,
- data: list1,
- itemStyle:{
- normal: {
- borderWidth: 10,
- color: '#CC66FF',
- lineStyle: { // 系列级个性化折线样式,横向渐变描边
- borderWidth: 2,
- width: window.screen.width > 3000 ? 4 : 2
- },
- label:{
- textStyle: {
- fontSize: fontSize
- }
- }
- },
- emphasis: {
- label: {
- show: true
- }
- }
- }
- },{
- name: "收缩压",
- type: 'line',
- smooth: true,
- symbol: "circle",
- symbolSize: 0.005 * window.screen.width,
- data: list2,
- itemStyle:{
- normal: {
- borderWidth: 10,
- color: '#5dd1d2',
- lineStyle: { // 系列级个性化折线样式,横向渐变描边
- borderWidth: 2,
- width: window.screen.width > 3000 ? 4 : 2
- },
- label:{
- textStyle: {
- fontSize: fontSize
- }
- }
- },
- emphasis: {
- label: {
- show: true
- }
- }
- }
- }]
- }
-
- function buildData(value, max, min) {
- if(value > 0 && value < min) {
- return {
- value: value,
- itemStyle: {
- normal: {
- color: '#fd9c0d'
- }
- }
- }
- } else if(value > 0 && value > max) {
- return {
- value: value,
- itemStyle: {
- normal: {
- color: '#ff3803'
- }
- }
- }
- }else{
- return {
- value: value,
- itemStyle:{
- normal: {
- color: "#0ad800"
- }
- }
- }
- }
- }
- function drawLineChart(xData, seriesData, legent, fontSize){
- $("#lineChart").show();
- var lastIndex = xData.length % 10;
- if(xData.length >10 ){
- var dataZoom_end = 100-(9/xData.length)*100;
- }else{
- var dataZoom_end = 0;
- }
- var lineCharts = echarts.init(document.getElementById('lineChart'));
- var options = {
- tooltip: {
- trigger: 'axis',
- textStyle: {
- fontSize: fontSize,
- color: '#0fa5f2'
- },
- backgroundColor: "#B5E1FC"
- },
- legend: legent,
- grid: {
- left: '5%',
- right: '5%',
- bottom: '15%',
- top: '12%',
- containLabel: true
- },
- xAxis: {
- type: 'category',
- boundaryGap: false,
- axisLabel: {
- interval:0,//横轴信息全部显示
- fontSize: fontSize,
- formatter: function (value, index) {
- return value.substr(5,5);
- }
- },
- nameTextStyle: {
- fontSize: fontSize
- },
- axisLine:{
- lineStyle:{
- color:'#b5e1fc',
- width:2
- }
- },
- data: xData,
- splitLine: {
- show: false
- },
- },
- yAxis: {
- type: 'value',
- axisPointer: {
- snap: true
- },
- scale: true,
- minInterval: 1,
- boundaryGap: ['10%', '30%'],
- axisLine: {
- "lineStyle": {
- "color": "#b5e1fc",
- "width": window.screen.width > 3000 ? 2 : 1
- }
- },
- axisLabel:{
- fontSize: fontSize
- },
- nameTextStyle: {
- fontSize: fontSize
- },
- },
- dataZoom: [{//给x轴设置滚动条
- // show: false,
- start: dataZoom_end,
- end: 100,
- type: 'slider',
- zoomLock: true,
- },{ //下面这个属性是内容区域配置
- start: dataZoom_end,
- end: 100,
- type: 'inside',
- zoomLock: true,
- }],
- series: seriesData
- };
- //删除旧的图标数据重新渲染
- $("#lineChart").removeAttr("_echarts_instance_");
- lineCharts.setOption(options);
- window.addEventListener("resize", function () {
- setTimeout(function () {
- lineCharts.resize();
- }, 500)
- });
- }
-
- function getStartDate(type){
- //type: 1-周, 2-月, 3-年
- var now = new Date(),
- endDate = new Date();
- switch(parseInt(type)){
- case 1:
- endDate.setDate(now.getDate()- 6);
- break;
- case 2:
- endDate.setMonth(now.getMonth() - 1);
- break;
- case 3:
- endDate.setFullYear(now.getFullYear() - 1);
- break;
- }
- return endDate.format("yyyy-MM-dd")+" 00:00:00";
- }
-
- function getEndDate(){
- var now = new Date();
- return now.format("yyyy-MM-dd")+ " 23:59:59";
- }
-
- function getTimeName(type){
- switch(parseInt(type)){
- case 1:
- return "一周";
- break;
- case 2:
- return "一月";
- break;
- case 3:
- return "一年";
- break;
- }
- }
- })();
|