123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- (function() {
- var request = getRequest(),
- patient = request.patiCode || '';
- var tabIndex = 0,
- dayIndex = 0,
- statusIndex = 1;
- // 绘制折线图初始定义
- var ctx = document.getElementById('canvas').getContext("2d");
- var dataCanvas = {
- labels : [],
- datasets : [
- {
- fillColor : "rgba(220,220,220,0.5)",
- strokeColor : "rgba(220,220,220,1)",
- pointColor : "rgba(220,220,220,1)",
- pointStrokeColor : "#fff",
- data : []
- },
- {
- fillColor : "rgba(151,187,205,0.5)",
- strokeColor : "rgba(151,187,205,1)",
- pointColor : "rgba(151,187,205,1)",
- pointStrokeColor : "rgba(151,187,205,1)",
- data : []
- }
- ]
- },
- defaults = {
- scaleStartValue : 0,
- scaleShowLabels : true,
- datasetFill : false, // 是否填充数据集
- animation : true, // 是否执行动画
- animationSteps : 60, // 动画的时间
- animationEasing : "easeOutQuart", // 动画的特效
- onAnimationComplete : null // 动画完成时的执行函数
- };
- var myLineChart = null;
- // new Chart(ctx).Line(dataCanvas, defaults);
- $('.tab-record span').click(function() {
- tabIndex = $(this).index();
- // 初始化数据
- if(tabIndex == 1) {
- statusIndex = 0;
- $('.status-record').hide();
- } else {
- var ele = $('.status-record span').get(0);
- indexHover(ele);
- statusIndex = 1;
- $('.status-record').show();
- }
- indexHover(this);
- dayIndex = 0;
- var ele = $('.day-record span').get(0);
- indexHover(ele);
- canvasDataDefault();
- });
- $('.day-record span').click(function() {
- dayIndex = $(this).index();
- if(tabIndex == 0) {
- var ele = $('.status-record span').get(0);
- indexHover(ele);
- statusIndex = 1;
- }
- indexHover(this);
- canvasDataDefault();
-
- });
- $('.status-record span').click(function() {
- statusIndex = $(this).index() + 1;
- indexHover(this);
- canvasDataDefault();
- });
- // 点击指示特效
- function indexHover(ele) {
- $(ele).siblings().removeClass('f-hover');
- $(ele).addClass('f-hover');
- };
- // 绘图数据格式化
- function canvasDataDefault() {
- dataCanvas.labels = [];
- dataCanvas.datasets[0].data = [];
- dataCanvas.datasets[1].data = [];
- // 切换数据
- getBodyRecord(tabIndex, dayIndex, statusIndex);
- }
- // 时间推算
- function getDateFromCurrentDate(fromDate, dayInterval) {
- var curDate = new Date(Date.parse(fromDate.replace(/-/g, "/")));
- curDate.setDate(curDate.getDate() + dayInterval);
- var year = curDate.getFullYear();
- var month = (curDate.getMonth() + 1) < 10 ? "0" + (curDate.getMonth() + 1) : (curDate.getMonth() + 1);
- var day = curDate.getDate() < 10 ? "0" + curDate.getDate() : curDate.getDate();
- return year + "-" + month + "-" + day + " 00:00:00";
- };
- // 血糖标准
- function getNormalLevel(index) {
- return [
- [],
- [6.1, 3.9],
- [7.8, 4.4],
- [6.1, 3.9],
- [7.8, 4.4],
- [6.1, 3.9],
- [7.8, 4.4],
- [6.1, 3.9]
- ][index];
- };
- var xtMax = getNormalLevel(statusIndex)[0],
- xtMin = getNormalLevel(statusIndex)[1],
- xyMax = [139, 89],
- xyMin = [90, 60],
- toNormal = 0,
- toHigh = 0,
- toLow = 0;
- function judgeXTValue(value1) {
- // 血糖判断
- if(value1 > xtMax) {
- ++toHigh;
- } else if(value1 < xtMin) {
- ++toLow;
- } else {
- ++toNormal;
- };
- }
- function judgeXYValue(value1, value2) {
- // 血压判断
- if(value1 > xyMax[0] || value2 > xyMax[1]) {
- ++toHigh;
- } else if(value1 < xyMin[0] || value2 < xyMin[1]) {
- ++toLow;
- } else {
- ++toNormal;
- }
- }
- // 数据统计
- function totalStauts(zc, pg, pd) {
- $('.is-ok').html("正常:" + zc + "次");
- $('.is-height').html("偏高:" + pg + "次");
- $('.is-low').html("偏低:" + pd + "次");
- }
- // 获取最后一条数据
- var dataLast = {patient: patient};
- var lastXT = '',
- lastXY = '';
- bodyRecordApis.getBodyRecoredLast({data: dataLast}).then(function(res){
- if(res.status == 200){
- lastXT = res.data.xt ? res.data.xt.recordDate : null;
- lastXY = res.data.xy ? res.data.xy.recordDate : null;
- // 初始化执行
- getBodyRecord(tabIndex, dayIndex, statusIndex);
- }else{
- showWarningMsg(res.msg)
- }
- })
- // 获取数据
- function getBodyRecord(tab, day, statu) {
- toNormal = 0;
- toHigh = 0;
- toLow = 0;
- totalStauts(toNormal, toHigh, toLow);
- $('.danwei').html(tab == 0 ? '单位(mmol/L)' : '单位(mmHg)');
- var dayNum = 0;
- switch(day) {
- case 0:
- dayNum = 6;break;
- case 1:
- dayNum = 29;break;
- case 2:
- dayNum = 89;break;
- case 3:
- dayNum = 364 / 2;break;
- }
- var type = (tab == 0 ? 1 : 2),
- startdate = (tab == 0 ? lastXT : lastXY),
- enddate = null;
- if(startdate) {
- enddate = getDateFromCurrentDate(startdate, -dayNum);
- } else {
- showWarningMsg("当前状态下无居民体征记录");return;
- }
- $('.data-record').html('<' + enddate.substr(0, 10) + '至' + startdate.substr(0,10) + '>');
- var recordData = {
- type: type,
- begin: enddate,
- end: startdate,
- gi_type: statu,
- patient: patient
- };
- // 获取体征记录
- bodyRecordApis.getBodyRecordData({data: recordData}).then(function(res){
- if(myLineChart) {// 如果构造过,解析
- myLineChart.destroy();
- }
- if(res.status == 200){
- var list = res.list,
- len = 0;
- if(list) {
- len = list.length;
- } else {
- showWarningMsg("当前状态下无居民体征记录");return;
- };
- list.reverse();
- if(len == 1) {
- dataCanvas.labels = [enddate.substr(5, 5), list[0].date.substr(5, 5)];
- dataCanvas.datasets[0].data = [null, list[0].value1];
- if(tabIndex == 1) {
- dataCanvas.datasets[1].data = [null, list[0].value2];
- judgeXYValue(list[0].value1, list[0].value2)
- } else {
- dataCanvas.datasets[1].data = null
- judgeXTValue(list[0].value1)
- }
- } else {
- for(var i = 0; i < len; i++) {
- dataCanvas.labels[i] = list[i].date.substr(5, 5);
- dataCanvas.datasets[0].data[i] = list[i].value1;
- if(tabIndex == 1) {
- dataCanvas.datasets[1].data[i] = list[i].value2;
- judgeXYValue(list[i].value1, list[i].value2)
- } else {
- dataCanvas.datasets[1].data = null
- judgeXTValue(list[i].value1)
- }
- }
- }
- totalStauts(toNormal, toHigh, toLow);
- // 绘制图
- myLineChart = new Chart(ctx).Line(dataCanvas, defaults);
- }else{
- showWarningMsg(res.msg)
- }
- })
- }
- })(jQuery)
|