myHome.js 3.11 KB
Newer Older
hanpeng committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
define(['zepto','medtap'],function($,medtap){
	var my = {
		wechatId:medtap.getRequest('wechatId'),
		init:function(){
			my.getToken();
		},
		getToken: function() {
			localStorage.wxLungToken = '';
			medtap.loading(1);
			medtap.submitAjax({
				url: 'https://testdevgw.medtap.cn/user/auth/token',
				type: 'POST',
				async: false,
				contentType: 'application/json',
				data: {
					wechatId: my.wechatId
				},
				success: function(res) {
					medtap.loading(0);
					if (res.success == true) {
						var token = res.content.token;
						localStorage.setItem('wxLungToken', token);
						my.checkUser();
					} else {
		
					}
				},
				error: function(res) {
					console.log(res.resultDesc);
				}
			})
		},
		checkUser: function() {
			medtap.loading(1);
			medtap.submitAjax({
				url: 'https://testdevgw.medtap.cn/wechat/user/getWechatUser',
				type: 'GET',
				async: false,
				data: {
					wechatId: my.wechatId
				},
				success: function(res) {
					medtap.loading(0);
					var info = res.content.wechatUser;
					if (info.hasOwnProperty('userId')) {
						my.getUserDetail();
					} else {
						window.location.replace('../login/login.html?wechatId=' + my.wechatId + '&route=my');
					}
				}
			})
		},
		getUserDetail:function(){
			medtap.loading(1);
			medtap.submitAjax({
				url:'https://testdevgw.medtap.cn/user/getUserDetail',
				type:'GET',
				async:false,
				data:{
					
				},
				success:function(res){
					medtap.loading(0);
					if(res.success == true){
						var userInfo = res.content.userInfo;
hanpeng committed
66
						/* $('#username').val(userInfo.username);
hanpeng committed
67 68 69 70 71 72 73 74 75 76 77 78 79
						$('#sex').val(userInfo.sex == 'M' ? '男' : '女');
						$('#mobile').val(userInfo.mobile);
						$('#tel').val(userInfo.telephone || '');
						$('#wechat').val(userInfo.wechatNumber || '');
						$('#email').val(userInfo.email || '');
						if(userInfo.hasOwnProperty('healthType')){
							if(userInfo.healthType.child == 'HE1'){
								$('#healthType').val('健康的咨询者');
							}else if(userInfo.healthType.child == 'HE2'){
								$('#healthType').val('患者家属');
							}else if(userInfo.healthType.child == 'HE3'){
								$('#healthType').val('患者本人');
							}
hanpeng committed
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
						} */
						if (!userInfo.hasOwnProperty('healthType') || !userInfo['username'] || !userInfo['sex'] || !userInfo['telephone']) {
							window.location.replace('../login/pages/basicUserInfo.html?wechatId=' + my.wechatId  + '&operationType=12&route=my');
						} else {
							$('#username').val(userInfo.username);
							$('#sex').val(userInfo.sex == 'M' ? '男' : '女');
							$('#mobile').val(userInfo.mobile);
							$('#tel').val(userInfo.telephone || '');
							$('#wechat').val(userInfo.wechatNumber || '');
							$('#email').val(userInfo.email || '');
							if(userInfo.hasOwnProperty('healthType')){
								if(userInfo.healthType.child == 'HE1'){
									$('#healthType').val('健康的咨询者');
								}else if(userInfo.healthType.child == 'HE2'){
									$('#healthType').val('患者家属');
								}else if(userInfo.healthType.child == 'HE3'){
									$('#healthType').val('患者本人');
								}
							}
hanpeng committed
99
						}
hanpeng committed
100
	
hanpeng committed
101 102 103 104 105 106 107
					}
				}
			})
		}
	}
	my.init();
})