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
AmAttachmentFormField.vue
141 lines
| 1 | <template> |
| 2 | <el-form-item |
| 3 | v-if="props.isUpload" |
| 4 | :id="props.id" |
| 5 | ref="formFieldRef" |
| 6 | class="am-ff__item" |
| 7 | :prop="props.itemName" |
| 8 | :label-position="props.labelPosition" |
| 9 | > |
| 10 | <template #label> |
| 11 | <span class="am-ff__item-label" v-html="props.label" /> |
| 12 | </template> |
| 13 | <AmAttachment |
| 14 | :id="props.id" |
| 15 | v-model="model" |
| 16 | :auto-upload="false" |
| 17 | :accept="customFieldsAllowedExtensions" |
| 18 | @change="onAddFile" |
| 19 | @remove="onRemoveFile" |
| 20 | > |
| 21 | {{ props.btnLabel }} |
| 22 | </AmAttachment> |
| 23 | </el-form-item> |
| 24 | <div v-else> |
| 25 | <p v-for="(fileInfo, index) in props.modelValue" :key="index"> |
| 26 | <a |
| 27 | :key="index" |
| 28 | :href=" |
| 29 | ajaxUrl + |
| 30 | '/fields/' + |
| 31 | props.id + |
| 32 | '/' + |
| 33 | props.bookingId + |
| 34 | '/' + |
| 35 | index + |
| 36 | '&source=' + |
| 37 | props.source |
| 38 | " |
| 39 | target="_blank" |
| 40 | > |
| 41 | {{ fileInfo.name }} |
| 42 | </a> |
| 43 | </p> |
| 44 | </div> |
| 45 | </template> |
| 46 | |
| 47 | <script setup> |
| 48 | // * _components |
| 49 | import AmAttachment from '../../_components/attachment/AmAttachment.vue' |
| 50 | |
| 51 | // * Import from Vue |
| 52 | import { computed, onMounted, ref, toRefs } from 'vue' |
| 53 | import { settings } from '../../../plugins/settings' |
| 54 | |
| 55 | // * Import from Vuex |
| 56 | import { useStore } from 'vuex' |
| 57 | |
| 58 | // * Form Item Props |
| 59 | let props = defineProps({ |
| 60 | modelValue: { |
| 61 | type: [String, Array, Object, Number], |
| 62 | required: true, |
| 63 | }, |
| 64 | id: { |
| 65 | type: [String, Number], |
| 66 | }, |
| 67 | bookingId: { |
| 68 | type: [String, Number], |
| 69 | }, |
| 70 | itemName: { |
| 71 | type: String, |
| 72 | required: true, |
| 73 | }, |
| 74 | isUpload: { |
| 75 | type: Boolean, |
| 76 | default: true, |
| 77 | }, |
| 78 | label: { |
| 79 | type: String, |
| 80 | }, |
| 81 | labelPosition: { |
| 82 | type: String, |
| 83 | default: 'top', |
| 84 | }, |
| 85 | btnLabel: { |
| 86 | type: String, |
| 87 | }, |
| 88 | source: { |
| 89 | type: String, |
| 90 | default: 'cabinet-provider', |
| 91 | }, |
| 92 | }) |
| 93 | |
| 94 | // * Define Emits |
| 95 | const emits = defineEmits(['update:modelValue', 'change', 'remove']) |
| 96 | |
| 97 | const store = useStore() |
| 98 | |
| 99 | let ajaxUrl = computed(() => store.getters['getBaseUrls'].wpAmeliaPluginAjaxURL) |
| 100 | |
| 101 | // * Component model |
| 102 | let { modelValue } = toRefs(props) |
| 103 | let model = computed({ |
| 104 | get: () => modelValue.value, |
| 105 | set: (val) => { |
| 106 | emits('update:modelValue', val) |
| 107 | }, |
| 108 | }) |
| 109 | |
| 110 | // * Form Item Reference |
| 111 | let formFieldRef = ref(null) |
| 112 | |
| 113 | defineExpose({ |
| 114 | formFieldRef, |
| 115 | }) |
| 116 | |
| 117 | let customFieldsAllowedExtensions = ref('') |
| 118 | |
| 119 | onMounted(() => { |
| 120 | if (settings.general.customFieldsAllowedExtensions) { |
| 121 | customFieldsAllowedExtensions.value = Object.keys( |
| 122 | settings.general.customFieldsAllowedExtensions, |
| 123 | ).join(', ') |
| 124 | } |
| 125 | }) |
| 126 | |
| 127 | function onAddFile(a) { |
| 128 | emits('update:modelValue', a.raw) |
| 129 | } |
| 130 | |
| 131 | function onRemoveFile(a) { |
| 132 | emits('update:modelValue', a.raw) |
| 133 | } |
| 134 | </script> |
| 135 | |
| 136 | <script> |
| 137 | export default { |
| 138 | name: 'AttachmentFormField', |
| 139 | } |
| 140 | </script> |
| 141 |