AmAddressFormField.vue
1 month ago
AmAttachmentFormField.vue
1 month ago
AmCheckboxFormField.vue
1 month ago
AmContentFormField.vue
1 month ago
AmDatePickerFormField.vue
1 month ago
AmInputFormField.vue
1 month ago
AmPhoneFormField.vue
1 month ago
AmRadioFormField.vue
1 month ago
AmSelectFormField.vue
1 month ago
AmSocialButton.vue
1 month ago
AmDatePickerFormField.vue
112 lines
| 1 | <template> |
| 2 | <el-form-item |
| 3 | ref="formFieldRef" |
| 4 | class="am-ff__item" |
| 5 | :prop="props.itemName" |
| 6 | :label-position="props.labelPosition" |
| 7 | > |
| 8 | <template #label> |
| 9 | <span class="am-ff__item-label" v-html="props.label" /> |
| 10 | </template> |
| 11 | <AmDatePickerFull |
| 12 | :existing-date="model" |
| 13 | :persistent="false" |
| 14 | :disabled="false" |
| 15 | :clearable="props.clearable" |
| 16 | :readonly="props.readonly" |
| 17 | :week-starts-from-day="props.weekStartsFromDay" |
| 18 | :input-placeholder="props.placeholder" |
| 19 | :refresh-value="props.refreshValue" |
| 20 | @selected-date=" |
| 21 | (dateString) => { |
| 22 | selectedDatePickerValue(dateString) |
| 23 | } |
| 24 | " |
| 25 | @clear-date="clearDate" |
| 26 | /> |
| 27 | </el-form-item> |
| 28 | </template> |
| 29 | |
| 30 | <script setup> |
| 31 | // * _components |
| 32 | import AmDatePickerFull from '../../_components/date-picker-full/AmDatePickerFull.vue' |
| 33 | |
| 34 | // * Import from Vue |
| 35 | import { computed, ref, toRefs } from 'vue' |
| 36 | |
| 37 | // * Moment |
| 38 | import moment from 'moment' |
| 39 | |
| 40 | // * Form Item Props |
| 41 | let props = defineProps({ |
| 42 | modelValue: { |
| 43 | type: [String, Array, Object, Number], |
| 44 | required: true, |
| 45 | }, |
| 46 | itemName: { |
| 47 | type: String, |
| 48 | required: true, |
| 49 | }, |
| 50 | label: { |
| 51 | type: String, |
| 52 | }, |
| 53 | labelPosition: { |
| 54 | type: String, |
| 55 | default: 'top', |
| 56 | }, |
| 57 | weekStartsFromDay: { |
| 58 | type: [String, Number], |
| 59 | default: 1, |
| 60 | }, |
| 61 | placeholder: { |
| 62 | type: String, |
| 63 | default: '', |
| 64 | }, |
| 65 | clearable: { |
| 66 | type: Boolean, |
| 67 | default: false, |
| 68 | }, |
| 69 | readonly: { |
| 70 | type: Boolean, |
| 71 | default: true, |
| 72 | }, |
| 73 | refreshValue: { |
| 74 | type: Boolean, |
| 75 | default: false, |
| 76 | }, |
| 77 | }) |
| 78 | |
| 79 | // * Define Emits |
| 80 | const emits = defineEmits(['update:modelValue']) |
| 81 | |
| 82 | // * Component model |
| 83 | let { modelValue } = toRefs(props) |
| 84 | let model = computed({ |
| 85 | get: () => modelValue.value, |
| 86 | set: (val) => { |
| 87 | emits('update:modelValue', val) |
| 88 | }, |
| 89 | }) |
| 90 | |
| 91 | // * Form Item Reference |
| 92 | let formFieldRef = ref(null) |
| 93 | |
| 94 | defineExpose({ |
| 95 | formFieldRef, |
| 96 | }) |
| 97 | |
| 98 | function selectedDatePickerValue(dateString) { |
| 99 | emits('update:modelValue', moment(dateString, 'YYYY-MM-DD').toDate()) |
| 100 | } |
| 101 | |
| 102 | function clearDate() { |
| 103 | emits('update:modelValue', '') |
| 104 | } |
| 105 | </script> |
| 106 | |
| 107 | <script> |
| 108 | export default { |
| 109 | name: 'DatePickerFormField', |
| 110 | } |
| 111 | </script> |
| 112 |