| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554 | 
							- var switchery = null;
 
- var date = new Date();
 
- var year = date.getFullYear();
 
- var begindate;
 
- var enddate;
 
- var page = 1;
 
- var pagesize = 10;
 
- var pagetype = 5;
 
- var patientCode = "";
 
- var charType = 1;
 
- var scroller1 = null;
 
- var self = null;
 
- var type = null;
 
- var charts = [];
 
- var $viewTabs = $('#viewTabs'),
 
- 	$swiperWrapper = $('.swiper-wrapper'),
 
- 	$duringList = $('#duringList'),
 
- 	$qushiView = $('#qushiView'),
 
- 	$liebiaoView = $('#liebiaoView'),
 
- 	$xtEdit = $('.xt-edit'),
 
- 	$btns = $('.btns'),
 
- 	$cancelBtn = $('.cancel-btn'),
 
- 	$okBtn = $('.ok-btn'),
 
- 	$xtAdd = $('.xt-add'),
 
- 	$popMain = $('.pop-main'),
 
- 	$popBtns = $('.pop-btns'),
 
- 	$popEditBtn = $('.pop-edit-btn'),
 
- 	$popDelBtn = $('.pop-del-btn'),
 
- 	$popCancelBtn = $('.pop-cancel-btn'),
 
- 	$selDate = $('#selDate'),
 
- 	swiper = null,
 
- 	d1 = [],
 
- 	d2 = [],
 
- 	d3 = [],
 
- 	d4 = [],
 
- 	page = 0,
 
- 	pagesize = 10,
 
- 	$zcNum = $('.ss-zc-num'),
 
- 	$pgNum = $('.ss-pg-num'),
 
- 	$pdNum = $('.ss-pd-num'),
 
- 	dayNum = 6,
 
- 	$xyList = $('.xy-list-con'),
 
- 	$xyTmp = $('#xyTmp'),
 
- 	thatIndex = 1,
 
- 	isTrue = false,
 
- 	isLoad = false;
 
- var norTime = '',
 
- 	enddate = '',
 
- 	sn = 0;
 
- mui.plusReady(function() {
 
- 	self = plus.webview.currentWebview();
 
- 	patientCode = self.code;
 
- 	begindate = self.dateT;
 
- 	norTime = self.dateT;
 
- 	enddate = getDateFromCurrentDate(begindate, -dayNum);
 
- 	type = self.type;
 
- 	bindEvents();
 
- 	scroller1 = new IScrollPullUpDown('wrapper6', {
 
- 		probeType: 2,
 
- 		bounceTime: 250,
 
- 		bounceEasing: 'quadratic',
 
- 		mouseWheel: false,
 
- 		scrollbars: true,
 
- 		fadeScrollbars: true,
 
- 		interactiveScrollbars: false,
 
- 		click: true,
 
- 	}, null, pullUpAction);
 
- 	//	checkLoad(thatIndex);
 
- 	init();
 
- });
 
- function changeTabCon() {
 
- 	var qsv = $qushiView.css('display'),
 
- 		lbv = $liebiaoView.css('display');
 
- 	if(qsv === 'block') {
 
- 		lbv.hide();
 
- 	}
 
- }
 
- function getxAxisData(data) {
 
- 	var a = [],
 
- 		b = [];
 
- 	b = _.chain(data).pluck('date').map(function(d) {
 
- 		return d.substr(5, 5)
 
- 	}).value();
 
- 	for(var i = b.length - 1; i >= 0; i--) {
 
- 		a.push(b[i]);
 
- 	}
 
- 	return a;
 
- }
 
- function buildData1(value, max, min) {
 
- 	if((value > 0 && value < min) || value > max) {
 
- 		return {
 
- 			value: value,
 
- 			itemStyle: {
 
- 				normal: {
 
- 					color: '#f00'
 
- 				}
 
- 			}
 
- 		}
 
- 	} else {
 
- 		return value
 
- 	}
 
- }
 
- //初始化图表数据
 
