| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534 | 
							- var d = dialog({contentType:'load', skin:'bk-popup'}).show();
 
- var dd = dialog({contentType:'load', skin:'bk-popup'});
 
- var pagetype = 5;
 
- var Request = GetRequest();
 
- var openid = Request["openid"];
 
- var $tizhengList = $('#tizhengList'),
 
- 	$baojianList = $('#baojianList');
 
- var id = 0;
 
- var pagesize = 15;
 
- var scroller1 = null;
 
- var xuetangRecord = null,
 
- 	xuyaRecord = null,
 
- 	tizhongRecord = null,
 
- 	yaoweiRecord = null,
 
- 	yundongRecord = null,
 
- 	yongyaoRecord = null,
 
- 	yinshiRecord = null,
 
- 	tzSta = false,
 
- 	xtdt = '',
 
- 	xydt = '',
 
- 	tzdt = '',
 
- 	ywdt = '',
 
- 	yddt = '',
 
- 	yydt = '',
 
- 	ysdt = '';
 
- var	tagType = Request["tagType"]?Request["tagType"]:0;
 
- var xuetangDuring = ['','早餐前', '早餐后', '午餐前', '午餐后', '晚餐前', '晚餐后', '睡前'];
 
- $(function() {
 
- 	 checkUserAgent();
 
-      scroller1= new IScrollPullUpDown('wrapper2',{
 
-             probeType:2,
 
-             bounceTime: 250,
 
-             bounceEasing: 'quadratic',
 
-             mouseWheel:true,
 
-             scrollbars:true,
 
-             click:true,
 
-             fadeScrollbars:true,
 
-             interactiveScrollbars:false
 
-     },pullDownAction,pullUpAction); 
 
-     EbindEvents();
 
-     
 
-     //下拉刷新
 
-     function pullDownAction(theScrollerTemp) {
 
- //      $(".pullUp").show();
 
- //      setTimeout(function () {
 
- //          $(".c-list").html("");  
 
- //          id=0;
 
- //          getEquipments();    
 
- //      }, 1000);   
 
-     }   
 
-         
 
-     //上拉加载数据
 
-     function pullUpAction(theScrollerTemp) {
 
-         $(".pullUp").show();
 
-         setTimeout(function () {    
 
-             getEquipments();        
 
-         }, 1000);
 
-     }
 
-     
 
-     if(tagType == 1){
 
- 		$('.j-tab-select li').eq(1).addClass('hit');
 
- 		$('.pt-tab-list').eq(1).addClass('hit');
 
- 	}else{
 
- 		$('.j-tab-select li').eq(0).addClass('hit');
 
- 		$('.pt-tab-list').eq(0).addClass('hit');
 
- 	}
 
- })		
 
- //体征设备绑定事件
 
- function EbindEvents(){
 
-     //绑定编辑和删除事件 
 
-     $(".c-list").on("click","li div",function(){
 
-             var code = $(this.parentElement).attr("data-id");
 
-             var deviceId = $(this.parentElement).attr("device-id");
 
-             var type = $(this.parentElement).attr("data-type");
 
-             if(type==1){
 
-                 location.href="../../wdsb/html/view-xuetangyi.html?deviceId="+deviceId+"&id="+code;
 
-             }else if(type==2){
 
-                 location.href="../../wdsb/html/view-xueyaji.html?deviceId="+deviceId+"&id="+code;
 
-             }
 
-     })
 
-     function deleteSn(code){
 
-         sendPost("patient/device/DeletePatientDevice?id="+code,{},"JSON","DELETE",function(res){
 
-             if (res &&  res.msg) {
 
-                 dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:res.msg}).show();
 
-             } else {
 
-                 dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'删除设备失败'}).show();
 
-             }
 
-         },function(res){
 
-             if(res.status==200){
 
-                 $(".c-list").html("");  
 
-                 id=0;
 
-                 getEquipments();
 
-             }else{
 
-                 dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'删除设备失败'}).show();
 
-             }
 
-         })
 
-     }
 
-     
 
-    //点击血糖仪事件
 
-    $(".xuetangyi-icon").on("click",function(){
 
-         $(this).addClass("active");
 
-         window.location.href = "../../wdsb/html/list-xuetangyi.html?category_code=1";
 
-     });
 
-     
 
-      //点击血压计事件
 
-    $(".xueyaji-icon").on("click",function(){
 
-         $(this).addClass("active");
 
-         window.location.href = "../../wdsb/html/list-xueyaji.html?category_code=2";
 
-    });
 
