2024-02-02 15:45:29 +00:00
|
|
|
<script setup>
|
2024-04-25 06:50:12 +00:00
|
|
|
import { ref, markRaw } from 'vue';
|
2024-02-02 15:45:29 +00:00
|
|
|
import { useI18n } from 'vue-i18n';
|
|
|
|
|
2024-04-23 11:03:32 +00:00
|
|
|
import VnSelect from 'src/components/common/VnSelect.vue';
|
2024-02-02 15:45:29 +00:00
|
|
|
import VnInput from 'src/components/common/VnInput.vue';
|
2024-04-25 06:50:12 +00:00
|
|
|
import VnInputDate from 'src/components/common/VnInputDate.vue';
|
|
|
|
import VnRow from 'components/ui/VnRow.vue';
|
|
|
|
import { QCheckbox } from 'quasar';
|
2024-02-02 15:45:29 +00:00
|
|
|
|
|
|
|
import axios from 'axios';
|
|
|
|
import useNotify from 'src/composables/useNotify.js';
|
|
|
|
|
|
|
|
const emit = defineEmits(['onDataSaved']);
|
|
|
|
|
|
|
|
const $props = defineProps({
|
|
|
|
rows: {
|
|
|
|
type: Array,
|
|
|
|
default: () => [],
|
|
|
|
},
|
2024-02-05 12:37:29 +00:00
|
|
|
fieldsOptions: {
|
|
|
|
type: Array,
|
|
|
|
default: () => [],
|
|
|
|
},
|
|
|
|
editUrl: {
|
|
|
|
type: String,
|
|
|
|
default: '',
|
|
|
|
},
|
2024-02-02 15:45:29 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const { t } = useI18n();
|
|
|
|
const { notify } = useNotify();
|
|
|
|
|
2024-04-25 06:50:12 +00:00
|
|
|
const inputs = {
|
|
|
|
input: markRaw(VnInput),
|
|
|
|
number: markRaw(VnInput),
|
|
|
|
date: markRaw(VnInputDate),
|
|
|
|
checkbox: markRaw(QCheckbox),
|
|
|
|
select: markRaw(VnSelectFilter),
|
|
|
|
};
|
2024-02-02 15:45:29 +00:00
|
|
|
|
2024-04-25 06:50:12 +00:00
|
|
|
const newValue = ref(null);
|
|
|
|
const selectedField = ref(null);
|
2024-02-02 15:45:29 +00:00
|
|
|
const closeButton = ref(null);
|
|
|
|
const isLoading = ref(false);
|
|
|
|
|
|
|
|
const onDataSaved = () => {
|
|
|
|
notify('globals.dataSaved', 'positive');
|
|
|
|
emit('onDataSaved');
|
|
|
|
closeForm();
|
|
|
|
};
|
|
|
|
|
|
|
|
const submitData = async () => {
|
|
|
|
try {
|
|
|
|
isLoading.value = true;
|
|
|
|
const rowsToEdit = $props.rows.map((row) => ({ id: row.id, itemFk: row.itemFk }));
|
|
|
|
const payload = {
|
2024-04-25 06:50:12 +00:00
|
|
|
field: selectedField.value.field,
|
|
|
|
newValue: newValue.value,
|
2024-02-02 15:45:29 +00:00
|
|
|
lines: rowsToEdit,
|
|
|
|
};
|
|
|
|
|
2024-02-05 12:37:29 +00:00
|
|
|
await axios.post($props.editUrl, payload);
|
2024-02-02 15:45:29 +00:00
|
|
|
onDataSaved();
|
|
|
|
isLoading.value = false;
|
|
|
|
} catch (err) {
|
|
|
|
console.error('Error submitting table cell edit');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const closeForm = () => {
|
|
|
|
if (closeButton.value) closeButton.value.click();
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<QForm @submit="submitData()" class="all-pointer-events">
|
|
|
|
<QCard class="q-pa-lg">
|
|
|
|
<span ref="closeButton" class="close-icon" v-close-popup>
|
|
|
|
<QIcon name="close" size="sm" />
|
|
|
|
</span>
|
2024-03-06 22:00:50 +00:00
|
|
|
<span class="title">{{ t('Edit') }}</span>
|
|
|
|
<span class="countLines">{{ ` ${rows.length} ` }}</span>
|
|
|
|
<span class="title">{{ t('buy(s)') }}</span>
|
2024-02-02 15:45:29 +00:00
|
|
|
<VnRow class="row q-gutter-md q-mb-md">
|
2024-04-25 06:50:12 +00:00
|
|
|
<VnSelect
|
|
|
|
:label="t('Field to edit')"
|
|
|
|
:options="fieldsOptions"
|
|
|
|
hide-selected
|
|
|
|
option-label="label"
|
|
|
|
v-model="selectedField"
|
|
|
|
/>
|
|
|
|
<component
|
|
|
|
:is="inputs[selectedField?.component || 'input']"
|
|
|
|
v-bind="selectedField?.attrs || {}"
|
|
|
|
v-model="newValue"
|
|
|
|
:label="t('Value')"
|
|
|
|
style="width: 200px"
|
|
|
|
/>
|
2024-02-02 15:45:29 +00:00
|
|
|
</VnRow>
|
|
|
|
<div class="q-mt-lg row justify-end">
|
|
|
|
<QBtn
|
2024-03-06 22:00:50 +00:00
|
|
|
:label="t('globals.cancel')"
|
|
|
|
type="reset"
|
2024-02-02 15:45:29 +00:00
|
|
|
color="primary"
|
2024-03-06 22:00:50 +00:00
|
|
|
flat
|
2024-02-02 15:45:29 +00:00
|
|
|
:disabled="isLoading"
|
|
|
|
:loading="isLoading"
|
2024-03-06 22:00:50 +00:00
|
|
|
v-close-popup
|
2024-02-02 15:45:29 +00:00
|
|
|
/>
|
|
|
|
<QBtn
|
2024-03-06 22:00:50 +00:00
|
|
|
:label="t('globals.save')"
|
|
|
|
type="submit"
|
2024-02-02 15:45:29 +00:00
|
|
|
color="primary"
|
|
|
|
class="q-ml-sm"
|
|
|
|
:disabled="isLoading"
|
|
|
|
:loading="isLoading"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</QCard>
|
|
|
|
</QForm>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.title {
|
|
|
|
font-size: 17px;
|
|
|
|
font-weight: bold;
|
|
|
|
line-height: 20px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.close-icon {
|
|
|
|
position: absolute;
|
|
|
|
top: 20px;
|
|
|
|
right: 20px;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
2024-03-06 22:00:50 +00:00
|
|
|
|
|
|
|
.countLines {
|
|
|
|
font-size: 24px;
|
|
|
|
color: $primary;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
2024-02-02 15:45:29 +00:00
|
|
|
</style>
|
|
|
|
|
|
|
|
<i18n>
|
2024-03-06 22:00:50 +00:00
|
|
|
es:
|
|
|
|
Edit: Editar
|
|
|
|
buy(s): compra(s)
|
|
|
|
Field to edit: Campo a editar
|
|
|
|
Value: Valor
|
|
|
|
</i18n>
|