refactor: refs #8944 modified EditFixedPrice component to save data as VnTable
This commit is contained in:
parent
701af0d9b8
commit
1a6fd22b94
|
@ -2,9 +2,10 @@
|
||||||
import { onMounted, ref, onUnmounted, computed, watch } from 'vue';
|
import { onMounted, ref, onUnmounted, computed, watch } from 'vue';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
import { useQuasar } from 'quasar';
|
||||||
|
|
||||||
import { useStateStore } from 'stores/useStateStore';
|
import { useStateStore } from 'stores/useStateStore';
|
||||||
import { useState } from 'src/composables/useState';
|
import { useState } from 'src/composables/useState';
|
||||||
|
|
||||||
import { beforeSave } from 'src/composables/updateMinPriceBeforeSave';
|
import { beforeSave } from 'src/composables/updateMinPriceBeforeSave';
|
||||||
|
|
||||||
import FetchedTags from 'components/ui/FetchedTags.vue';
|
import FetchedTags from 'components/ui/FetchedTags.vue';
|
||||||
|
@ -15,13 +16,13 @@ import RightMenu from 'src/components/common/RightMenu.vue';
|
||||||
import VnTable from 'src/components/VnTable/VnTable.vue';
|
import VnTable from 'src/components/VnTable/VnTable.vue';
|
||||||
import VnColor from 'src/components/common/VnColor.vue';
|
import VnColor from 'src/components/common/VnColor.vue';
|
||||||
|
|
||||||
import { toDate } from 'src/filters';
|
import { toDate, toCurrency } from 'src/filters';
|
||||||
import { isLower, isBigger } from 'src/filters/date.js';
|
import { isLower, isBigger } from 'src/filters/date.js';
|
||||||
import ItemFixedPriceFilter from './ItemFixedPriceFilter.vue';
|
import ItemFixedPriceFilter from './ItemFixedPriceFilter.vue';
|
||||||
import ItemDescriptorProxy from './Card/ItemDescriptorProxy.vue';
|
import ItemDescriptorProxy from './Card/ItemDescriptorProxy.vue';
|
||||||
import { toCurrency } from 'src/filters';
|
|
||||||
|
|
||||||
const stateStore = useStateStore();
|
const stateStore = useStateStore();
|
||||||
|
const quasar = useQuasar();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const tableRef = ref();
|
const tableRef = ref();
|
||||||
const editFixedPriceForm = ref(null);
|
const editFixedPriceForm = ref(null);
|
||||||
|
@ -219,9 +220,13 @@ const dateStyle = (date) =>
|
||||||
}
|
}
|
||||||
: { color: dateColor, 'background-color': 'transparent' };
|
: { color: dateColor, 'background-color': 'transparent' };
|
||||||
|
|
||||||
const onDataSaved = () => {
|
const onDataSaved = async (data) => {
|
||||||
tableRef.value.CrudModelRef.saveChanges();
|
for (const row of data) {
|
||||||
|
await axios.patch('FixedPrices/upsertFixedPrice', row);
|
||||||
|
}
|
||||||
selectedRows.value = [];
|
selectedRows.value = [];
|
||||||
|
tableRef.value.reload();
|
||||||
|
tableRef.value.CrudModelRef.reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
async function saveData(data, getChanges) {
|
async function saveData(data, getChanges) {
|
||||||
|
@ -236,6 +241,10 @@ async function saveData(data, getChanges) {
|
||||||
if (data?.deletes?.length) {
|
if (data?.deletes?.length) {
|
||||||
for (const deleteItem of data.deletes) {
|
for (const deleteItem of data.deletes) {
|
||||||
await axios.delete(`FixedPrices/${deleteItem}`);
|
await axios.delete(`FixedPrices/${deleteItem}`);
|
||||||
|
quasar.notify({
|
||||||
|
message: t('globals.dataDeleted'),
|
||||||
|
color: 'positive',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tableRef.value.reload();
|
tableRef.value.reload();
|
||||||
|
|
|
@ -26,7 +26,6 @@ const $props = defineProps({
|
||||||
default: () => {},
|
default: () => {},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const emit = defineEmits(['onDataSaved']);
|
const emit = defineEmits(['onDataSaved']);
|
||||||
|
|
||||||
|
@ -38,7 +37,7 @@ const inputs = {
|
||||||
select: markRaw(VnSelect),
|
select: markRaw(VnSelect),
|
||||||
};
|
};
|
||||||
|
|
||||||
const newValue = ref(null);
|
const newFieldValue = ref(null);
|
||||||
const selectedField = ref(null);
|
const selectedField = ref(null);
|
||||||
const closeButton = ref(null);
|
const closeButton = ref(null);
|
||||||
const isLoading = ref(false);
|
const isLoading = ref(false);
|
||||||
|
@ -46,7 +45,11 @@ const isLoading = ref(false);
|
||||||
const onSubmit = async () => {
|
const onSubmit = async () => {
|
||||||
isLoading.value = true;
|
isLoading.value = true;
|
||||||
$props.rows.forEach((row) => {
|
$props.rows.forEach((row) => {
|
||||||
row[selectedField.value.name] = newValue.value;
|
const newValue =
|
||||||
|
selectedField.value.component === 'number'
|
||||||
|
? parseInt(newFieldValue.value)
|
||||||
|
: newFieldValue.value;
|
||||||
|
row[selectedField.value.name] = newValue;
|
||||||
});
|
});
|
||||||
emit('onDataSaved', $props.rows);
|
emit('onDataSaved', $props.rows);
|
||||||
closeForm();
|
closeForm();
|
||||||
|
@ -77,11 +80,19 @@ const closeForm = () => {
|
||||||
data-cy="EditFixedPriceSelectOption"
|
data-cy="EditFixedPriceSelectOption"
|
||||||
@update:model-value="newValue = null"
|
@update:model-value="newValue = null"
|
||||||
:class="{ 'is-select': selectedField?.component === 'select' }"
|
:class="{ 'is-select': selectedField?.component === 'select' }"
|
||||||
/>
|
>
|
||||||
|
<template #option="{ opt, itemProps }">
|
||||||
|
<QItem v-bind="itemProps" class="q-pa-xs row items-center">
|
||||||
|
<QItemSection class="col-9 justify-center">
|
||||||
|
<span>{{ opt?.label }}</span>
|
||||||
|
</QItemSection>
|
||||||
|
</QItem>
|
||||||
|
</template>
|
||||||
|
</VnSelect>
|
||||||
<component
|
<component
|
||||||
:is="inputs[selectedField?.component || 'input']"
|
:is="inputs[selectedField?.component || 'input']"
|
||||||
v-bind="selectedField?.attrs || {}"
|
v-bind="selectedField?.attrs || {}"
|
||||||
v-model="newValue"
|
v-model="newFieldValue"
|
||||||
:label="t('Value')"
|
:label="t('Value')"
|
||||||
data-cy="EditFixedPriceValueOption"
|
data-cy="EditFixedPriceValueOption"
|
||||||
style="width: 200px"
|
style="width: 200px"
|
||||||
|
|
Loading…
Reference in New Issue