1. 程式人生 > >ios風格的時間選擇外掛

ios風格的時間選擇外掛

initBasicData(){

	for(let i=1900; i<=2100; i++){
		this.years.push(i+'年');
	}

	for(let i=0; i<60; i++){
		if(i>0 && i<=12){
			this.monthes.push(String(i).padStart(2,'0')+'月');
		}
		if(i>0 && i<=31){
			this.days.push(String(i).padStart(2,'0')+'日');
		}
		if(i<24){
			this.hours.push(String(i).padStart(2,'0')+'時');
		}
		this.minutes.push(String(i).padStart(2,'0')+'分');
	}
	// 當type=date並且有預設值時
	if(this.type == 'date' && this.datex){
		let y = new Date(this.datex).getFullYear();
		let m = new Date(this.datex).getMonth();
		let d = new Date(this.datex).getDate();
		this.timerSelectIndex = [y-1900, m, d-1];
	// 當type=datetime並且有預設值
	}else if(this.type == 'datetime' && this.datetimex){
		let y  = new Date(this.datetimex).getFullYear();
		let m  = new Date(this.datetimex).getMonth();
		let d  = new Date(this.datetimex).getDate();
		let h  = new Date(this.datetimex).getHours();
		let min= new Date(this.datetimex).getMinutes();
		this.timerSelectIndex = [y-1900, m, d-1, h, min];
	// 當type=time並且有預設值
	}else if(this.type == 'time' && this.timex){
		let h  = Number(this.timex.split(':')[0]);
		let min= Number(this.timex.split(':')[1]);
		this.timerSelectIndex = [h, min];
	}else{
		// 當沒有預設值的時候
		this.timerSelectIndex = [0,0,0,0,0];
	}
},
initTimeList(){
	if(this.type == 'datetime'){
		this.timeList.push(this.years);
		this.timeList.push(this.monthes);
		this.timeList.push(this.days);
		this.timeList.push(this.hours);
		this.timeList.push(this.minutes);
	}else if(this.type == 'time'){
		this.timeList.push(this.hours);
		this.timeList.push(this.minutes);
	}else {
		this.timeList.push(this.years);
		this.timeList.push(this.monthes);
		this.timeList.push(this.days);
	}
},