dur.js
1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//获取当前时间
const date=new Date();
import App from '../../../utils/api';
Component({
properties:{
seller:Object,
//时间段
time:{
type:String,
value:''
},
//日期
date:{
type:String,
value:''
}
},
attached(){
this.getdurlist();
},
ready(){
//设置默认时间段
if(this.data.time==''){
this.setData({
time:this.data.durlist[0].showdur
})
}
//设置默认日期
if(this.data.date==''){
let currentmonth=date.getMonth()+1;
let currentdate=date.getDate();
this.setData({
date:date.getFullYear()+'-'+(currentmonth<10 ? '0'+currentmonth : currentmonth)+'-'+(currentdate<10 ? '0'+currentdate : currentdate)
})
}
this.triggerEvent('selecttime',{time:this.data.time,action:'defalut'})
},
methods:{
selecttime(e){
const target=e.currentTarget.dataset;
this.triggerEvent('selecttime',{time:target.time,action:'click'})
},
//获得默认所有可订时间段
getdurlist(){
let currenttimemark=date.getHours()+new Date().getMinutes()/60;
let timedur=this.data.seller.daily;
let durlist=[];
for(let key in timedur){
let arr=timedur[key].split('-');
//每个时段的开始时间、结束时间
let starttime=Number(arr[0].split(':')[0]);
let endtime=Number(arr[1].split(':')[0]);
if(currenttimemark+0.5<endtime){
if(currenttimemark+0.5>starttime){
starttime=Math.round(currenttimemark)+0.5;
}
for(let i=starttime;i<=endtime;i+=0.5){
let obj={};
if(i%1==0){
obj.showdur=i<10 ? '0'+i+':00' : i+':00'
}else{
obj.showdur=i<10 ? '0'+Math.floor(i)+':30' : Math.floor(i)+':30'
}
durlist.push(obj)
}
}
}
this.setData({
durlist:durlist
})
},
//获取具体日期时间段满房状态
getroombydate(){
//参数:date:'2019-07-24' sid:1
},
}
})