import { defineComponent, inject, nextTick } from 'vue'; import moment from 'moment'; import Calendar from '../vc-calendar'; import VcDatePicker from '../vc-calendar/src/Picker'; import CloseCircleFilled from '@ant-design/icons-vue/CloseCircleFilled'; import { defaultConfigProvider } from '../config-provider'; import { hasProp, getOptionProps, getComponent } from '../_util/props-util'; import classNames from '../_util/classNames'; import BaseMixin from '../_util/BaseMixin'; import { WeekPickerProps } from './props'; import interopDefault from '../_util/interopDefault'; import InputIcon from './InputIcon'; import { getDataAndAriaProps } from '../_util/util'; import initDefaultProps from '../_util/props-util/initDefaultProps'; function formatValue(value: moment.Moment | null, format: string): string { return (value && value.format(format)) || ''; } interface WeekPickerState { _open?: boolean; _value?: moment.Moment | null; } function noop() {} export default defineComponent({ name: 'AWeekPicker', mixins: [BaseMixin], inheritAttrs: false, props: initDefaultProps(WeekPickerProps, { allowClear: true, }), setup() { return { configProvider: inject('configProvider', defaultConfigProvider), prevState: {} as WeekPickerState, input: undefined, sPrefixCls: undefined, }; }, data(): WeekPickerState { const value: any = this.value || this.defaultValue; if (value && !interopDefault(moment).isMoment(value)) { throw new Error( 'The value/defaultValue of WeekPicker or MonthPicker must be ' + 'a moment object', ); } return { _value: value, _open: this.open, }; }, watch: { value(val) { const state = { _value: val }; this.setState(state); this.prevState = { ...this.$data, ...state }; }, open(val) { const state = { _open: val }; this.setState(state); this.prevState = { ...this.$data, ...state }; }, _open(val, oldVal) { nextTick(() => { if (!hasProp(this, 'open') && oldVal && !val) { this.focus(); } }); }, }, mounted() { this.prevState = { ...this.$data }; }, updated() { nextTick(() => { if (!hasProp(this, 'open') && this.prevState._open && !this._open) { this.focus(); } }); }, methods: { saveInput(node: any) { this.input = node; }, weekDateRender({ current }) { const selectedValue = this.$data._value; const { sPrefixCls: prefixCls, $slots } = this; const dateRender = this.dateRender || $slots.dateRender; const dateNode = dateRender ? dateRender({ current }) : current.date(); if ( selectedValue && current.year() === selectedValue.year() && current.week() === selectedValue.week() ) { return (