- function initCD(list, n) {
 
- 	var seriesArray = [];
 
- 	var data1 = new Array();
 
- 	var data2 = new Array();
 
- 	var allDatas = new Array();
 
- 	var xynum = {};
 
- 	for(var i = 0; i < list.length; i++) {
 
- 		var data = list[i];
 
- 		if(!data) {
 
- 			continue;
 
- 		}
 
- 		data1.unshift(buildData1(data.value1, 139, 90));
 
- 		data2.unshift(buildData1(data.value2, 89, 60));
 
- 	}
 
- 	allDatas.unshift(data1);
 
- 	allDatas.unshift(data2);
 
- 	for(var i = 0; i < allDatas.length; i++) {
 
- 		var na = (i == 1 ? '收缩压' : '舒张压');
 
- 		var series = {
 
- 			name: na,
 
- 			type: 'line',
 
- 			symbol: 'emptyCircle',
 
- 			layerPadding: 0,
 
- 			nodePadding: 0,
 
- 			itemStyle: {
 
- 				normal: {
 
- 					borderWidth: 8,
 
- 					color: '#0ad800',
 
- 					lineStyle: { // 系列级个性化折线样式,横向渐变描边
 
- 						borderWidth: 2,
 
- 						color: i == 1 ? '#CC66FF' : '#5dd1d2',
 
- 						width: 4
 
- 					},
 
- 					nodeStyle: {
 
- 						borderWidth: 2,
 
- 						color: '#93DB70',
 
- 						borderColor: '#93DB70'
 
- 					}
 
- 				},
 
- 				emphasis: {
 
- 					label: {
 
- 						show: true
 
- 					}
 
- 				}
 
- 			},
 
- 			data: allDatas[i]
 
- 		};
 
- 		seriesArray.unshift(series);
 
- 	}
 
- 	return seriesArray;
 
- }
 
- function queryListByTypeP(type, begindate, enddate, page, pagesize, code) {
 
- 	plus.nativeUI.showWaiting();
 
- 	//拼请求内容
 
- 	var params = {};
 
- 	params.type = type;
 
- 	params.page = page;
 
- 	params.pagesize = pagesize;
 
- 	params.begin = begindate + " 00:00:00";
 
- 	params.end = enddate + " 23:59:59";
 
- 	params.patient = code;
 
- 	return new Promise(function(resolve, reject) {
 
- 		sendPost("doctor/health_index/list", params, function(res) {
 
- 			resolve(res)
 
- 			console.log(res);
 
- 		}, function(res) {
 
- 			if(res.status == 200) {
 
- 				plus.nativeUI.closeWaiting();
 
- 				resolve(res)
 
- 			} else {
 
- 				queryListFailed(res);
 
- 			}
 
- 		});
 
- 	})
 
- }
 
- function getSeriesData(data) {
 
- 	var a = [];
 
- 	for(var i = 1; i <= 2; i++) {
 
- 		a.unshift((_.chain(data).pluck('value' + i).map(function(v) {
 
- 			if(i == 1) {
 
- 				return buildData1(v, 139, 90);
 
- 			}
 
- 			if(i == 2) {
 
- 				return buildData1(v, 89, 60);
 
- 			}
 
- 		}).value()));
 
- 	}
 
- 	return a;
 
- }
 
- var val1 = [],
 
- 	val2 = [],
 
- 	val3 = [],
 
- 	val4 = [];
 
- function calNum(d, v, n1, n2) {
 
- 	var vv = {
 
- 		zc: 0,
 
- 		pg: 0,
 
- 		pd: 0
 
- 	};
 
- 	for(var i = 0, len = d.length; i < len; i++) {
 
- 		var data = d[i];
 
- 		if(data[v] > 0 && data[v] < n2) { //偏低
 
- 			vv.pd++;
 
- 		} else if(data[v] > n1) { //偏高
 
- 			vv.pg++;
 
- 		} else {
 
- 			vv.zc++;
 
- 		}
 
- 	}
 
- 	return vv;
 
- }
 
- //上拉加载数据
 
- function pullUpAction(theScrollerTemp) {
 
- 	$(".pullUp").show();
 
- 	setTimeout(function() {
 
- 		loadListPromise();
 
- 	}, 1000);
 
- }
 
- function loadListPromise() {
 
- 	page++;
 
- 	Promise.all([
 
- 			queryListByTypeP(2, getDateFromCurrentDate(norTime, -2000), norTime, page, pagesize, patientCode)
 
- 		])
 
- 		.then(function(res) {
 
- 			$(".pullUp").hide();
 
- 			var data = res[0];
 
- 			if (data.list.length > 0) {
 
- 				console.log(data.list);
 
- 				$xyList.append(template('xyTmp', {
 
- 					data: data.list
 
- 				}));
 
- 				scroller1.refresh();
 
- 			} else {
 
- 				if(!isLoad) {
 
- 	    			mui.toast("暂无数据!");
 
- 				} else {
 
- 	    			mui.toast("暂无更多数据!");
 
- 				}
 
- 			}
 
- 			isLoad = true;
 
- 		})
 
- 		.catch(function(e) {
 
- 			console && console.error(e)
 
- 		});
 
- }
 
