!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:[],//当前的年月(时间轴)
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'],
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:[]
},
mounted:function(){
if(!this.planId){
layer.msg('未传入计划id(planId)',{icon:2})
}else{
this.tabStatus=1;
}
this.planSchedule();
this.serviceDoctorList();//获取服务医生列表
this.bindEvents();
},
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+"&completePlan=true")
}
}else{
layer.msg(res.msg,{icon:5});
}
})
},
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)
},1000)
}else{
layer.msg(res.msg,{icon:5});
}
})
},
setImgSrc: function (src) {
var str = httpRequest.getImgUrl(src)
return str
},
showCompleteDailog:function(){
layer.confirm('
', {
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();
})
},
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();
},
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;ic_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();
},
// 日历请求
calenderPlanDetail:function(){
var vm=this;
var __days=vm.__Data;
var lastDay=(__days.concat()).pop().day;
lastDay=lastDay>9?lastDay:'0'+lastDay;
var params={
executeStartTime:__days[0].date+'-'+__days[0].day+' 00:00:00',//日历开始时间(格式:yyyy-MM-dd HH:mm:ss)
executeEndTime:(__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
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=data[j];
item.day=__days[i].day;
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;
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;
})||[];
}
console.log(vm.timeAxisData)
})
},
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)
}
},
watch:{
tabStatus:function(){
this.goToLoadData();
}
}
})
}();