| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478 | 
							- var d = dialog({contentType:'load', skin:'bk-popup'});
 
- var id = 0;
 
- var pagetype = 22;
 
- var scroller1 = new IScrollPullUpDown('wrapper',{
 
- 	probeType:2,
 
- 	bounceTime: 250,
 
- 	bounceEasing: 'quadratic',
 
- 	mouseWheel:false,
 
- 	scrollbars:true,
 
- 	click:true,
 
- 	fadeScrollbars:true,
 
- 	interactiveScrollbars:false
 
- }, pullDownAction, null);
 
- $(function(){
 
- 	// 判断是否登录
 
- 	checkUserAgent();
 
- 	$('#msgContainer').on('tap',function() {
 
- 		var userAgent = JSON.parse(window.localStorage.getItem(agentName));
 
- 		window.location.href = "application-msg-list.html?member="+userAgent.uid;		
 
- 	});
 
- 	// 点击咨询详情
 
- 	$("body").on("tap", ".n-list.tap-enable", function () {
 
- 		if ($(this).is(".list-last")) {
 
- 			window.location.href = "add-step1.html";
 
- 		} else {
 
- 			// 缓存信息
 
- 			var index = $(this).parents("li").index();
 
- 			var name = $(this).data("name");
 
- 			var imgUrl = $(this).find("img").attr("src");
 
- 			var code = $(this).data("code");
 
- 			var mobile = $(this).data("mobile");
 
- 			var idcard = $(this).data("idcard");
 
- 			var address = $(this).data("address");
 
- 			var sign = $(this).data("sign");
 
- 			var relation,
 
- 				relationIndex = "relation" + index;
 
- 			relation = $(this).data("relation");
 
- 			window.localStorage.removeItem(relationIndex);
 
- 			window.localStorage.setItem(relationIndex, relation);
 
- 			window.localStorage.removeItem("index");
 
- 			window.localStorage.setItem("index", index);
 
- 			window.localStorage.removeItem("name");
 
- 			window.localStorage.setItem("name", name);
 
- 			window.localStorage.removeItem("imgUrl");
 
- 			window.localStorage.setItem("imgUrl", imgUrl);
 
- 			window.localStorage.removeItem("code");
 
- 			window.localStorage.setItem("code", code);
 
- 			window.localStorage.removeItem("mobile");
 
- 			window.localStorage.setItem("mobile", mobile);
 
- 			window.localStorage.removeItem("idcard");
 
- 			window.localStorage.setItem("idcard", idcard);
 
- 			window.localStorage.removeItem("address");
 
- 			window.localStorage.setItem("address", address);
 
- 			window.localStorage.removeItem("sign");
 
- 			window.localStorage.setItem("sign", sign);
 
- 			// 跳转详情
 
- 			window.location.href = "family-detail.html";
 
- 		}
 
- 	});
 
- 	//免疫关联
 
- 	$("body").on("tap", ".n-list.childSick", function (){
 
- 		var $this = $(this)
 
- 		location.href="../../fybj/html/mianyijihua.html"
 
- 	})
 
- 	bindEvents();
 
- });
 
- //下拉刷新
 
- function pullDownAction(theScrollerTemp) {
 
- 	$(".pullDown").show();
 
- 	setTimeout(function () {
 
- 		$("#ul_family").html("");
 
- 		queryInit();
 
- 	}, 1000);
 
- }
 
- //上拉加载数据
 
- function pullUpAction(theScrollerTemp) {
 
- 	$(".pullUp").show();
 
- 	setTimeout(function () {
 
- 		queryInit();
 
- 	}, 1000);
 
- }
 
- // 禁止拖动
 
- document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
 
