美文网首页
按财年选择时间 当年 10 月 到 明年 9 月

按财年选择时间 当年 10 月 到 明年 9 月

作者: 我叫杨毅 | 来源:发表于2022-08-16 16:27 被阅读0次
        <el-date-picker
                        style=" width: auto;"
                        v-model="deliveryValue"
                        format="yyyy 年 MM 月 dd 日"
                        value-format="yyyy-MM-dd"
                        type="monthrange"
                        range-separator="至"
                        start-placeholder="开始月份"
                        end-placeholder="结束月份"
                        :picker-options="pickerOptions"
                        @change="deliveryDateStartAndEnd"
                    ></el-date-picker>
    data() {
        return {
            // 判断交付率 按财年选择 当年 10 月 到 明年 9 月
            choiceDate: '',
            pickerOptions: {
                onPick: ({ maxDate, minDate }) => {
                    this.choiceDate = minDate.getTime();
                    if (maxDate) {
                        this.choiceDate = '';
                    }
                },

                disabledDate: time => {
                    const self = this;
                    if (self.choiceDate) {
                        const selectDate = new Date(self.choiceDate);
                        const nowYear = selectDate.getFullYear(); // 当前年
                        const nowMonth = selectDate.getMonth(); // 当前月

                        if (nowMonth >= 9) {
                            // 本年的开始时间
                            const yearStartDate = new Date(nowYear, 10, 0).getTime();
                            // 本年的结束时间
                            const yearEndDate = new Date(nowYear + 1, 9, 0).getTime();
                            return time.getTime() < yearStartDate || time.getTime() > yearEndDate;
                        } else {
                            // 本年的开始时间
                            const yearStartDate = new Date(nowYear, 9, 0).getTime();
                            // 本年的结束时间
                            const yearEndDate = new Date(nowYear - 1, 10, 0).getTime();
                            return time.getTime() > yearStartDate || time.getTime() < yearEndDate;
                        }
                    }
                },
            },
      }
}

相关文章

网友评论

      本文标题:按财年选择时间 当年 10 月 到 明年 9 月

      本文链接:https://www.haomeiwen.com/subject/tjfdgrtx.html