!function(){
				var httpData=GetRequest();
				var currentGMT=new Date();//当前时间GMT
	new Vue({
		el:"#app",
		data:{
			ynow: currentGMT.getFullYear(),//年份
			mnow: currentGMT.getMonth(),//月份（比实际少一个月---0开始至11）
			dnow: currentGMT.getDate(),//当前日
			currentDay:null,//带中文格式的当前年月
			currentDayForEn:null,//不带中文格式年月日2018/10/01如果写成/的话  转换成时间戳会变成北京时间8点
			calendarData:[],//日历数据
			timeAxisData:[],//时间轴数据
			__Data:[],//当前的年月（日历）
			__xData:[],//当前的年月(时间轴)
			isFastSearch: false, // 是否是快速查找任务
			status:null,//任务状态（0未完成，1已完成，2已预约）
			searchTask:null,//快速查找任务：（1、我的任务，2、健康教育，3、健康指导，4、随访，5、复诊）
			searchTaskName:null,//快速查找任务：（1、我的任务，2、健康教育，3、健康指导，4、随访，5、复诊）
			planId: httpData['planId'],
			patientCode: httpData['patientCode'],
			curDoc: JSON.parse(localStorage.docInfo),
			taskArr:[
				{code:1,name:'我的任务'},
				{code:2,name:'健康教育'},
				{code:3,name:'健康指导'},
				{code:4,name:'随访'},
				{code:5,name:'复诊'},
			],
			statusArr:[
				{code:0,name:'未完成'},
				{code:1,name:'已完成'},
				{code:2,name:'已预约'},
			],
			curTask:'',//快速查找是否点击了搜索按钮
			curTaskName:'',//快速查找是否点击了搜索按钮
			tabStatus:null,
			planInfo:{},
			docList:[],
			diagnosisInformation: null,
			searchData: [], // 搜索计划安排（去年、今年、明年）
		},
		mounted:function(){
			if(!this.planId){
				layer.msg('未传入计划id（planId）',{icon:2})
			}else{							
				this.tabStatus=1;
			}
			this.planSchedule();
			this.serviceDoctorList();//获取服务医生列表
			this.bindEvents();
			// 获取最新的诊疗信息1条
            this.findDiagnosisInformationByPlanId()
		},
		methods:{
			//获取计划表
			planSchedule:function(){
				var vm = this;
				var  params = {
		            planId: this.planId,
		            patientCode: this.patientCode
		        };
				rehaAPI.planSchedule(params).then(function(res){
					 if(res.status == 200){
			            vm.planInfo = res.data;
			            vm.planInfo.tagClass = "tag-"+res.data.healthyConditionType;
			            //patientImg：居民签名照/证件照,如果不为null的话说明居民已确认，显示康复完成明细
			            if(vm.planInfo.status==2 && !vm.planInfo.patientImg){//任务全部完成时，显示完成提示框
							vm.showCompleteDailog();
			            }else if(vm.planInfo.status==2 && vm.planInfo.patientImg){//居民已确认计划完成
			            	vm.tabStatus=3;
							$("#framePage").attr("src","stop_special_service.html?planids="+vm.planId+"&planStatus="+vm.planInfo.status)
			            }
			        }else{
			        	layer.msg(res.msg,{icon:5});
			        }
				})
			},
			// 获取最新的诊疗消息
			findDiagnosisInformationByPlanId: function() {
				var vm = this,
					loading = layer.load(0, {shade: false}),
					params = {
						planId: vm.planId
					}
				recoverAPI.findDiagnosisInformationByPlanId(params).then(function(res) {
					layer.close(loading)
					if(res.status == 200) {
						vm.diagnosisInformation = res.data
					} else {
						showErrorMessage(res.msg);
					}
				})
			},
			serviceDoctorList:function(){
				var vm = this;
				rehaAPI.serviceDoctorList({patientCode: this.patientCode}).then(function(res){
					 if(res.status == 200){
					 	vm.docList = res.data;
					 }else{
			        	layer.msg(res.msg,{icon:5});
			        }
				})
			},
			weiXinConfirmClick:function(){
				var vm = this;
				rehaAPI.sendWxMsg({planId: this.planId}).then(function(res){
					 if(res.status == 200){
					 	layer.msg("发送成功，等待居民确认");
					 	setTimeout(function(){
					 		vm.tabStatus=3;
							$("#framePage").attr("src","stop_special_service.html?planids="+vm.planId+"&planStatus="+vm.planInfo.status)
					 	},1000)
					 }else{
			        	layer.msg(res.msg,{icon:5});
			        }
				})
			},
			setImgSrc: function (src) {
                var str = httpRequest.getImgUrl(src)
                return str
            },
			showCompleteDailog:function(){
				layer.confirm('<div class="mt10 tac"><image src="../images/yiwancheng_icon.png" width="100" height="100"/><div class="mt20 c-f20 c-333 mb40">本次康复计划已完成</div><div class="div-patient-comfirm c-f14 c-fff bgc-12b7f5" style="margin:40px auto 20px;">邀请居民确认</div></div>', { 
		    		btn: [],
		    		area: ["400px", "340px"],
		    		title: "完成提示"
		    	}, function (index) {
		    		
	//	            layer.close(index);
		        });
			},
			refreshPage:function(){
				if(!this.planId){
					layer.msg('未传入计划id（planId）',{icon:2})
					return ;
				}
				this.goToLoadData(true);
			},
			bindEvents:function(){
				var vm = this;
				$("body").on("click",".div-patient-comfirm",function(){
					layer.closeAll();
					vm.weiXinConfirmClick();
				}).on("click", ".div-patient-home", function() {
					location.href = "../../recover/html/personal-manage.html?patientCode=" + vm.patientCode
				})
			},
			viewDetail:function(planids,status,type){
				var vm=this;
				if(!planids){
					layer.msg('无服务项',{icon:5})
					return ;
				}
				if(status==1 && type==1){
					top.layer.open({
					  type: 2,
					  area: ['800px', '650px'],
					  shade: 0.5,
					  title: '完成项目确认',
					  fixed: true, //不固定
					  maxmin: true,
					  closeBtn:1,
					  shift: 5,
					  shadeClose: false, //点击遮罩关闭层
					  content: '../../rehabilitation/html/guide_the_message.html?planid='+planids
					});
					return ;
				}
//							planids='402803f6657f195301657f4c4ce70000';
				layer.open({
				  type: 2,
				  area: ['800px', '650px'],
				  shade: 0.5,
				  title: '服务项目内容',
				  fixed: true, //不固定
				  maxmin: true,
				  closeBtn:1,
				  shift: 5,
				  shadeClose: false, //点击遮罩关闭层
				  content: '../../rehabilitation/html/service_item_content.html?planids='+planids,
				  end:function(){
				  	vm.goToLoadData(true);	
				  }
					
				});
			},
			changeStatus:function(val){
				this.status=this.status==val?null:val;
			},
			changeTask:function(val){
				this.searchTask=this.searchTask==val.code?null:val.code;
				this.searchTaskName=this.searchTaskName==val.name?null:val.name;
			},
			monDetail:function(){
			  this.currentDay = this.ynow + '年'+ (this.mnow + 1) +'月';
			  this.currentDayForEn=this.ynow+'/'+(this.mnow>=9?(this.mnow+1):"0"+(this.mnow+1))+'/'+(this.dnow>=9?this.dnow:"0"+this.dnow)
			},
			is_leap:function(year) {  //判断是否为闰年
			   return (year%100==0?res=(year%400==0?1:0):res=(year%4==0?1:0));
			},
			preMonth:function(){  //上一个月
			  if(this.mnow<=0){
			    this.mnow=11;
			    this.ynow=this.ynow-1;
			  }else{
			    this.mnow--;
			  }
			  this.monDetail();
			  this.goToLoadData(true);
			},
			getPreMouth:function(){
				var pMnow,pYnow;
				if(this.mnow<=0){
				    pMnow=11;
				    pYnow=this.ynow-1;
				  }else{
				    pMnow=this.mnow-1;
				    pYnow=this.ynow;
				  }
				var m_days=new Array(31,(28+this.is_leap(pYnow)),31,30,31,30,31,31,30,31,30,31);  //每个月的天数
				return {
						days:m_days[pMnow],
						date:pYnow+'-'+(++pMnow>=10?pMnow:"0"+pMnow)
					}
			},
			nextMonth:function(){   //下一个月
			  if(this.mnow>=11){
			    this.mnow=0;
			    this.ynow=this.ynow+1;
			  }else{
			     this.mnow++;
			  }
			  this.monDetail();
			  this.goToLoadData(true);			
			},
			getNextMouth:function(){
				var nMnow,nYnow;
				if(this.mnow>=11){
				    nMnow=0;
				    nYnow=this.ynow+1;
				  }else{
				     nMnow=this.mnow+1;
				     nYnow=this.ynow;
				  }
				var m_days=new Array(31,(28+this.is_leap(nYnow)),31,30,31,01,31,31,30,31,30,31);  //每个月的天数
				return {
						days:m_days[nMnow],
						date:nYnow+'-'+(++nMnow>=10?nMnow:"0"+nMnow)
					}
			},
			goToLoadData:function(flag){//flag是否更新数据
				this.tabStatus==1 && (!this.calendarData.length || flag) && this.calendar();
				this.tabStatus==2 && (!this.timeAxisData.length || flag) && this.timeAxis();
				this.changeSearch(-1)
			},
			calendar:function(){
			  var nlstr = new Date(this.ynow,this.mnow,1);  //当月第一天
			  var firstday = nlstr.getDay()-1;//第一天星期几,默认是周日  我们改成周一
			  firstday=firstday==-1?6:firstday;//如果是-1，说明当月的第一天是周日
			  var m_days=new Array(31,(28+this.is_leap(this.ynow)),31,30,31,30,31,31,30,31,30,31);  //每个月的天数
			  var tr_str=Math.ceil((m_days[this.mnow] + firstday)/7);   //当前月天数+第一天是星期几的数值   获得 表格行数
			  var c_days=m_days[this.mnow];//当前月份的天数
			  var p_arr=this.getPreMouth();
			  var n_arr=this.getNextMouth();
			  var i,k,idx,date_str;
			  var dataArr=[];//天数/年月
			  for(i=0;i<tr_str;i++) { //表格的行
			     for(k=0;k<7;k++) { //表格每行的单元格
			        idx=i*7+k; //单元格自然序列号
			        date_str=idx-firstday+1; //计算日期
			        var __ym;
			        if(date_str<=0){//过滤无效日期（小于等于零的、大于月总天数的）
			        	date_str=date_str+p_arr['days'];//当前日期+上个月的天数就是上个月的日期
			        	__ym=p_arr['date'];
			        }else if(date_str>c_days){
			        	date_str=date_str-c_days;//下个月的日期就是这个月的天数-当月的天数
			        	__ym=n_arr['date'];
			        }else{
			        	__ym=this.ynow+'-'+(this.mnow>=9?"":"0")+(this.mnow+1);
			        }
			        dataArr.push({
			        	day:date_str,
			        	date:__ym
			        });
			     }
			  }
			  this.__Data=dataArr;
			  this.monDetail();
			  this.calenderPlanDetail();
			},
			daysSort: function(arr) {
				var getArr = JSON.parse(JSON.stringify(arr)),
					returnArr = []
				for(var i = 1; i < 31; i++) {
					for(var j = 0, len = getArr.length; j < len; j++) {
						var stri = i > 9 + '' ? i : '0'+i
						if(getArr[j].day == stri) {
							returnArr.push(getArr[j])
							getArr.splice(j,1)
							break;
						}
					}
				}
				return returnArr
			},
			// 日历有计划数据处理
			planHandleData: function(data, day, mounth) {
				var item = data;
				item.day = day;
				if(mounth) {item.mounth = mounth}
				var finishFlag=false
				var sFlag=false;
				var fFlag=false;
				if(item.specialist){
					if(item.specialist.all==item.specialist.finish){
						sFlag=true;
					}
				}else{
					sFlag = true;
				}
				if(item.family){
					if(item.family.all==item.family.finish){
						fFlag = true;
					}
				}else{
					fFlag = true;
				}
				finishFlag = sFlag && fFlag;
				item.finishFlag=finishFlag;
				return item
			},
//						日历请求
			calenderPlanDetail:function(){
				var vm=this;
				var __days=vm.__Data;
				var lastDay=(__days.concat()).pop().day;
				lastDay=lastDay>9?lastDay:'0'+lastDay;
				if(vm.searchTask || vm.status || vm.status == 0) {
					vm.isFastSearch = true
				} else {
					vm.isFastSearch = false
				}
				var params={
					executeStartTime: vm.isFastSearch ? '' : __days[0].date+'-'+__days[0].day+' 00:00:00',//日历开始时间（格式：yyyy-MM-dd HH:mm:ss）
					executeEndTime: vm.isFastSearch ? '' : (__days.concat()).pop().date+'-'+lastDay+' 23:59:59',//日历结束时间（格式：yyyy-MM-dd HH:mm:ss）
					planId:vm.planId,//计划id
					searchTask:vm.searchTask,//快速查找任务：（1、我的任务，2、健康教育，3、健康指导，4、随访）
					status:vm.status,//任务状态（0未完成，1已完成，2已预约）
				}
				rehaAPI.calendarPlanDetail(params).then(function(res){
					vm.curTask=vm.searchTask;
					vm.curTaskName=vm.searchTaskName;
					vm.calendarData=[];
					var list = [];
					if(res.status==200){
						var data=res.data
						// 快速查找
						if(vm.isFastSearch) {
							vm.searchData = []
							var searchData0 = [],
								searchData1 = [],
								searchData2 = [];
							for(var setM = 1; setM <= 12; setM++) {
								var _setM = setM > 9 ? setM : '0' + setM,
									_setY = new Date().getFullYear();
								var data0 = [],
									data1 = [],
									data2 = [];
								for(var i in data) {
									var getY = i.split("-")[0],
										getM = i.split("-")[1],
										getD = i.split("-")[2];
									// 去年
									if(_setY - 1 == getY && _setM == getM) {
										var item = vm.planHandleData(data[i], getD, getM)
										data0.push(item)
										data.length && data.splice(i,1);
									} else if(_setY == getY && _setM == getM) { // 今年
										var item = vm.planHandleData(data[i], getD, getM)
										data1.push(item)
										data.length && data.splice(i,1);
									} else if(_setY + 1 == getY && _setM == getM) { // 明年
										var item = vm.planHandleData(data[i], getD, getM)
										data2.push(item)
										data.length && data.splice(i,1);
									}
								}
								if(data0.length) {
									var dataSort = vm.daysSort(data0)
									var addlen = (dataSort.length + 1) % 7 ? (dataSort.length + 1) % 7 : 7
									for(var i = 0; i < 7 - addlen; i++) {
										dataSort.push({
											noService:true
										})	
									}
									searchData0.push(dataSort)
								}
								if(data1.length) {
									var dataSort = vm.daysSort(data1)
									var addlen = (dataSort.length + 1) % 7 ? (dataSort.length + 1) % 7 : 7
									for(var i = 0; i < 7 - addlen; i++) {
										dataSort.push({
											noService:true
										})	
									}
									searchData1.push(dataSort)
								}
								if(data2.length) {
									var dataSort = vm.daysSort(data2)
									var addlen = (dataSort.length + 1) % 7 ? (dataSort.length + 1) % 7 : 7
									for(var i = 0; i < 7 - addlen; i++) {
										dataSort.push({
											noService:true
										})	
									}
									searchData2.push(dataSort)
								}
							}
							if(searchData0.length) {vm.searchData.push(searchData0)}
							if(searchData1.length) {vm.searchData.push(searchData1)}
							if(searchData2.length) {vm.searchData.push(searchData2)}
							return false;
						}
						// 正常日历
						var _currentTimeStamp=+new Date(new Date().setHours(0, 0, 0, 0));
						for(var i in __days){
							var _key=__days[i].date+'-'+(__days[i].day>9?__days[i].day:'0'+__days[i].day);
							var item={
									noService:true,
									day:__days[i].day
								};
							for(var j in data){
								if(_key==j){
									item = vm.planHandleData(data[j], __days[i].day)
									data.length && data.splice(j,1);
									break;
								}
							}
							var thatTime=+new Date(_key)-8*60*60*1000;
							var future=_currentTimeStamp>thatTime?0:(_currentTimeStamp==thatTime?1:2);
							item.future=future;
							list.push(item);
//							vm.calendarData.push(item);
						}
						vm.calendarData = _.chunk(list, 7)
					}
				})
			},
//						时间轴请求
			timeAxis:function(){
				var m_days=new Array(31,(28+this.is_leap(this.ynow)),31,30,31,30,31,31,30,31,30,31);  //每个月的天数
				var c_days=m_days[this.mnow];//当前月份的天数
				var __ym=this.ynow+'-'+(this.mnow>=9?"":"0")+(this.mnow+1);
				var dataArr=[];//天数/年月
				for(;c_days>0;c_days--){
					dataArr.push({
			        	day:c_days,
			        	date:__ym
			        });
				}
				this.__xData=dataArr;
				this.monDetail();
				this.calendarPlanDetailList();
			},
//						时间轴请求
			calendarPlanDetailList:function(){
				var vm=this;
				var __days=vm.__xData;
				var lastDay=(__days.concat()).pop().day;
				lastDay=lastDay>9?lastDay:'0'+lastDay;
				var params={
					executeEndTime:__days[0].date+'-'+__days[0].day+' 00:00:00',//日历开始时间（格式：yyyy-MM-dd HH:mm:ss）
					executeStartTime:(__days.concat()).pop().date+'-'+lastDay+' 23:59:59',//日历结束时间（格式：yyyy-MM-dd HH:mm:ss）
					planId:vm.planId,//计划id
					searchTask:vm.searchTask,//快速查找任务：（1、我的任务，2、随访，3、复诊，4、健康教育）
					status:vm.status,//任务状态（0未完成，1已完成，2已预约）
				}
				rehaAPI.calendarPlanDetailList(params).then(function(res){
					if(res.status==200){
						var _currentTimeStamp=+new Date(new Date().setHours(0, 0, 0, 0))
						vm.timeAxisData=_.map(res.data||{},function(o){
							var _time=o.executeTime.split(' ');
							var thatTime=+new Date(_time[0]);
							var future=_currentTimeStamp>thatTime?0:(_currentTimeStamp==thatTime?1:2);
							(o.status==0 && _currentTimeStamp>thatTime) && (future=-1)
							var _html=o.status==2?'预':(future==-1?'逾':'');
							_html=future==1?'今':_html;
							if(_html=='预') future=3;
							o.html=_html
							o.date=_time[0];
							o.time=_time[1];
							o.future=future;
							return o;
						})||[];
					}
				})
			},
			changeSearch: function(status) {
				var i = status == 1 ? -400 : 0;
				var timer1 = setInterval(function() {
					i += (5 * status)
					$(".search-left").css("right", i + "px")
					if(status == 1 && i >= 0) {
						clearInterval(timer1)
					}
					if(status == -1 && i <= -400) {
						clearInterval(timer1)
					}
				}, 5)
			},
			//邀请视频聊天
			openVideoChat: function(otherDoc){
				var vm = this;
				var loading = layer.load(0);

				var participants = []
				var participantsMobile = {}
				var docInfo = JSON.parse(localStorage.docInfo);

				//发起人
				participants.push({mobile: docInfo.mobile, name: docInfo.name, sex: docInfo.sex==1? 1 : 2, birthdate: "", level: 3, hospital_name: docInfo.hospitalName, idcard: ""});
				participantsMobile[docInfo.mobile] = 1;
				
				if(otherDoc){
					//被邀请人
					participants.push({
						mobile: otherDoc.doctorMobile, 
						name: otherDoc.doctorName, 
						sex: otherDoc.doctorSex==1? 1 : 2,
						birthdate: "", 
						level: 3, 
						hospital_name: otherDoc.doctorHospitalName, 
						idcard: otherDoc.doctorIdcard})
					participantsMobile[otherDoc.doctorMobile] = 0;
				}
				
				videoChatAPI.addDoctor({participants : JSON.stringify(participants)}).then(function(res){
				 	if(res.status == 200){
			            videoChatAPI.sessions({
			            	sessionId: httpRequest.uuid(24, 16),
			            	sessionType: 4,
			            	sessionName: vm.planInfo.patientName +"的远程门诊",
			            	participants: JSON.stringify(participantsMobile),
			            	videoconferencing: 1,
			            	idcard: vm.planInfo.idcard
			            }).then(function(res1){
			            	layer.close(loading)
			            	if(res1.status == 200){
			            		layer.msg("发起会话成功",{icon:6});
			            	} else{
			            		layer.msg("发起会话失败",{icon:5});
			            	}
			            }).catch(function(){
							layer.close(loading)
							layer.msg("系统繁忙",{icon:5});
						})
			        }else{
			        	layer.close(loading)
			        	layer.msg(res.msg,{icon:5});
			        }
				}).catch(function(){
					layer.close(loading)
					layer.msg("系统繁忙",{icon:5});
				})

			}
		
		},
		watch:{
			tabStatus:function(){
				this.goToLoadData();
			}
		}
	})
}();