- function bindEvents() {
 
- 	$('#wrapper').on('tap','.cancel-btn',function() {
 
- 		var id = $(this).attr('data-id');
 
- 		dialog({
 
- 			content: '确定撤销添加此家人的申请吗?',
 
- 			ok: function() {
 
- 				cancelApplicationPromise(id)
 
- 				.then(function(res) {
 
- 					if(res.status=="200") {
 
- 						dialog({contentType:'tipsbox', skin:'bk-popup' , content:"撤销成功"}).show();
 
- 						$("#ul_family").html("");
 
- 						queryInit();
 
- 					} else {
 
- 						dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg||"撤销失败"}).show();
 
- 					}
 
- 				},function() {
 
- 					dialog({contentType:'tipsbox', skin:'bk-popup' , content:"撤销失败"}).show();
 
- 				}).catch(function(e) {
 
- 					console && console.error(e)
 
- 				})
 
- 			},
 
- 			cancel: function() {
 
- 				return;
 
- 			}
 
- 		}).showModal();
 
- 	}).on('tap','.retry-btn',function() {
 
- 		var code = $(this).attr('data-code');
 
- 		var mobile = $(this).attr('data-mobile');
 
- 		var name = $(this).attr('data-name');
 
- 		var relation = $(this).attr('data-relation');
 
- 		var photo = $(this).attr('data-photo');
 
- 		retryApplication(name,code,mobile,relation,photo);
 
- 	}).on('tap','.immunememberConnec',function(){
 
- 		location.href="../../fybj/html/mianyijihua.html"
 
- 	});	
 
- }
 
- /**
 
-  * 界面数据初始化
 
-  */
 
- function queryInit() {
 
- 	d.show();
 
- 	var data = {};
 
- 	sendPostNoCache("patient/family/members", data, "json", "get", queryListFailed, queryAppoListSuccesss);
 
- 	var userAgent = JSON.parse(window.localStorage.getItem(agentName));
 
- 	getFamilyMesListPromise(userAgent.uid)
 
- 	.then(function(res) {
 
- 		if(res.status == "200") {
 
- 			if(res.data.mes && res.data.mes.length) {
 
- 				var unhandledMsgs = _.filter(res.data.mes,function(v) {
 
- 					return v.state == '0'
 
- 				});
 
- 				if(unhandledMsgs.length) {
 
- 					$('#msgNum').text('('+unhandledMsgs.length+')')
 
- 				}
 
- 			}
 
- 		} else {
 
- 			dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
 
- 		}
 
- 	});
 
- }
 
- function queryListFailed(res) {
 
- 	d.close();
 
- 	if (res && res.msg) {
 
- 		var d1 = dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg});     
 
- 	} else {
 
- 		var d2 = dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载失败'}); 
 
- 	}
 
- }
 
