From 38a6b93a5d16f68e206a346ec1669822853b5941 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 16 Feb 2023 14:10:17 +0100 Subject: [PATCH] feat(claim_photo): add upload button --- src/i18n/en/index.js | 3 +- src/i18n/es/index.js | 4 +- src/pages/Claim/Card/ClaimPhoto.vue | 151 +++++++++++++++++----------- src/pages/Claim/Card/ClaimRma.vue | 36 +++++-- src/router/modules/claim.js | 2 +- 5 files changed, 125 insertions(+), 71 deletions(-) diff --git a/src/i18n/en/index.js b/src/i18n/en/index.js index b0323421d..056338b46 100644 --- a/src/i18n/en/index.js +++ b/src/i18n/en/index.js @@ -241,6 +241,7 @@ export default { summary: 'Summary', basicData: 'Basic Data', rma: 'RMA', + photos: 'Photos', }, list: { customer: 'Customer', @@ -296,7 +297,7 @@ export default { }, photo: { fileDescription: - 'Reclamacion ID {{claimId}} del cliente {{clientName}} id {{clientId}}', + 'Reclamacion ID {claimId} del cliente {clientName} id {clientId}', }, }, invoiceOut: { diff --git a/src/i18n/es/index.js b/src/i18n/es/index.js index 09ffb9d15..1a19a329c 100644 --- a/src/i18n/es/index.js +++ b/src/i18n/es/index.js @@ -240,6 +240,7 @@ export default { summary: 'Resumen', basicData: 'Datos básicos', rma: 'RMA', + photos: 'Fotos', }, list: { customer: 'Cliente', @@ -294,8 +295,7 @@ export default { returnOfMaterial: 'Autorización de retorno de materiales (RMA)', }, photo: { - fileDescription: - 'Claim id {{claimId}} from client {{clientName}} id {{clientId}}', + fileDescription: 'Claim id {claimId} from client {clientName} id {clientId}', }, }, invoiceOut: { diff --git a/src/pages/Claim/Card/ClaimPhoto.vue b/src/pages/Claim/Card/ClaimPhoto.vue index 9a7431fae..3aa6fc3b4 100644 --- a/src/pages/Claim/Card/ClaimPhoto.vue +++ b/src/pages/Claim/Card/ClaimPhoto.vue @@ -3,6 +3,7 @@ import { ref, computed } from 'vue'; import axios from 'axios'; import { useQuasar } from 'quasar'; import VnConfirm from 'src/components/ui/VnConfirm.vue'; +import TeleportSlot from 'src/components/ui/TeleportSlot.vue'; import { useRouter } from 'vue-router'; import { useI18n } from 'vue-i18n'; @@ -22,6 +23,7 @@ const claimId = computed(function () { }); const claimDms = ref([]); +const claimDmsRef = ref(); const dmsType = ref({}); const config = ref({}); const dms = ref({}); @@ -75,22 +77,28 @@ async function deleteDms(index) { function setClaimDms(data) { claimDms.value = data.map((media) => { media.isVideo = media.dms.contentType == 'video/mp4'; + media.url = getImagePath(media); return media; }); } -function uploadFile() { +async function uploadFile() { + claimDmsRef.value.fetch(); const element = document.createElement('input'); element.setAttribute('type', 'file'); element.setAttribute('multiple', true); element.click(); - element.addEventListener('change', () => setDefaultParams()); + element.addEventListener('change', () => { + setDefaultParams(); + create(element.files).then(() => claimDmsRef.value.fetch()); + }); } function setDefaultParams() { console.log(config.value); console.log(dmsType.value); + console.log(claimDms.value); dms.value = { hasFile: false, hasFileAttached: false, @@ -100,12 +108,32 @@ function setDefaultParams() { dmsTypeId: dmsType.value.id, description: t('claim.photo.fileDescription', { claimId: claimId.value, - clientId: claimDms.value.clientFk, clientName: claimDms.value.clientName, + clientId: claimDms.value.clientFk, }).toUpperCase(), }; console.log(dms.value); } + +async function create(files) { + const formData = new FormData(); + for (let i = 0; i < files.length; i++) formData.append(files[i].name, files[i]); + + const query = `claims/${claimId.value}/uploadFile`; + + await axios({ + method: 'POST', + url: query, + data: formData, + params: dms.value, + }); + + quasar.notify({ + message: t('globals.dataSaved'), + type: 'positive', + icon: 'check', + }); +} diff --git a/src/pages/Claim/Card/ClaimRma.vue b/src/pages/Claim/Card/ClaimRma.vue index 8461eb6bd..6f734b917 100644 --- a/src/pages/Claim/Card/ClaimRma.vue +++ b/src/pages/Claim/Card/ClaimRma.vue @@ -6,7 +6,7 @@ import { useRoute } from 'vue-router'; import axios from 'axios'; import Paginate from 'src/components/PaginateData.vue'; import FetchData from 'components/FetchData.vue'; -import TeleportSlot from 'components/ui/TeleportSlot'; +import TeleportSlot from 'components/ui/TeleportSlot.vue'; import { toDate } from 'src/filters'; const quasar = useQuasar(); @@ -90,22 +90,38 @@ function hide() { - {{ t('claim.rma.user') }} - {{ row.worker.user.name }} + {{ + t('claim.rma.user') + }} + {{ + row.worker.user.name + }} - {{ t('claim.rma.created') }} + {{ + t('claim.rma.created') + }} - {{ toDate(row.created, { timeStyle: 'medium' }) }} + {{ + toDate(row.created, { + timeStyle: 'medium', + }) + }} - + {{ t('globals.remove') }} @@ -124,7 +140,13 @@ function hide() { - + diff --git a/src/router/modules/claim.js b/src/router/modules/claim.js index 30be6fd96..597d3e61b 100644 --- a/src/router/modules/claim.js +++ b/src/router/modules/claim.js @@ -81,7 +81,7 @@ export default { path: 'photos', meta: { title: 'photos', - icon: 'vn:image', + icon: 'image', }, component: () => import('src/pages/Claim/Card/ClaimPhoto.vue'), },