<template>
	<view style="height: 100vh;">
		<calendar ref="calendar" 
		v-if="show"
		:startDate="StartTime"
		:height="height"
		:endDate="EndTime"
		@selectDate="selectDate"
		:limit="limit" />
	</view>
</template>

<script>
	import calendar from './fl-calendar.vue'
	export default{
		components:{
			calendar
		},
		data(){
			return{
				pageTitle: "日期选择",
				contentHeight: 0,
				height:500, //日历容器高度
				limit:36,
				StartTime:'',
				EndTime:'',
				show:false,
			}
		},
		created() {
			this.height = this.$utils.calcContentHeight(-40) ;
			uni.setNavigationBarTitle({
				title: this.pageTitle,
			});
		},
		onLoad(options) {
			if(options){
				this.StartTime = options.StartTime
				this.EndTime = options.EndTime
				setTimeout(()=>{
					this.show = true
				},100)
			}
		},
		methods:{
			selectDate(data){
				console.log(data)
				if(data.dayNum>31){
					uni.showToast({
					    title: '时间不能超过31天',
						icon:'none',
					    duration: 2000
					});
				}else{
					if(new Date(data.startDate).getTime() < new Date(data.endDate).getTime()){
						let pages = getCurrentPages(); // 当前页面
						let beforePage = pages[pages.length - 2]; // 前一个页面
						let that = this
						setTimeout(()=>{
							 uni.navigateBack({
								 success: function() {
									 beforePage.$vm.children(data.startDate,data.endDate); // 执行前一个页面的方法
								 }
							 });
						},500)
					}else{
						uni.showToast({
						    title: '开始时间小于结束时间',
							icon:'none',
						    duration: 2000
						});
					}
					
					
				}
			}
		}
	}
</script>

<style>
</style>