- function queryAppoListSuccesss(res) {
 
- 	if (res.status == 200) {
 
- 		var $list = document.querySelector("#ul_family");
 
- 		if (res.data && res.data.normalmembers.length > 0) {
 
- 			var list = res.data.normalmembers;
 
- 			window.localStorage.removeItem("userfamily");
 
- 			window.localStorage.setItem("userfamily", JSON.stringify(res.data));
 
- 			for (var i = 0; i < list.length; i++) {
 
- 				var $li = document.createElement("li");
 
- 				var code = list[i].code;
 
- 				var name = list[i].name;
 
- 				var mobile = list[i].mobile;
 
- 				var idcard = list[i].idcard;
 
- 				var address = list[i].address;
 
- 				var familyRelation = list[i].familyRelation;
 
- 				var photo = getImgUrl(list[i].photo);
 
- 				var signType=list[i].signType;
 
- 				var isAuthorize = list[i].isAuthorize;
 
- 				var state = list[i].state; // 状态(0 :未处理;1:已同意;2:已拒绝;3:已撤销)
 
- 				var id = list[i].id;
 
- 				// 手机不存在默认显示未绑定手机
 
- 				if(mobile == undefined || mobile == null || mobile == ""){
 
- 					mobile = "未绑定手机";
 
- 				}
 
- 				// 地址不存在或者为空显示空
 
- 				if(address == undefined || address == null || address == ""){
 
- 					address = "";
 
- 				}
 
- 				// 头像为空设置默认头像
 
- 				if(photo == undefined || photo == null || photo == ""){
 
- 					photo = "../../../images/p-default.png";
 
- 				}
 
- 				// 家庭关系
 
- 				var relation = "";
 
- 				if (familyRelation == 0) {
 
- 					relation = "其他";
 
- 				} else if (familyRelation == 1) {
 
- 					relation = "父亲";
 
- 				} else if (familyRelation == 2) {
 
- 					relation = "母亲";
 
- 				} else if (familyRelation == 3) {
 
- 					relation = "老公";
 
- 				} else if (familyRelation == 4) {
 
- 					relation = "老婆";
 
- 				} else if (familyRelation == 5) {
 
- 					relation = "儿子";
 
- 				} else if (familyRelation == 6) {
 
- 					relation = "女儿";
 
- 				} else if (familyRelation == 7) {
 
- 					relation = "未知";
 
- 				};
 
- 				// 签约类型
 
- 				var signTmpl = "";
 
- 				var signText = "";
 
- 				if (signType == 0) {
 
- 					signTmpl = '<p class="red">未签约</p>';
 
- 					signText = "未签约";
 
- 				} else {
 
- 					if (signType == 1) {
 
- 						signText = "三师共管";
 
- 					} else if (signType == 2) {
 
- 						signText = "家庭医生";
 
- 					} else if (signType == 3) {
 
- 						signText = "三师共管、家庭医生";
 
- 					}
 
- 					signTmpl = '<p>签约类型:' + signText + '</p>'
 
- 				}
 
- 				var childContent = "";
 
- 				if(state == "1") {
 
- 					childContent =  '<div class="c-list c-border dr-item list-wrap"><div class="n-list tap-enable" data-name="' + name + '" data-mobile="' + mobile + '" data-idcard="' + idcard + '" data-code="' + code + '" data-address="' + address + '" data-sign="' + signText + '" data-relation="' + familyRelation + '">'+
 
- 									'<div class="n-list-li">'+
 
- 										'<div class="n-list-key">'+
 
- 											'<div class="n-avatar-l">'+
 
- 												'<img class="c-images-cycle" src="' + photo + '">'+
 
- 											'</div>'+
 
- 										'</div>'+
 
- 										'<div class="n-list-info pl15">'+
 
- 											'<h2>' + name + '(' + relation + ')</h2>'+ signTmpl +
 
- 										'</div>'+
 
- 									'</div>'+
 
- 								'</div>'+
 
- 								'<li class="c-list-cover">'+
 
- 			                        '<div class="c-list-info">'+
 
- 			                           '<h4 class="c-nowrap c-f14">授权设置</h4>'+
 
- 			                            '<p class="c-nowrap">是否允许该家人处理您全部健康服务</p>'+
 
- 			                        '</div>'+
 
- 			                        '<div class="c-list-key">'+
 
- 			                            '<div data-code="' + code + '" class="mui-switch mui-switch-mini '+(isAuthorize=="1"?'mui-active':'')+
 
- 			                            '"><div class="mui-switch-handle"></div></div></div>'
 
- 			                        '</div>'+
 
- 			                    '</li>'
 
- 								;
 
- 				} else if(state == "0") {
 
- 					childContent =  '<div class="c-list c-border dr-item list-wrap"><div class="n-list" data-name="' + name + '" data-mobile="' + mobile + '" data-idcard="' + idcard + '" data-code="' + code + '" data-address="' + address + '" data-sign="' + signText + '" data-relation="' + familyRelation + '">'+
 
- 									'<div class="n-list-li">'+
 
- 										'<div class="n-list-key">'+
 
- 											'<div class="n-avatar-l">'+
 
- 												'<img class="c-images-cycle" src="' + photo + '">'+
 
- 											'</div>'+
 
- 										'</div>'+
 
- 										'<div class="n-list-info pl15">'+
 
- 											'<h2>' + name + '(' + relation + ')</h2>'+ '<p class="red">待对方确认关联</p>' +
 
- 										'</div>'+
 
- 									'</div>'+
 
- 								'</div>'+
 
- 								'<div class="ptb10 plr10 c-border-t">'+
 
- 									'<div class="c-row">'+
 
- 								        '<div class="c-50"><div data-name="'+name+'" data-code="'+code+'" data-mobile="'+mobile+'" data-relation="'+familyRelation+'"data-photo="'+photo+'"  class="c-btn c-btn-full c-btn-radius c-btn-4dcd70 retry-btn">重新添加</div></div>'+
 
- 								        '<div class="c-50"><div data-id="'+id+'"  class="c-btn c-btn-full c-btn-radius c-btn-fc6155 cancel-btn"> 撤销 </div></div>'+
 
- 								    '</div>'+
 
- 			                    '</div>'
 
- 								;
 
- 				} else if(state == "2") {
 
- 					childContent =  '<div class="c-list c-border dr-item list-wrap"><div class="n-list childSick" data-name="' + name + '" data-idcard="' + idcard + '" data-code="' + code + '">'+
 
- 									'<div class="n-list-li">'+
 
- 										'<div class="n-list-key">'+
 
- 											'<div class="n-avatar-l">'+
 
- 												'<img class="c-images-cycle" src="' + photo + '">'+
 
- 											'</div>'+
 
- 										'</div>'+
 
- 										'<div class="n-list-info pl15">'+
 
- 											'<h2>' + name + '(免疫关联)</h2>'+'<p>未签约</p>'
 
- 										'</div>'+
 
- 									'</div>'+
 
- 								'</div>';
 
- 				}
 
- 				
 
- 				$li.innerHTML = childContent;
 
- 				$list.appendChild($li);
 
- 			}
 
- 			if( res.data.immunemembers && res.data.immunemembers.length > 0){
 
- 				var listImmunemembers = res.data.immunemembers;
 
- 				for(var j = 0; j < listImmunemembers.length; j++){
 
- 					var $li = document.createElement("li");
 
- 					var immunememberName = listImmunemembers[j].name;
 
- 					var immunememberPhoto = getImgUrl(listImmunemembers[j].photo);
 
- 					// 头像为空设置默认头像
 
- 					if(immunememberPhoto == undefined || immunememberPhoto == null || immunememberPhoto == ""){
 
- 						immunememberPhoto = "../../../images/p-default.png";
 
- 					}
 
- 					childContent =  '<div class="c-list c-border dr-item list-wrap immunememberConnec"><div class="n-list childSick" data-name="' + immunememberName + '" data-idcard="' + idcard + '" data-code="' + code + '">'+
 
- 									'<div class="n-list-li">'+
 
- 										'<div class="n-list-key">'+
 
- 											'<div class="n-avatar-l">'+
 
- 												'<img class="c-images-cycle" src="' + immunememberPhoto + '">'+
 
- 											'</div>'+
 
- 										'</div>'+
 
- 										'<div class="n-list-info pl15">'+
 
- 											'<h2>' + immunememberName + '(免疫关联)</h2>'
 
- //											+'<p>未签约</p>'
 
- 										'</div>'+
 
- 									'</div>'+
 
- 								'</div>';
 
- 					$li.innerHTML = childContent;
 
- 					$list.appendChild($li);
 
- 				}
 
- 				
 
- 			}
 
- 			var $liLast = document.createElement("li");
 
- 		    lastContent = '<div class="n-list tap-enable list-last dr-item c-t-center">'+
 
- 		            			'<i class="icon-add"></i>'+
 
- 		            			'<p>添加家人</p>'+
 
- 		            		'</div>';
 
- 		    $liLast.innerHTML = lastContent;
 
- 			$list.appendChild($liLast);
 
- 		} else {
 
- 			var $li = document.createElement("li");
 
- 			var content =   '<div class="n-list tap-enable list-last dr-item c-t-center">'+
 
- 		            			'<i class="icon-add"></i>'+
 
- 		            			'<p>添加家人</p>'+
 
- 	            			'</div>';
 
- 			$li.innerHTML = content;
 
- 			$list.appendChild($li);
 
- 		}
 
- 		d.close();
 
- 		scroller1.myScroll.refresh();
 
- 		$(".pullUp").hide();
 
- 		$(".pullDown").hide();
 
- 	} else {
 
- 		//非200则为失败
 
- 		queryListFailed(res);
 
- 	}
 
- 	mui('.mui-switch')['switch']();
 
- 	$('.mui-switch').on('toggle',function(e) {
 
- 		var event = e.originalEvent;
 
- 		d.show()
 
- 		var isAuthorize = event.detail.isActive?1:0;
 
- 		var msg = isAuthorize?'授权':'取消授权';
 
- 		sendPost("patient/family/member_authorize", {
 
- 	    	familyMember: $(this).data('code'),
 
- 	    	isAuthorize: isAuthorize
 
- 	    }, "json", "post", function() {
 
- 	    	d.close();
 
- 	    	dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:msg+'失败'}).show();
 
- 	    }, function(){
 
- 	    	d.close();
 
- 	    	dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:(msg+'成功')}).show(); 
 
- 	    });
 