- //初始化swiper
 
- function init() {
 
- 	Promise.all([(function() {
 
- 			$swiperWrapper
 
- 				.append($('<li id="chart0" class="swiper-slide"> </li>'))
 
- 				.append($('<li id="chart1" class="swiper-slide"> </li>'))
 
- 				.append($('<li id="chart2" class="swiper-slide"> </li>'))
 
- 				.append($('<li id="chart3" class="swiper-slide"> </li>'));
 
- 		})()])
 
- 		.then(function(echarts) {
 
- 			swiper = new Swiper('.swiper-container', {
 
- 				paginationClickable: false,
 
- 				onSlideChangeStart: function(swiper) {
 
- 					//切换
 
- 					var ind = swiper.activeIndex;
 
- 					if(ind < sn) {
 
- 						begindate = enddate;
 
- 						enddate = getDateFromCurrentDate(begindate, -dayNum);
 
- 					} else {
 
- 						enddate = begindate;
 
- 						begindate = getDateFromCurrentDate(begindate, dayNum);
 
- 					}
 
- 					sn = ind;
 
- 					loadPromise(sn, enddate, begindate);
 
- 				}
 
- 			});
 
- 		})
 
- 		.then(function() {
 
- 			$swiperWrapper.find('.swiper-slide');
 
- 			swiper.slideTo(swiper.slides.length - 1, 0, false); //切换到最后一个slide
 
- 			sn = swiper.slides.length - 1;
 
- 			loadPromise(sn, enddate, begindate);
 
- 		})
 
- 		.catch(function(e) {
 
- 			console && console.error(e)
 
- 		})
 
- }
 
- function loadPromise(n, enddate, begindate) {
 
- 	
 
- 	plus.nativeUI.showWaiting();
 
- 	Promise.all([
 
- 			queryChatByTypePromise(2, enddate, begindate, 0, patientCode)
 
- 		])
 
- 		.then(function(res) {
 
- 			d1 = res[0];
 
- 			loadData(n);
 
- 		})
 
- 		.catch(function(e) {
 
- 			console && console.error(e)
 
- 		});
 
- }
 
- function getZcNum (d) {
 
- 	var vv = {"ss_zc":0, "sz_zc": 0};
 
- 	for (var i = 0,len = d.length; i < len; i++) {
 
- 		if (d[i]['value1'] >= 90 && d[i]['value1'] <= 139) {
 
- 			vv.ss_zc ++;
 
- 		}else if(d[i]['value2'] >= 60 && d[i]['value2'] <= 89){
 
- 		    vv.sz_zc ++;
 
- 		}
 
- 	}
 
- 	return vv;
 
- }
 
- //初始化echart
 
- function loadData(n) {
 
- 	new Promise(function(resolve, reject) {
 
- 		var yAxisName = '单位(mmHg)';
 
- 		if (typeof d1.list == 'undefined') {
 
- 			d1.list = [];
 
- 		}
 
- 		var el = document.getElementById('chart' + n);
 
- 		val1['value1'] = calNum(d1.list, 'value1', 139, 90);
 
- 		val1['value2'] = calNum(d1.list, 'value2', 89, 60);
 
- 		var zc = getZcNum(d1.list);
 
- 		$zcNum.html(zc.ss_zc);
 
- 		$('.sz-zc-num').html(zc.sz_zc);
 
- //		$pgNum.html(Math.max(val1['value1'].pg, val1['value2'].pg)),
 
- //		$pdNum.html(Math.max(val1['value1'].pd, val1['value2'].pd));
 
-         $pgNum.html(val1['value1'].pg);
 
-         $pdNum.html(val1['value1'].pd);
 
-         $(".sz-pg-num").html(val1['value2'].pg);
 
-         $(".sz-pd-num").html(val1['value2'].pd);
 
- 		Promise.all([
 
- 				createChartPromise(el, 2, yAxisName, getxAxisData(d1.list), initCD(d1.list))
 
- 			])
 
- 			.then(function(echarts) {
 
- 				
 
- 				plus.nativeUI.closeWaiting();
 
- 				charts.push(echarts[0]);
 
- 				$(el).append('<div class="c-time">< ' + enddate + ' 至 ' + begindate + ' ></div>');
 
- 			})
 
- 			.then(function() {
 
- 			})
 
- 			.catch(function(e) {
 
- 				console && console.error(e)
 
- 			})
 
- 	});
 
- }
 
- //function loadPromise(t, cb) {
 