- }
 
- function checkDate (v) {
 
- 	return (v < 10 ? '0' + v : v);
 
- }
 
- appendFamilyMember($('#memberContainer'),function(){
 
-     $(".c-list").html("");  
 
-     $(".div-no-info").hide();
 
-     $(".main").show();
 
-     id=0;
 
- 	getEquipments();
 
- 	getRecentDataInit();	 
 
- },function(){
 
-     //判断有授权家人,修改样式
 
-     if($('#memberContainer').is(':hidden')){
 
-         $('#wrapper').css('top','0px');
 
-     }else{
 
-         $('#wrapper').css('top','90px');
 
-     }
 
- });
 
- //获取最新的体征记录
 
- function getRecentDataPromise() {	
 
- 	return new Promise(function(resolve, reject) {
 
- 		sendPost("patient/health_index/last", {}, "json", "get", function() {
 
- 			d.close();
 
- 			dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据查询失败'}).show();
 
- 		}, function(res) {
 
- 			d.close();
 
- 			if(res.status == 200) {
 
- 			    console.log(res);
 
- 				resolve(res)
 
- 			} else {
 
- 				dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据查询失败'}).show();
 
- 			}
 
- 		});
 
- 	})
 
- }
 
- //获取最新的体征设备
 
- function getEquipments(){
 
-     var params = {};
 
-     params.id=id;
 
-     params.pagesize = pagesize;
 
-     d.show();
 
-     sendPost("patient/device/PatientDeviceList",params,"JSON","GET",queryListFailed,queryListSuccess);
 
- }
 
- //获取最新体征设备成功回调
 
- function queryListSuccess(res){
 
-     d.close();  
 
-     if(res.status==200){
 
-         if(res.data&&res.data.length>0){
 
-             for(var i in res.data){
 
-                 showList(res.data[i]); 
 
-             }
 
-             id = res.data[res.data.length-1].id;
 
-             scroller1.myScroll.refresh(); 
 
-         }else{
 
-             if(id==0){
 
-                 $(".div-no-info").show(); 
 
-                 $(".main").hide();
 
-             }         
 
-         }
 
-         $(".pullUp").hide();
 
-     }else{
 
-         queryListFailed(res);
 
-     }
 
- }
 
- //获取最新体征设备初始化数据
 
- function showList(rowData){
 
-     var img='xuetangyi_icon.png';
 
-     if(rowData.categoryCode==2){
 
-         img='xueyaji_icon.png';
 
-     }
 
-     var bindUser ="自己绑定";
 
-     if(rowData.doctor){
 
-         bindUser = "医生绑定";
 
-     }else if(rowData.agent){
 
-         bindUser = "家人绑定"; 
 
-     }
 
-     var showDomLi = '<li class="inp" device-id="'+rowData.deviceId+'" data-type="'+rowData.categoryCode+'" data-id="'+rowData.id+'">'+
 
-                         '<div class="icon-div">'+
 
-                             '<img src="../images/'+img+'">'+
 
-                         '</div>'+
 
-                         '<div class="div-content">'+rowData.deviceName+'</div>'+
 
-                         '<div class="div-sn"><span class="bullspan">• </span>绑定时间:'+rowData.czrq+'</div>'+
 
-                         '<div class="div-sn" style="top: 70px;color: #ff9526;"><span class="bullspan">•</span> '+bindUser+'</div>'+
 
-                     '</li>';
 
-     $("#shebeiList .Equipment").append(showDomLi);
 
- }
 
- //获取最新体征设备失败回调
 
- function queryListFailed(res) {
 
-     d.close();
 
-     if (res &&  res.msg) {
 
-         dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:res.msg}).show();
 
-     } else {
 
-         dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'加载设备列表失败'}).show();
 
-     }
 
- }
 
- //获取最新保健记录
 
- function getBJRecentDataPromise () {
 
- 	return new Promise(function( resolve, reject){
 
- 		sendPost("patient/health_record/recent", {}, "json", "get", function() {
 
- 			dd.close();
 
- 			dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据查询失败'}).show();
 
- 		}, function(res) {
 
- 			dd.close();
 
- 			if(res.status == 200) {
 
- 				resolve(res)
 
- 			} else {
 
- 				dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据查询失败'}).show();
 
- 			}
 
- 		});
 
- 	});
 
- }
 
