define(['zepto','medtap'],function($,medtap){
	var rukou = {
		wechatId:medtap.getRequest('wechatId'),
		// 问卷id
    followUpId: medtap.getRequest('followUpId'),
		init:function(){
			rukou.getToken()
		},
		checkUser:function(){
			medtap.loading(1);
			medtap.submitAjax({
				url:'https://testdevgw.medtap.cn/wechat/user/getWechatUser',
				type:'GET',
				async: false,
				data:{
					wechatId:rukou.wechatId
				},
				success:function(res){
					medtap.loading(0);
					var info = res.content.wechatUser;
					if(info.hasOwnProperty('userId')){
						//medtap.pushWindow('index.html?wechatId=' + rukou.wechatId)
						window.location.replace('index.html?wechatId=' + rukou.wechatId +'&followUpId='+ rukou.followUpId)
					}else{
						window.location.replace('https://review-formal.iplusmed.com/wechatForLungCancer/dev/wechat_lung_login/login.html?wechatId=' + rukou.wechatId)
					}
				}
			})
		},
		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: rukou.wechatId
				},
				success: function(res) {
					medtap.loading(0);
					if (res.success == true) {
						var token = res.content.token;
						localStorage.setItem('wxLungToken', token);
						rukou.checkUser();
					} else {
			
					}
				},
				error: function(res) {
					console.log(res.resultDesc);
				}
			})
		}
	}
	rukou.init();
})