- //	Promise.all([
 
- //			queryChatByTypePromise(2, getBeforeDate(begindate, 7), begindate, 0, patientCode),
 
- //			queryChatByTypePromise(2, getBeforeDate(begindate, 30), begindate, 0, patientCode),
 
- //			queryChatByTypePromise(2, getBeforeDate(begindate, 90), begindate, 0, patientCode),
 
- //			queryChatByTypePromise(2, getBeforeDate(begindate, 365 / 2), begindate, 0, patientCode)
 
- //		])
 
- //		.then(function(res) {
 
- //			plus.nativeUI.closeWaiting();
 
- //			d1 = res[0];
 
- //			d2 = res[1];
 
- //			d3 = res[2];
 
- //			d4 = res[3];
 
- //
 
- //			cb && cb.call(this);
 
- //		})
 
- //		.catch(function(e) {
 
- //			console && console.error(e)
 
- //		});
 
- //}
 
- //
 
- //function loadData() {
 
- //	new Promise(function(resolve, reject) {
 
- //		var yAxisName = '单位(mmHg)';
 
- //		$swiperWrapper
 
- //			.append('<li id="chart3" class="swiper-slide">')
 
- //			.append('<li id="chart2" class="swiper-slide">')
 
- //			.append('<li id="chart1" class="swiper-slide">')
 
- //			.append('<li id="chart0" class="swiper-slide">');
 
- //
 
- //		var el1 = document.getElementById('chart0'),
 
- //			el2 = document.getElementById('chart1'),
 
- //			el3 = document.getElementById('chart2'),
 
- //			el4 = document.getElementById('chart3')
 
- //		Promise.all([
 
- //				createChartPromise(el1, 2, yAxisName, getxAxisData(d1.list), initCD(d1.list)),
 
- //				createChartPromise(el2, 2, yAxisName, getxAxisData(d2.list), initCD(d2.list)),
 
- //				createChartPromise(el3, 2, yAxisName, getxAxisData(d3.list), initCD(d3.list)),
 
- //				createChartPromise(el4, 2, yAxisName, getxAxisData(d4.list), initCD(d4.list))
 
- //			])
 
- //			.then(function(echarts) {
 
- //				charts.push(echarts[0]);
 
- //				charts.push(echarts[1]);
 
- //				charts.push(echarts[2]);
 
- //				$(el1).append('<div class="c-time">< ' + getBeforeDate(begindate, 7) + ' 至 ' + begindate + ' ></div>');
 
- //				$(el2).append('<div class="c-time">< ' + getBeforeDate(begindate, 30) + ' 至 ' + begindate + ' ></div>');
 
- //				$(el3).append('<div class="c-time">< ' + getBeforeDate(begindate, 90) + ' 至 ' + begindate + ' ></div>');
 
- //				$(el4).append('<div class="c-time">< ' + getBeforeDate(begindate, 365 / 2) + ' 至 ' + begindate + ' ></div>');
 
- //
 
- //				val1['value1'] = calNum(d1.list, 'value1', 139, 90);
 
- //				val1['value2'] = calNum(d1.list, 'value2', 89, 60);
 
- //				val2['value1'] = calNum(d2.list, 'value1', 139, 90);
 
- //				val2['value2'] = calNum(d2.list, 'value2', 89, 60);
 
- //				val3['value1'] = calNum(d3.list, 'value1', 139, 90);
 
- //				val3['value2'] = calNum(d3.list, 'value2', 89, 60);
 
- //				val4['value1'] = calNum(d4.list, 'value1', 139, 90);
 
- //				val4['value2'] = calNum(d4.list, 'value2', 89, 60);
 
- //
 
- //				$zcNum.html(Math.max(val1['value1'].zc, val1['value2'].zc));
 
- //				$pgNum.html(Math.max(val1['value1'].pg, val1['value2'].pg)),
 
- //					$pdNum.html(Math.max(val1['value1'].pd, val1['value2'].pd));
 
- //
 
- //			})
 
- //			.then(function(res) {
 
- //				swiper = new Swiper('.swiper-container', {
 
- //					paginationClickable: false,
 
- //					normalizeSlideIndex: false,
 
- //					onSlideChangeStart: function(swiper) {
 
- //						var ind = swiper.activeIndex;
 
- //						console.log(ind);
 
- //						switch(ind) {
 
- //							case 0:
 
- //								$zcNum.html(Math.max(val4['value1'].zc, val4['value2'].zc));
 
- //								$pgNum.html(Math.max(val4['value1'].pg, val4['value2'].pg)),
 
