feat: remove duplicity

This commit is contained in:
Javier Segarra 2024-08-14 15:26:47 +02:00
parent ea43df81fd
commit c878fc9cff
1 changed files with 15 additions and 10 deletions

View File

@ -1,5 +1,5 @@
<script setup> <script setup>
import { onMounted, ref, reactive } from 'vue'; import { onMounted, ref, reactive, watch } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import VnSelect from 'src/components/common/VnSelect.vue'; import VnSelect from 'src/components/common/VnSelect.vue';
@ -12,6 +12,7 @@ const { notify } = useNotify();
const deliveryMethodFk = ref('delivery'); const deliveryMethodFk = ref('delivery');
const deliveryMethods = ref({}); const deliveryMethods = ref({});
const inq = ref([]);
const formData = reactive({}); const formData = reactive({});
const arrayData = useArrayData('ZoneDeliveryDays', { const arrayData = useArrayData('ZoneDeliveryDays', {
@ -39,11 +40,18 @@ const onSubmit = async () => {
}; };
onMounted(async () => { onMounted(async () => {
deliveryMethodFk.value = 'delivery';
formData.geoFk = arrayData.store?.userParams?.geoFk; formData.geoFk = arrayData.store?.userParams?.geoFk;
formData.agencyModeFk = arrayData.store?.userParams?.agencyModeFk; formData.agencyModeFk = arrayData.store?.userParams?.agencyModeFk;
if (formData.geoFk || formData.agencyModeFk) await fetchData(); if (formData.geoFk || formData.agencyModeFk) await fetchData();
}); });
watch(
() => deliveryMethodFk.value,
() => {
inq.value = {
deliveryMethodFk: { inq: deliveryMethods.value[deliveryMethodFk.value] },
};
}
);
</script> </script>
<template> <template>
@ -52,13 +60,14 @@ onMounted(async () => {
:fields="['id', 'name', 'deliveryMethodFk']" :fields="['id', 'name', 'deliveryMethodFk']"
@on-fetch=" @on-fetch="
(data) => { (data) => {
console.log('data: ', data);
console.log('deliveryMethodsConfig: ', deliveryMethodsConfig);
Object.entries(deliveryMethodsConfig).forEach(([key, value]) => { Object.entries(deliveryMethodsConfig).forEach(([key, value]) => {
deliveryMethods[key] = data deliveryMethods[key] = data
.filter((code) => value.includes(code.code)) .filter((code) => value.includes(code.code))
.map((method) => method.id); .map((method) => method.id);
}); });
inq = {
deliveryMethodFk: { inq: deliveryMethods[deliveryMethodFk] },
};
} }
" "
auto-load auto-load
@ -112,9 +121,7 @@ onMounted(async () => {
v-model="formData.agencyModeFk" v-model="formData.agencyModeFk"
url="AgencyModes/isActive" url="AgencyModes/isActive"
:fields="['id', 'name']" :fields="['id', 'name']"
:where="{ :where="inq"
deliveryMethodFk: { inq: deliveryMethods[deliveryMethodFk] },
}"
sort-by="name ASC" sort-by="name ASC"
option-value="id" option-value="id"
option-label="name" option-label="name"
@ -129,9 +136,7 @@ onMounted(async () => {
v-model="formData.agencyModeFk" v-model="formData.agencyModeFk"
url="AgencyModes/isActive" url="AgencyModes/isActive"
:fields="['id', 'name']" :fields="['id', 'name']"
:where="{ :where="inq"
deliveryMethodFk: { inq: deliveryMethods[deliveryMethodFk] },
}"
sort-by="name ASC" sort-by="name ASC"
option-value="id" option-value="id"
option-label="name" option-label="name"