dur.js
2.68 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//获取当前时间
import App from '../../../utils/api';
import util from '../../../utils/util';
Component({
properties:{
seller:Object,
//时间段
time:{
type:String,
value:''
},
//日期
date:{
type:String,
value:util.unixtoTime(new Date()/1000,'YYYY-MM-DD')
}
},
data:{
current:0
},
attached(){
},
ready(){
},
observers: {
'date': function(newdate) {
if(newdate!=''){
this.getroombydate();
}
}
},
methods:{
selecttime(e){
const target=e.currentTarget.dataset;
this.triggerEvent('selecttime',{time:target.time,action:'click'})
},
//获得默认所有可订时间段
getdurlist(houseFull){
console.log(houseFull)
const date=new Date();
let currenttimemark=date.getHours()+date.getMinutes()/60;
let timedur=this.data.seller.daily;
let durlist=[];
for(let key in timedur){
if(timedur[key]!="" && houseFull[key]==0){ //有这个时间段,并且不满房
let arr=timedur[key].split('-');
//每个时段的开始时间、结束时间
let starttime=Number(arr[0].split(':')[0]);
let endtime=Number(arr[1].split(':')[0]);
if(util.unixtoTime(date/1000,'YYYY-MM-DD')==this.data.date){ //当天
if(currenttimemark+0.5<endtime){
if(currenttimemark+0.5>starttime){
starttime=Math.round(currenttimemark)+0.5;
}
let thisdurlist=this.getsinglelist(starttime,endtime)
durlist=durlist.concat(thisdurlist)
}
}else{
let thisdurlist=this.getsinglelist(starttime,endtime);
durlist=durlist.concat(thisdurlist)
}
}
}
let duritem=[];
for(let i=0;i<Math.ceil((durlist.length)/5);i++){
duritem.push({
list:[]
})
}
durlist.forEach((v,i)=>{
let thiscurrent=Math.floor(i/5);
duritem[thiscurrent].list.push(v)
})
this.setData({
durlist:duritem,
time:durlist.length>0 ? duritem[0].list[0].showdur : '',
current:0
})
this.triggerEvent('selecttime',{time:this.data.time,action:'defalut'})
},
//获取每个时段的时间列表
getsinglelist(starttime,endtime){
let singledurlist=[];
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'
}
singledurlist.push(obj)
}
return singledurlist;
},
//获取具体日期时间段满房状态
getroombydate(){
//参数:date:'2019-07-24' sid:1
let parmdata={
date:this.data.date,
sid:this.data.seller.id
}
App.Customer.GetHouseFullDateTimes(parmdata).then((json)=>{
console.log(json)
if(json.ret==200){
this.getdurlist(json.data);
}
})
},
}
})