- 	})
 
- }
 
- function getFamilyMesListPromise(code) {
 
- 	return new Promise(function(resolve, reject) {
 
- 		sendPost("patient/family/getFamilyMesList", {
 
- 			code: code
 
- 		} , "json", "POST",
 
- 			function failed (res) {
 
- 				d.close();
 
- 				
 
- 			}, function(res) {
 
- 				resolve(res)
 
- 		});
 
- 	})
 
- }
 
- function cancelApplicationPromise(id) {
 
- 	d.show();
 
- 	return new Promise(function(resolve, reject) {
 
- 		sendPost("patient/family/member_revoke", {
 
- 			id: id
 
- 		} , "json", "POST",
 
- 			function failed (res) {
 
- 				d.close();
 
- 				reject(res);
 
- 			}, function(res) {
 
- 				d.close();
 
- 				resolve(res)
 
- 		});
 
- 	})
 
- }
 
- function checkMemberPromise(code) {
 
- 	
 
- 	return new Promise(function(resolve, reject) {
 
- 		sendPost("patient/family/check_member", {
 
- 			memberCode: code
 
- 		}, "json", "get", commitFailed, function(res) {
 
- 			resolve(res)
 
- 		});
 
- 	})
 
- }
 
- // 提交失败
 
- function commitFailed (res) {
 
- 	d.close();
 
- 	if (res && res.msg) {
 
- 		var d1 = dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
 
- 	} else {
 
- 		var d2 = dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败'}).show();
 
- 	}
 
- }
 
