// components/My_selectTime/index.js
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        /* 最小时间 */
        minDate: {
            type: Number,
            value: -284025600000, //1961.1.1
        },
        /* 最大选择时间 */
        maxDate: {
            type: Number,
            value: Date.parse(new Date()) //当前时间
        },
        /* 弹窗显示 */
        showSelectTime: {
            type: Boolean,
            value: false
        },
        /* 保存回调 */
        getTimeData: {
            type: Function,
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        currentDate: new Date().getTime(),
        formatter(type, value) {
            if (type === 'year') {
                return `${value}年`;
            }
            if (type === 'month') {
                return `${value}月`;
            }
            return value;
        },
    },

    /**
     * 组件的方法列表
     */
    methods: {
        submit() {
            const time = new Date(this.data.currentDate),
                setTime = time.getFullYear() + '-' + (time.getMonth() + 1) + "-" + time.getDate();
            this.triggerEvent("getTimeData", setTime)
            this.setData({
                showSelectTime: false
            })
        },
        onInput(event) {
            this.setData({
                currentDate: event.detail,
            });
        },
        dateOnClose() {
            this.setData({
                showSelectTime: !this.data.showSelectTime
            })
        },
    }
})