- function getLevelClazz(value,max,min) {
 
- 	if(!value||(!max && !min)) {
 
- 		return '';
 
- 	}
 
- 	var value = parseFloat(value);
 
- 	if(value < min) {
 
- 		return 'low';
 
- 	} else if(value > max) {
 
- 		return 'high';
 
- 	} else {
 
- 		return ''
 
- 	}
 
- }
 
- function bindEvents() {
 
- 	//标签切换
 
-   $(".pt-tab li").click(function(){
 
- 		var id = $(this).attr("id");
 
- 		$(".pt-tab li").removeClass("hit");
 
- 		$(this).addClass("hit");
 
- 		if(id=="tizhengLi"){
 
- 			$("#tizhengList").show();
 
- 			$("#baojianList").hide();
 
- 		    $("#shebeiList").hide();
 
- 		}if(id=="shebeiLi"){
 
- 		    $("#shebeiList").show();
 
- 			$("#tizhengList").hide();
 
- 			$("#baojianList").hide();
 
- 		}if(id=="healthLi"){
 
- 		    $("#baojianList").show();
 
- 		    $("#shebeiList").hide(); 
 
- 		    $("#tizhengList").hide();
 
- 		}
 
- 	});	
 
- 	$('#tizhengList').on('click','li',function() {
 
- 		var index = $(this).index();
 
- 		var dat = new Date(),
 
- 			nowD = dat.getFullYear() + '-' + (dat.getMonth() + 1) + '-' + dat.getDate();
 
- 		if(index == 0) {
 
- 			window.location.href = 'xuetang-view.html?dateT=' + (xtdt || nowD);
 
- 		}
 
- 		if(index == 1) {
 
- 			window.location.href = 'xueya-view.html?dateT=' + (xydt || nowD);
 
- 		}
 
- 		if(index == 2) {
 
- 			window.location.href = 'tizhong-view.html?dateT=' + (nowD);
 
- 		}
 
- 		if(index == 3) {
 
- 			window.location.href = 'yaowei-view.html?dateT=' + (ywdt || nowD);
 
- 		}
 
- 	})
 
- 	$('#baojianList').on('click','li',function() {
 
- 		var index = $(this).index();
 
- 		var dat = new Date(),
 
- 			nowD = dat.getFullYear() + '-' + (dat.getMonth() + 1) + '-' + dat.getDate();
 
- 		if(index == 0) {
 
- 			window.location.href = 'yundong-view.html?dateT=' + (yddt || nowD);
 
- 		}
 
- 		if(index == 1) {
 
- 			window.location.href = 'yongyao-view.html?dateT=' + (yydt || nowD);
 
- 		}
 
- 		if(index == 2) {
 
- 			window.location.href = 'yinshi-view.html?dateT=' + (ysdt || nowD);
 
- 		}
 
- 	})
 
- 		//点击新增事件
 
-     	$(".div-add-btn").click(function(){
 
-     		$(".modal-overlay").css("background","transparent");
 
-     		$("#footer").css("z-index",4).hide();
 
-     		var activeItem = $(".pt-tab li.hit").attr("id");
 
-     		console.log(activeItem);
 
-     		if(activeItem=="tizhengLi"){ 
 
-     			if($(this).hasClass("active")){
 
- 					$(".div-dialog-content.div-tizhengtezheng").hide();
 
- 				}else{
 
- 					$(".div-dialog-content.div-tizhengtezheng").show();
 
- 				}
 
-     		}else if(activeItem=="shebeiLi"){
 
-     		   if($(this).hasClass("active")){ 
 
-     		       $(".div-dialog-content.div-tizhengshebei").hide();
 
-     		   }else{
 
-     		       $(".div-dialog-content.div-tizhengshebei").show();
 
-     		   }
 
-     		}else{
 
-     			if($(this).hasClass("active")){
 
- 					$(".div-dialog-content.div-baojianjilu").hide();
 
- 				}else{
 
- 					$(".div-dialog-content.div-baojianjilu").show();
 
- 				}
 
-     		}
 
-     		
 
-     		if($(this).hasClass("active")){
 
- 				$(".modal-overlay").removeClass("modal-overlay-visible");
 
- 				$(this).removeClass("active");
 
- 			}else{
 
- 				$(this).addClass("active");
 
- 				$(".modal-overlay").addClass("modal-overlay-visible");
 
- 			}
 
-     	});
 
-     	//点击遮罩事件
 
- 		$(".modal-overlay").on("click",function(){
 
- 			$(".div-add-btn").removeClass("active");
 
- 			$(".div-dialog-content").hide();
 
- 			$(".modal-overlay").removeClass("modal-overlay-visible");
 
- 			$("#footer").show();
 
- 	    });
 
- 	    //取消
 
- 	    $(".quxiao").on("click",function(){
 
- 			$(".div-add-btn").removeClass("active");
 
- 			$(".div-dialog-content").hide();
 
- 			$(".modal-overlay").removeClass("modal-overlay-visible");
 
- 			$("#footer").show();
 
- 	    });
 
- 	    
 
- 	     //新增血糖
 
- 	   $(".addxuetang").on("click",function(){
 
- 	   		$(this).addClass("active");
 
- 	   		window.open('health-index-add-bloodsugar.html');
 
- 	   	});
 
- 		
 
- 		//新增血压
 
- 	   $(".addxueya").on("click",function(){
 
- 	   		$(this).addClass("active");
 
- 	   		window.open('health-index-add-bloodpressure.html');
 
- 	   	});
 
- 	   	
 
- 	   	//新增体重
 
- 	   $(".addtizhong").on("click",function(){
 
- 	   		$(this).addClass("active");
 
- 	   		var dat = new Date(),
 
-                 nowD = dat.getFullYear() + '-' + (dat.getMonth() + 1) + '-' + dat.getDate();
 
- 	   		window.open('health-index-add-weight.html?dateT='+nowD);
 
- 	   	});
 
- 	   	
 
- 	   	//新增腰围
 
- 	   $(".addyaowei").on("click",function(){
 
- 	   		$(this).addClass("active");
 
- 	   		window.open('health-index-add-waistline.html');
 
- 	   	});
 
- 	   	
 
- 	   	//新增设备管理
 
- 	   $(".addshebei").on("click",function(){
 
- 	   		$(this).addClass("active");
 
- 	   		window.open('../../wdsb/html/my-equipments.html');
 
- 	   	});
 
- 	   	
 
- 	   	//新增运动
 
- 	   $(".addyundong").on("click",function(){
 
- 	   		$(this).addClass("active");
 
- 	   		window.open('add-sport-record.html');
 
- 	   	});
 
- 	   	
 
- 	   	//新增用药
 
- 	   $(".addyongyao").on("click",function(){
 
- 	   		$(this).addClass("active");
 
- 	   		window.open('add-drug-record.html');
 
- 	   	});
 
- 	   	
 
- 	   	//新增饮食
 
- 	   $(".addyinshi").on("click",function(){
 
- 	   		$(this).addClass("active");
 
- 	   		// 修复bug#2724
 
- 	   		window.location.href = 'add-diet-record.html';
 
- 	   	});
 
- }
 
