{{ t('Edit file') }}
diff --git a/src/pages/Travel/Card/TravelThermographsForm.vue b/src/pages/Travel/Card/TravelThermographsForm.vue
index da0a4ee2b..ea407ec69 100644
--- a/src/pages/Travel/Card/TravelThermographsForm.vue
+++ b/src/pages/Travel/Card/TravelThermographsForm.vue
@@ -52,11 +52,13 @@ const thermographForm = reactive({
description: null,
});
-onBeforeMount(() => {
- getAllowedFileTypes();
+onBeforeMount(async () => {
+ await getAllowedFileTypes();
if (props.viewAction === 'create') {
setCreateDefaultParams();
+ } else {
+ await setEditDefaultParams();
}
if (route.query.thermographData) {
@@ -103,6 +105,30 @@ const setCreateDefaultParams = async () => {
}).toUpperCase();
};
+const setEditDefaultParams = async () => {
+ try {
+ const filterObj = { include: { relation: 'dms' } };
+ const filter = encodeURIComponent(JSON.stringify(filterObj));
+ const { data } = await axios.get(
+ `TravelThermographs/${route.params.thermographId}?filter=${filter}`
+ );
+
+ if (data) {
+ thermographForm.thermographId = data.thermographFk;
+ thermographForm.state = data.result;
+ thermographForm.reference = data.dms?.reference;
+ thermographForm.warehouseId = data.dms?.warehouseFk;
+ thermographForm.companyId = data.dms?.companyFk;
+ thermographForm.dmsTypeId = data.dms?.dmsTypeFk;
+ thermographForm.description = data.dms?.description || '';
+ thermographForm.hasFile = data.dms?.hasFile;
+ thermographForm.hasFileAttached = false;
+ }
+ } catch (err) {
+ console.error('Error fetching termograph');
+ }
+};
+
const onSubmit = () => {
props.viewAction === 'create' ? createThermograph() : updateThermograph();
};
@@ -128,8 +154,25 @@ const createThermograph = async () => {
}
};
-const updateThermograph = () => {
- // `travels/${route.params.id}/updateThermograph`;
+const updateThermograph = async () => {
+ const formData = new FormData();
+
+ thermographForm.files.forEach((file) => {
+ formData.append(file.name, file);
+ });
+
+ try {
+ await axios.post(`travels/${route.params.id}/updateThermograph`, formData, {
+ params: thermographForm,
+ headers: {
+ 'Content-Type': 'multipart/form-data',
+ },
+ });
+ router.push({ name: 'TravelThermographsIndex' });
+ notify(t('Thermograph created'), 'positive');
+ } catch (error) {
+ console.error('Error creating thermograph');
+ }
};
@@ -197,6 +240,7 @@ const updateThermograph = () => {
:options="thermographsOptions"
option-value="thermographFk"
option-label="thermographFk"
+ :disable="viewAction === 'edit'"
/>
@@ -243,6 +287,16 @@ const updateThermograph = () => {
/>
+
+
+
+
+
{
-
-
-
-
-
-
-
-
-
-
-
-
-
+ />
-
-
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/src/router/modules/travel.js b/src/router/modules/travel.js
index 5d9884dc2..c34ebe757 100644
--- a/src/router/modules/travel.js
+++ b/src/router/modules/travel.js
@@ -83,7 +83,7 @@ export default {
},
{
name: 'TravelThermographs',
- path: 'thermographs',
+ path: 'thermographs/:thermographId?',
meta: {
title: 'thermographs',
icon: 'vn:thermometer',