<template>
    <div>
        <a-range-picker
                format="YYYY-MM-DD"
                value-format="YYYY-MM-DD"
                v-model="dateInner"
                :ranges="ranges"
        />
    </div>
</template>

<script>
    import moment from 'moment';

    export default {
        name: "dateRangePicker",
        props: {
            date: {
                type: Array,
            }
        },
        created() {
            let ranges = {
                '今天': [moment(), moment()],
                '近一周':  [moment().add(-7,'day'), moment()],
                '近一月': [moment().add(-1,'month'), moment()],
                '近三个月': [moment().add(-3, 'month'), moment()],
                '近半年': [moment().add(-6, 'month'), moment()],
                '近一年': [moment().add(-1, 'year'), moment()],
            }
            this.ranges=ranges;
        },
        data() {
            return {
                dateInner: this.date,
                ranges: {}
            };
        },
        watch: {
            dateInner(val) {
                this.$emit('update:date', val)
            },
            date(val) {
                this.dateInner = val
            }
        },
        methods: {
            moment,
        }
    }
</script>

<style scoped>

</style>
