|
62 | 62 | <script> |
63 | 63 | import { ref, reactive, toRaw } from 'vue' |
64 | 64 | // import moment from 'moment' |
| 65 | +import dayjs from 'dayjs' |
65 | 66 |
|
66 | 67 | export default { |
67 | 68 | name: 'DateTimeFilter', |
@@ -97,27 +98,40 @@ export default { |
97 | 98 | submitButtonLabel: this.$t('label.ok') |
98 | 99 | } |
99 | 100 | }, |
100 | | - updated () { |
101 | | - this.form.startDate = this.startDate |
102 | | - this.form.endDate = this.endDate |
103 | | - }, |
104 | 101 | created () { |
105 | 102 | this.initForm() |
106 | 103 | }, |
| 104 | + watch: { |
| 105 | + startDateProp (newVal) { |
| 106 | + this.form.startDate = newVal ? dayjs(newVal) : null |
| 107 | + }, |
| 108 | + endDateProp (newVal) { |
| 109 | + this.form.endDate = newVal ? dayjs(newVal) : null |
| 110 | + } |
| 111 | + }, |
107 | 112 | methods: { |
108 | 113 | initForm () { |
109 | 114 | this.formRef = ref() |
| 115 | + // Use dayjs instead of moment - Ant Design Vue requires dayjs |
| 116 | + const startDate = this.startDateProp ? dayjs(this.startDateProp) : null |
| 117 | + const endDate = this.endDateProp ? dayjs(this.endDateProp) : null |
| 118 | +
|
110 | 119 | this.form = reactive({ |
111 | | - startDate: this.startDate, |
112 | | - endDate: this.endDate |
| 120 | + startDate: startDate, |
| 121 | + endDate: endDate |
113 | 122 | }) |
114 | 123 | }, |
115 | 124 | handleSubmit (e) { |
116 | 125 | e.preventDefault() |
117 | 126 | this.formRef.value.validate().then(() => { |
118 | 127 | this.submitButtonLabel = this.$t('label.refresh') |
119 | 128 | const values = toRaw(this.form) |
120 | | - this.$emit('onSubmit', values) |
| 129 | + // Convert dayjs objects back to JavaScript Date objects |
| 130 | + const result = { |
| 131 | + startDate: values.startDate ? values.startDate.toDate() : null, |
| 132 | + endDate: values.endDate ? values.endDate.toDate() : null |
| 133 | + } |
| 134 | + this.$emit('onSubmit', result) |
121 | 135 | }).catch(error => { |
122 | 136 | this.formRef.value.scrollToField(error.errorFields[0].name) |
123 | 137 | }) |
|
0 commit comments