|
|
|
import util from '../../../utils/util';
|
|
|
|
import App from '../../../utils/api';
|
|
|
|
Component({
|
|
|
|
properties:{
|
|
|
|
seller:Object,
|
|
|
|
//选中日期
|
|
|
|
date:{
|
|
|
|
type:String,
|
|
|
|
value:util.unixtoTime(new Date()/1000,'YYYY-MM-DD'),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data:{
|
|
|
|
hidecalendar:true
|
|
|
|
},
|
|
|
|
attached(){
|
|
|
|
this.today=util.unixtoTime(new Date()/1000,'YYYY-MM-DD');
|
|
|
|
this.setData({
|
|
|
|
showYearMonth:this.getshowmonth(this.data.date)
|
|
|
|
})
|
|
|
|
this.hasNowInToday();
|
|
|
|
this.getweeklist();
|
|
|
|
this.getdaylist();
|
|
|
|
this.getFullDate();
|
|
|
|
},
|
|
|
|
ready(){
|
|
|
|
|
|
|
|
},
|
|
|
|
methods:{
|
|
|
|
//判断是否过了今天时段,并设置date
|
|
|
|
hasNowInToday(){
|
|
|
|
let daily=this.data.seller.daily
|
|
|
|
let maxDur='';
|
|
|
|
Object.keys(daily).forEach(k=>{
|
|
|
|
let dur=daily[k].split('-')
|
|
|
|
if(dur[1]>maxDur){
|
|
|
|
maxDur=dur[1]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
let nowDur=util.unixtoTime(new Date()/1000,'HH:II')
|
|
|
|
let nowDate=this.data.date
|
|
|
|
if(nowDur>maxDur){
|
|
|
|
nowDate=util.unixtoTime(new Date()/1000+86400,'YYYY-MM-DD')
|
|
|
|
this.setData({
|
|
|
|
date:nowDate
|
|
|
|
})
|
|
|
|
}
|
|
|
|
//console.log('hasNowInToday',maxDur)
|
|
|
|
this.triggerEvent('selectdate',{date:nowDate,action:'defalut'})
|
|
|
|
},
|
|
|
|
//获取当前选中日期年月
|
|
|
|
getshowmonth(selecteddate){
|
|
|
|
let datearr=selecteddate.split('-');
|
|
|
|
return{
|
|
|
|
showyear:Number(datearr[0]),
|
|
|
|
showmonth:Number(datearr[1]),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
//获得周列表
|
|
|
|
getweeklist(){
|
|
|
|
let week=['日','一','二','三','四','五','六'];
|
|
|
|
let weeklist=[];
|
|
|
|
for(let i=0;i<week.length;i++){
|
|
|
|
weeklist.push({
|
|
|
|
weekfont:week[i],
|
|
|
|
weeknum:i
|
|
|
|
})
|
|
|
|
}
|
|
|
|
this.setData({
|
|
|
|
weeklist:weeklist,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
//获取日期列表
|
|
|
|
getdaylist(){
|
|
|
|
//选中时间时间戳
|
|
|
|
let selectedtime=Number(util.timetouUnix(this.data.date+' 00:00:00'));
|
|
|
|
//选中日期星期几
|
|
|
|
let selectedweek=new Date(this.data.date).getDay();
|
|
|
|
console.log('selectedweek',selectedweek)
|
|
|
|
let daylist=[],current=0;
|
|
|
|
//用于月历点击的时候判断是否改变周历列表
|
|
|
|
this.datelist={}
|
|
|
|
if(this.data.date==this.today){
|
|
|
|
selectedweek=0;
|
|
|
|
}
|
|
|
|
for(let i=0;i<14;i++){
|
|
|
|
let thistimestamp=selectedtime+(i-selectedweek)*86400;
|
|
|
|
let thisdate=new Date(thistimestamp*1000);
|
|
|
|
let thisdayobj={
|
|
|
|
year:thisdate.getFullYear(),
|
|
|
|
month:thisdate.getMonth()+1,
|
|
|
|
day:thisdate.getDate(),
|
|
|
|
week:thisdate.getDay(),
|
|
|
|
date:util.unixtoTime(thistimestamp,'YYYY-MM-DD'),
|
|
|
|
overdate:thistimestamp<=(new Date()/1000)-86400 ? true : false, //日期是否过期
|
|
|
|
istoday:false,
|
|
|
|
timestamp:thistimestamp,
|
|
|
|
}
|
|
|
|
//是否是今天
|
|
|
|
if(this.today==thisdayobj.date){
|
|
|
|
thisdayobj.istoday=true;
|
|
|
|
thisdayobj.mark='今'
|
|
|
|
}
|
|
|
|
if(util.unixtoTime(new Date()/1000+86400,'YYYY-MM-DD')==thisdayobj.date){
|
|
|
|
thisdayobj.mark='明'
|
|
|
|
}
|
|
|
|
thisdayobj.isselected=false
|
|
|
|
if(this.data.date==thisdayobj.date){
|
|
|
|
thisdayobj.isselected=true
|
|
|
|
current=i
|
|
|
|
}
|
|
|
|
thisdayobj.isselected=this.data.date==thisdayobj.date ? true : false;
|
|
|
|
//日期是否选中
|
|
|
|
daylist.push(thisdayobj);
|
|
|
|
this.datelist[thisdayobj.date]=Math.floor(i/7)+'-'+(i-Math.floor(i/7)*7)
|
|
|
|
}
|
|
|
|
this.setData({
|
|
|
|
current:this.getCurrentMax(current),
|
|
|
|
daylist:daylist
|
|
|
|
})
|
|
|
|
console.log('getdaylist.daylist',daylist,this.datelist)
|
|
|
|
},
|
|
|
|
//获取满房日期
|
|
|
|
getFullDate(){
|
|
|
|
let parmdata={
|
|
|
|
sid:this.data.seller.id,
|
|
|
|
type:'week',
|
|
|
|
date:this.data.daylist[0].date
|
|
|
|
}
|
|
|
|
App.Customer.GetHouseFullDate(parmdata).then((json)=>{
|
|
|
|
console.log(json)
|
|
|
|
if(json.ret==200){
|
|
|
|
if(json.data && json.data.length>0){
|
|
|
|
this.markFullHouse(json.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
//标记满房
|
|
|
|
markFullHouse(fullHouseDate){
|
|
|
|
let daylist=this.data.daylist;
|
|
|
|
daylist.forEach((r,i)=>{
|
|
|
|
fullHouseDate.forEach((r1,n1)=>{
|
|
|
|
if(r1==r.date){
|
|
|
|
r.mark='满'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
console.log('markFullHouse.daylist',daylist)
|
|
|
|
this.setData({
|
|
|
|
daylist:daylist
|
|
|
|
})
|
|
|
|
},
|
|
|
|
//选择日期
|
|
|
|
selectdate(e){
|
|
|
|
let _target=e.currentTarget.dataset;
|
|
|
|
this.changedatestyle(_target.date);
|
|
|
|
this.triggerEvent('selectdate',{date:_target.date,action:'click'});
|
|
|
|
this.setData({
|
|
|
|
date:_target.date,
|
|
|
|
showYearMonth:this.getshowmonth(_target.date),
|
|
|
|
current:this.getCurrentMax(_target.index-(_target.date==this.today?0:1)),
|
|
|
|
})
|
|
|
|
},
|
|
|
|
//日历组件---通知事件
|
|
|
|
tellselectdate(e){
|
|
|
|
console.log(e)
|
|
|
|
let _target=e.detail;
|
|
|
|
this.triggerEvent('selectdate',{date:_target.date,action:'click'});
|
|
|
|
this.setData({
|
|
|
|
date:_target.date,
|
|
|
|
showYearMonth:this.getshowmonth(_target.date),
|
|
|
|
hidecalendar:true
|
|
|
|
})
|
|
|
|
console.log('tellselectdate',_target.date , this.datelist,_target.date in this.datelist)
|
|
|
|
if(_target.date in this.datelist){
|
|
|
|
this.changedatestyle(_target.date)
|
|
|
|
}else{
|
|
|
|
this.getdaylist();
|
|
|
|
this.getFullDate();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
//修改日期列表
|
|
|
|
changedatestyle(selecteddate){
|
|
|
|
let daylist=this.data.daylist;
|
|
|
|
let prevsingle,previndex,cursingle,curindex;
|
|
|
|
daylist.forEach((r,i)=>{
|
|
|
|
if(r.isselected){
|
|
|
|
prevsingle=i;
|
|
|
|
let prevkey='daylist['+prevsingle+'].isselected';
|
|
|
|
this.setData({
|
|
|
|
[prevkey]:false,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if(r.date==selecteddate){
|
|
|
|
cursingle=i;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
let currentkey='daylist['+cursingle+'].isselected';
|
|
|
|
this.setData({
|
|
|
|
[currentkey]:true,
|
|
|
|
current:this.getCurrentMax(cursingle-(selecteddate==this.today?0:1)),
|
|
|
|
})
|
|
|
|
},
|
|
|
|
clickmore(){
|
|
|
|
this.setData({
|
|
|
|
hidecalendar:false
|
|
|
|
})
|
|
|
|
},
|
|
|
|
getCurrentMax(current){
|
|
|
|
return current>10?10:current;
|
|
|
|
},
|
|
|
|
closecalendar(){
|
|
|
|
this.setData({
|
|
|
|
hidecalendar:true
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}) |
|
|
\ No newline at end of file |
...
|
...
|
|