- function sendWXTempPromise(data) {
 
- 	return new Promise(function(resolve, reject) {
 
- 		sendPost("patient/family/sendWXTemp", data , "json", "POST", commitFailed, function(res) {
 
- 			resolve(res)
 
- 		});
 
- 	})
 
- }
 
- function retryApplication(name,code,mobile,relation,photo) {
 
- 	d.show();
 
- 	
 
- 	window.localStorage.removeItem("familyCode");
 
- 	window.localStorage.setItem("familyCode", code);
 
- 	window.localStorage.removeItem("familyName");
 
- 	window.localStorage.setItem("familyName", name);
 
- 	window.localStorage.removeItem("familyImgUrl");
 
- 	window.localStorage.setItem("familyImgUrl", photo);
 
- 	window.localStorage.removeItem("familyRelation");
 
- 	window.localStorage.setItem("familyRelation", relation);
 
- 	
 
- 	checkMemberPromise(code)
 
- 	.then(function(res) {
 
- 		d.close();
 
- 		if(res.status == "200") {
 
- 			var state = res.data.state;
 
- 			if(state == "0") { // 未绑定微信和手机
 
- 				window.location.href = 'add-step3.html';
 
- 			} else if(state == "1") { // 仅绑定微信
 
- 				sendWXTempPromise({
 
- 					member: code,
 
- 					relation: relation,
 
- 					reAdd: "1" // 重新申请
 
- 				})
 
- 				.then(function(res) {
 
- 					if(res.status=="200") {
 
- 						dialog({contentType:'tipsbox', skin:'bk-popup' , content:"已发送添加申请"}).show();
 
- 					} else {
 
- 						if(res.msg){
 
- 						    dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
 
- 						}else
 
- 						dialog({contentType:'tipsbox', skin:'bk-popup' , content:"发送失败"}).show();
 
- 					}
 
- 				})
 
- 			} else if(state == "2") { // 仅绑定手机
 
- 				window.localStorage.removeItem("familyMobile");
 
- 				window.localStorage.setItem("familyMobile", mobile);
 
- 				window.location.href = 'add-step2.html';
 
- 			} else if(state== "3") { // 手机和微信都绑定
 
- 				window.localStorage.removeItem("familyMobile");
 
- 				window.localStorage.setItem("familyMobile", mobile);
 
- 				window.location.href = 'add-step2-pre.html?reAdd=1';
 
- 			}
 
- 		} else {
 
- 			d.close();
 
- 			dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败'}).show()
 
- 		}
 
- 	})
 
- 	.catch(function(e) {
 
- 		d.close();
 
- 		console && console.error(e)
 
- 	})
 
- }
 
 
  |