<template>
	<view class="content">
		<picker mode="date" :value="valueDate" :start="startDate" :end="endDate" @change="bindDateChange">
			<view class="uni-input">{{valueDate}}</view>
		</picker>
	</view>
</template>

<script>
	export default {
		name: 'mouldDate',
		props: {
			bankList: {
				type: Array,
				default: () => {
					return []
				}
			},
			valueDate: {
				type	: String,
				default : ''
			}
		},
		data(){
			const currentDate = this.getDate({
				format: true
			})
			return {}
		},
		computed: {
			startDate() {
				return this.getDate('start');
			},
			endDate() {
				return this.getDate('end');
			}
		},
		methods: {
			bindDateChange(e){
				this.$emit('onDate', e.detail.value)
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
				
				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
		}
	}
</script>

<style>
</style>