dur.js 1.82 KB
//获取当前时间
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
			
		},
	}
})