- //									$pdNum.html(Math.max(val4['value1'].pd, val4['value2'].pd));
 
- //								$selDate.find('li').removeClass('curr').eq(3).addClass('curr');
 
- //								dayNum = -1;
 
- //								break;
 
- //							case 1:
 
- //								$zcNum.html(Math.max(val3['value1'].zc, val3['value2'].zc));
 
- //								$pgNum.html(Math.max(val3['value1'].pg, val3['value2'].pg)),
 
- //									$pdNum.html(Math.max(val3['value1'].pd, val3['value2'].pd));
 
- //								$selDate.find('li').removeClass('curr').eq(2).addClass('curr');
 
- //								dayNum = 90;
 
- //								break;
 
- //							case 2:
 
- //								$zcNum.html(Math.max(val2['value1'].zc, val2['value2'].zc));
 
- //								$pgNum.html(Math.max(val2['value1'].pg, val2['value2'].pg)),
 
- //									$pdNum.html(Math.max(val2['value1'].pd, val2['value2'].pd));
 
- //								$selDate.find('li').removeClass('curr').eq(1).addClass('curr');
 
- //								dayNum = 30;
 
- //								break;
 
- //							case 3:
 
- //								$zcNum.html(Math.max(val1['value1'].zc, val1['value2'].zc));
 
- //								$pgNum.html(Math.max(val1['value1'].pg, val1['value2'].pg)),
 
- //									$pdNum.html(Math.max(val1['value1'].pd, val1['value2'].pd));
 
- //								$selDate.find('li').removeClass('curr').eq(0).addClass('curr');
 
- //								dayNum = 7;
 
- //								break;
 
- //						}
 
- //					}
 
- //				});
 
- //				$swiperWrapper.find('.swiper-slide')
 
- //				swiper.slideTo(swiper.slides.length - 1, 0, false); //切换到最后一个slide
 
- //			})
 
- //			.then(function() {})
 
- //			.catch(function(e) {
 
- //				console && console.error(e)
 
- //			})
 
- //	});
 
- //}
 
- //
 
- //function checkLoad(d) {
 
- //	if(!isTrue) {
 
- //		loadPromise(d, loadData);
 
- //	} else {
 
- //		loadData();
 
- //	}
 
- //}
 
- function bindEvents() {
 
- 	$viewTabs.on('click', 'li', function(e) {
 
- 		e.stopPropagation();
 
- 		var index = $(this).index();
 
- 		$(this).siblings().removeClass('curr');
 
- 		$(this).addClass('curr');
 
- 		if(index === 0) {
 
- 			$qushiView.show();
 
- 			$liebiaoView.hide();
 
- 			$xtEdit.hide();
 
- 		} else {
 
- 			$qushiView.hide();
 
- 			$liebiaoView.show();
 
- 			var data = null;
 
- 			if(dayNum == 6) {
 
- 				data = d1.list;
 
- 			}
 
- 			if(dayNum == 30) {
 
- 				data = d2.list;
 
- 			}
 
- 			if(dayNum == 90) {
 
- 				data = d3.list;
 
- 			}
 
- 			if(dayNum == -1) {
 
- 				data = d4.list;
 
- 			}
 
- 			if(!isLoad) {
 
- //				isLoad = true;
 
- 				loadListPromise();
 
- 			}
 
- 			$xtEdit.show();
 
- 		}
 
- 	});
 
- 	$selDate.on('click', 'li', function(e) {
 
- 		var index = $(this).index();
 
- 		$(this).siblings().removeClass('curr');
 
- 		$(this).addClass('curr');
 
- 		console.log(index);
 
- 		$swiperWrapper.find('.swiper-slide').html('');
 
- 		swiper.slideTo(swiper.slides.length - 1, 0, false); //切换到最后一个slide
 
- 		sn = swiper.slides.length - 1;
 
- 		begindate = norTime;
 
- 		switch(index) {
 
- 			case 0:
 
- 				dayNum = 6;
 
- 				break;
 
- 			case 1:
 
- 				dayNum = 30;
 
- 				break;
 
- 			case 2:
 
- 				dayNum = 90;
 
- 				break;
 
- 			case 3:
 
- 				dayNum = 365 / 2;
 
- 				break;
 
- 		}
 
- 		enddate = getDateFromCurrentDate(begindate, -dayNum);
 
- 		loadPromise(sn, enddate, begindate);
 
- 	});
 
- }
 
- //根据sd获取n天前的时间;	
 
- 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;
 
- };
 
 
  |