!function(){
		var httpData=GetRequest();
		var userInfo = JSON.parse(window.localStorage.getItem(httpRequest.agentName));  
		new Vue({
					el:"#app",
		data:{
			planids:httpData['planids'],
			serviceData:[],
			isCollapse :false,
			collapseIndex:0,
			qrCode:'',
			qrModal:false,
		},
		mounted:function(){
			this.getServiceItemList();
		},
		methods:{
			chakan:function(){
				this.isCollapse=!this.isCollapse;
			},
			changeCollapseIndex:function(idx){
				this.collapseIndex=idx;
			},
			qwapp:function(){
				layer.msg('请前往app处理',{icon:5});    
			},
			//获取服务列表
			getServiceItemList:function(){
				var vm=this;
				var loginDoctor = JSON.parse(window.localStorage.getItem('wlyyAgent') || '{}');
				var loadding = layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
				rehaAPI.serviceItemList({planDetailIds:vm.planids}).then(function(res){
					layer.close(loadding);
					if(res.status==200){
						var isZK=loginDoctor.doctorType==1?true:false;
						vm.serviceData=_.map(res.data||{},function(o){
							o.isZK=isZK;
							if(o.isMyTask==1){//执行者										
								o.isCK=true;//无法显示按钮
								if(loginDoctor.uid==o.specialistDoctorCode){//说明我自己是创建者
									o.isCK=false;
									o.isCreate=true;
								}
							}else{
								if(loginDoctor.uid==o.specialistDoctorCode){//说明我自己是创建者
									o.isCreate=true;
								}
							}
							console.log(o)
							return o
						})
					}else{
						layer.msg(res.msg,{icon:5});
					}
				})
			},
			//健康教育
			jkjy:function(patient,planId){
				var vm=this
				layer.open({
					type: 2,
					area: ['80%', '600px'],
					shade: 0.5,
					title: '健康教育',
					fixed: true, //不固定
					maxmin: true,
					closeBtn: 1,
					shift: 5,
					shadeClose: false, //点击遮罩关闭层
					content: '../../article/html/article.html?code='+patient+'&planId='+planId+'&isReha=true',
					end: function() { // 未点击确定按钮，点击关闭按钮  
						vm.getServiceItemList();　　　　
					}
				});
			},
//						健康指导
			jkzd:function(planId,patient){
				var vm=this
				layer.open({
					type: 2,
					//				  offset: ['100px'], //右下角弹出
					area: ['80%', '600px'],
					shade: 0.5,
					title: '健康指导',
					fixed: true, //不固定
					maxmin: true,
					closeBtn: 1,
					shift: 5,
					shadeClose: false, //点击遮罩关闭层
					content:'../../guidance/html/index.html#/person-edit-panel?patient='+patient+'&planId='+planId,
					end: function() { // 未点击确定按钮，点击关闭按钮  
						vm.getServiceItemList();　　　　
					}
				});
			},
//						暂未开放
			zwkf:function(){
				layer.msg('此功能暂未开放',{icon:1});
			},
			goToFinish:function(planid){
				var vm=this;
				layer.open({
				  type: 2,
//				  offset: ['100px'], //右下角弹出
				  area: ['80%', '600px'],
				  shade: 0.5,
				  title: '完成项目确认',
				  fixed: true, //不固定
				  maxmin: true,
				  closeBtn:1,
				  shift: 5,
				  shadeClose: false, //点击遮罩关闭层
				  content: '../../rehabilitation/html/guide_the_message.html?planid='+planid,
				  end: function() { // 未点击确定按钮，点击关闭按钮  
						vm.getServiceItemList();　　　　
					}
				});
			},
			fwm:function(planid,patient){
				this.loadSocket(planid,patient);
			},
			zdly:function(data){
				var vm = this
				var loginDoctor = JSON.parse(window.localStorage.getItem('wlyyAgent'));
				var otherCode,otherName;
				var planDetailId='';
				
				if(data.specialistDoctorCode==data.executeDoctorCode){
					layer.msg('无法与自己聊天',{icon:5}); 
					return ;
				}
				if(data.isMyTask==1){
					otherCode=data.specialistDoctorCode;
					otherName=data.specialistDoctorName;
				}else{
					planDetailId=data.planDetaiId;
					otherCode=data.executeDoctorCode;
					otherName=data.executeDoctorCode;
				}
				layer.open({
				  type: 2,
//				  offset: ['100px'], //右下角弹出
				  area: ['80%', '600px'],
				  shade: 0.5,
				  title: '指导留言',
				  fixed: true, //不固定
				  maxmin: true,
				  closeBtn:1,
				  shift: 5,
				  shadeClose: false, //点击遮罩关闭层
				  content: '../../consulting/html/consulting.html?otherCode='+otherCode+'&otherName='+encodeURI(otherName)+'&planDetailId='+planDetailId,
				  end:function(){ // 未点击确定按钮，点击关闭按钮  
			　　　　　　vm.getServiceItemList();
			　　　　}
				});
			},
			loadSocket:function(planid,patient){
				var vm=this;
				var imurl=httpRequest.socketUrl;
			    jQuery.getScript(imurl+"/socket.io/socket.io.js").done(function() {
			    	var type=2;//咨询类型
			        var socket = io.connect(imurl);
			        var sessionId = 'system';
			        socket.emit('login', {userId: userInfo.uid, password: userInfo.uid,sessionId:sessionId,clientType:"doctor"});
			        socket.on('message', function (data) {
			      		console.log(data);
			      		if(data.type==0){
			      			vm.checkAfterQrCode(planid,patient);
			      		}
			        });
			
			        socket.on('error', function (data) {
			          console.log(data);
			        });
			
			        socket.on('ack', function (data) {
			          console.log(data);
			          vm.getQRCode(planid);
			        }); 
			        function getLocalTime(nS) {     
			            return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');     
			        }    
			    })
			    .fail(function() {
			        layer.msg('服务码创建失败',{icon:5});    
			    });
			},
			checkAfterQrCode:function(planid,patient){
				var vm=this;
				var params={
					planDetailId:planid,
					patientCode: patient
				}
				rehaAPI.checkAfterQrCode(params).then(function(res){
					var icon=5;
					if(data.status==200){
						if(data.data){
							icon=1;
							vm.goToFinish(planid);
						}
					}
					layer.msg(res.msg,{icon:icon});  
				})
			},
			getQRCode:function(planid){
				var vm=this;
				var loginDoctor = JSON.parse(window.localStorage.getItem('wlyyAgent'));
				var params={
					planDetailId:planid,
					doctorCode: loginDoctor.uid
				}
				rehaAPI.createServiceQrCode(params).then(function(res){
					console.log(res);
					if(res.status==200){
						vm.qrCode=res.data;
						setTimeout(function(){
							vm.qrModal=true;
						},100)
					}else{
						layer.msg('服务码获取失败',{icon:5});  
					}
				})
				
			}
		},
		filters:{
		  	formatDate:function(value, format) {
		  		if(!value) return ;
		  		var fmt=format || "yyyy-MM-dd hh:mm";
				var date = new Date(value);
				if (/(y+)/.test(fmt)) {
					fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
				}
				let o = {
					'M+': date.getMonth() + 1,
					'd+': date.getDate(),
					'h+': date.getHours(),
					'm+': date.getMinutes(),
					's+': date.getSeconds()
				};
				for (let k in o) {
					if (new RegExp(`(${k})`).test(fmt)) {
						let str = o[k] + '';
						fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : ('00' + str).substr(str.length));
					}
				}
				return fmt;
			}
		}
	})
}();