define(['zepto','medtap'],function($,medtap){
	var rukou = {
		wechatId:medtap.getRequest('wechatId'),
		init:function(){
			rukou.getToken()
		},
		checkUser:function(){
			medtap.loading(1);
			medtap.submitAjax({
				url:'https://gateway.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)
					}else{
						window.location.replace('https://review-formal.iplusmed.com/wechatForLungCancer/prd/wechat_lung_login/login.html?wechatId=' + rukou.wechatId)
					}
				}
			})
		},
		getToken:function(){
			localStorage.wxLungToken = '';
			medtap.loading(1);
			medtap.submitAjax({
				url: 'https://gateway.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();
})