66 lines
1.6 KiB
Vue
66 lines
1.6 KiB
Vue
<script setup>
|
|
import { ref } from 'vue';
|
|
import { useI18n } from 'vue-i18n';
|
|
import { useRoute } from 'vue-router';
|
|
|
|
import VnSelect from 'src/components/common/VnSelect.vue';
|
|
import FormModelPopup from 'components/FormModelPopup.vue';
|
|
import FetchData from 'components/FetchData.vue';
|
|
import useNotify from 'src/composables/useNotify.js';
|
|
|
|
import axios from 'axios';
|
|
|
|
const emit = defineEmits(['onDataSaved']);
|
|
|
|
const { t } = useI18n();
|
|
const { notify } = useNotify();
|
|
const route = useRoute();
|
|
|
|
const dmsOptions = ref([]);
|
|
const dmsId = ref(null);
|
|
|
|
const importDms = async () => {
|
|
try {
|
|
if (!dmsId.value) throw new Error(t(`vehicle.errors.documentIdEmpty`));
|
|
|
|
const data = {
|
|
vehicleFk: route.params.id,
|
|
dmsFk: dmsId.value,
|
|
};
|
|
|
|
await axios.post('vehicleDms', data);
|
|
notify(t('globals.dataSaved'), 'positive');
|
|
dmsId.value = null;
|
|
emit('onDataSaved');
|
|
} catch (e) {
|
|
throw e;
|
|
}
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<FetchData
|
|
url="Dms"
|
|
:filter="{ fields: ['id'], order: 'id ASC' }"
|
|
auto-load
|
|
@on-fetch="(data) => (dmsOptions = data)"
|
|
/>
|
|
<FormModelPopup
|
|
model="DmsImport"
|
|
:title="t('globals.selectDocumentId')"
|
|
:form-initial-data="{}"
|
|
:save-fn="importDms"
|
|
>
|
|
<template #form-inputs>
|
|
<VnSelect
|
|
:label="t('globals.document')"
|
|
:options="dmsOptions"
|
|
hide-selected
|
|
option-label="id"
|
|
option-value="id"
|
|
v-model="dmsId"
|
|
/>
|
|
</template>
|
|
</FormModelPopup>
|
|
</template>
|