- function pushHistory() {  
 
-     var state = {  
 
-         title: "title",  
 
-         url: "#"  
 
-     };  
 
-     setTimeout(function (){
 
-     	window.history.pushState(state, "title", "#");  
 
-     },1000);
 
- }
 
- pushHistory(); 
 
- setTimeout( function () {
 
-     window.addEventListener("popstate", function(e) {  
 
-     	WeixinJSBridge.call('closeWindow');
 
- 	}, false);  
 
- }, 300); 
 
- function getRecordType(isDevice) {
 
- 	return isDevice === null ? "手动记录" : isDevice != null ? "设备上传" : '';
 
- //	return isDevice == "0"?"手动记录":(isDevice=="1"?"设备上传":"");
 
- }
 
- function getBJRecordType(isDevice) {
 
- 	return isDevice === 0 ? "手动记录" : isDevice == 1 ? "设备上传" : '';
 
- }
 
- var html = template('tizheng_list_temp',{
 
- 	xuetang:{},
 
- 	xueya:{},
 
- 	tizhong:{},
 
- 	yaowei:{}
 
- });
 
- $tizhengList.html(html);
 
- function getRecentDataInit(){
 
- 	//体征记录
 
- 	getRecentDataPromise()
 
- 	.then(function(res) {
 
- 		xuetangRecord = _.find(res.data,function(o) {
 
- 			var d = new Date(o.recordDate.replace(/\-/g, "/"));
 
- 			o.recordDate = d.getFullYear() + '-' + checkDate(d.getMonth() + 1) + '-' + checkDate(d.getDate());
 
- 			return o.type =="1";
 
- 		}) || {};
 
- 		xuyaRecord = _.find(res.data,function(o) {
 
- 			return o.type =="2";
 
- 		}) || {};
 
- 		tizhongRecord = _.find(res.data,function(o) {
 
- 			return o.type =="3";
 
- 		}) || {};
 
- 		yaoweiRecord = _.find(res.data,function(o) {
 
- 			return o.type =="4";
 
- 		}) || {};
 
- 		
 
- 		var xuetangValue = "";
 
- 		var xuetangValueIndex;
 
- 		var during = _.find(xuetangDuring,function(v,i){
 
- 			xuetangValue = xuetangRecord['value'+[i]];
 
- 			xuetangValueIndex = i;
 
- 			return i>0&&xuetangValue;
 
- 		});
 
- 		
 
- 		xtdt = xuetangRecord.recordDate;
 
- 		xydt = xuyaRecord.recordDate;
 
- 		tzdt = tizhongRecord.recordDate;
 
- 		ywdt = yaoweiRecord.recordDate;
 
- 		var duringIndex = xuetangRecord.value2 ? xuetangRecord.value2 : 0;
 
- 		return {
 
- 		    //血糖中,value1返回最新的值,value2表示当前值对应的时间段的值(1-7)
 
- 			xuetang: $.extend({},xuetangRecord,{
 
- 				during:  duringIndex ? xuetangDuring[duringIndex] : '',
 
- 				value: xuetangValue,
 
- 				levelClazz: (function() {
 
- 					// 不同时间段对应不同的血糖范围
 
- //					var levels = [[],[7.0, 3.9],[11.1, 4.0],
 
- //								[7.0, 3.9],[11.1, 4.4],
 
- //								[7.0, 3.9],[11.1, 4.4],
 
- //								[7.0, 3.9]][xuetangValueIndex];
 
-                     var levels = [[],[7.0, 3.9],[11.1, 4.0],
 
-                                 [7.0, 3.9],[11.1, 4.0],
 
-                                 [7.0, 3.9],[11.1, 4.0],
 
-                                 [7.0, 3.9]][duringIndex]
 
- 				
 
- 					return getLevelClazz(xuetangValue, levels[0],levels[1])
 
- 				})(),
 
- 				recordType: getRecordType(xuetangRecord.deviceSn)
 
- 			}),
 
- 			xueya: $.extend({},xuyaRecord,{
 
- 				levelClazz: getLevelClazz(xuyaRecord.value1, 139, 90)||getLevelClazz(xuyaRecord.value2, 89, 60),
 
- 				recordType: getRecordType(xuyaRecord.deviceSn)
 
- 			}),
 
- 			tizhong: $.extend({},tizhongRecord,{
 
- 				recordType: getRecordType(tizhongRecord.deviceSn)
 
- 			}),
 
- 			yaowei:  $.extend({},yaoweiRecord,{
 
- 				recordType: getRecordType(yaoweiRecord.deviceSn)
 
- 			})
 
- 		}
 
- 	})
 
- 	.then(function(data) {
 
- 		var html = template('tizheng_list_temp',data);
 
- 		$tizhengList.html(html)
 
- 	})
 
- 	.catch(function(e) {
 
- 		d.close();
 
- 		console && console.error(e)
 
- 	});
 
- 	
 
- 	//保健记录
 
- 	getBJRecentDataPromise()
 
- 	.then(function (res) {
 
- 		yundongRecord = res.data.sprot;
 
- 		yongyaoRecord = res.data.medication;
 
- 		yinshiRecord = res.data.diet;
 
- 		
 
- 		yddt = yundongRecord.recordDate;
 
- 		yydt = yongyaoRecord.recordDate;
 
- 		ysdt = yinshiRecord.recordDate;
 
- 		return {
 
- 			yundong: (function () {
 
- 				yundongRecord.recordType = getBJRecordType(yundongRecord.source);
 
- 				return yundongRecord;
 
- 			})(),
 
- 			yongyao: (function () {
 
- 				yongyaoRecord.recordType = getBJRecordType(yongyaoRecord.source);
 
- 				return yongyaoRecord;
 
- 			})() ,
 
- 			yinshi: (function () {
 
- 				yinshiRecord.recordType = getBJRecordType(yinshiRecord.source);
 
- 				return yinshiRecord;
 
- 			})()
 
- 		};
 
- 	}).then(function (data) {
 
- 		var html = template('baojian_list_tmp',data);
 
- 		$baojianList.html(html)
 
- 	});
 
- }
 
- getRecentDataInit();
 
- getEquipments(); 
 
- bindEvents();
 
 
  |