const onOpenChange = (open: boolean) => {
if (open) {
setDates([null, null]);
} else {
setDates(null);
}
};
const onPanelChange = (value: any, mode: any) => {
setQuarter(value)
run({ datetype: valueRadio, times: mode, business_line: ctxlint.line })
}
<RangePicker
picker="quarter"
size="small"
allowClear={false}
value={dates || quarter}
disabledDate={disabledQuarter}
onChange={(value, mode) => onPanelChange(value, mode)}
onCalendarChange={val => setDates(val)}
onOpenChange={onOpenChange}
bordered={false}
format='YYYY-[Q]Q'
style={{width: '200px', marginRight: '30px'}}
/>
const disabledQuarter: RangePickerProps['disabledDate'] = current => {
if (!dates) {
return current && current < moment([2021]) || current > moment().endOf('quarter');
}
const tooLate = dates[0] && current.diff(dates[0], 'quarter') > 3 || (current && current < moment([2021]) || current > moment().endOf('quarter'));
const tooEarly = (current && current < moment([2021]) || current > moment().endOf('quarter')) || dates[1] && dates[1].diff(current, 'quarter') > 2;
return !!tooEarly || !!tooLate;
};
const disabledDate: RangePickerProps["disabledDate"] = (current) => {
if (!dates) {
return (
(current && current < moment([2021])) || current > moment().endOf("month")
);
}
const tooLate = (dates[0] && current.diff(dates[0], "month") > 10) || (current && current < moment([2021])) || current > moment(ctx.disEndTimes).endOf("month");
const tooEarly = (current && current < moment([2021])) || current > moment(ctx.disEndTimes).endOf("month") || (dates[1] && dates[1].diff(current, "month") > 10);
return !!tooEarly || !!tooLate;
};
const disabledQuarter: RangePickerProps["disabledDate"] = (current) => {
if (!dates) {
return (
(current && current < moment([2021])) ||
current > moment().endOf("quarter")
);
}
const tooLate =
(dates[0] && current.diff(dates[0], "quarter") > 11) ||
(current && current < moment([2021])) ||
current > moment().endOf("quarter");
const tooEarly =
(current && current < moment([2021])) ||
current > moment().endOf("quarter") ||
(dates[1] && dates[1].diff(current, "quarter") > 10);
return !!tooEarly || !!tooLate;
};
const disabledYear: RangePickerProps["disabledDate"] = (current) => {
return (
(current && current < moment([2021])) || current > moment().endOf("year")
);
};