Solucion a comentarios 18
gitea/salix-front/pipeline/pr-dev This commit looks good
Details
gitea/salix-front/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
3bcd4984f5
commit
980904a382
|
@ -3,6 +3,8 @@ import { ref } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useRoute, useRouter } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
|
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
import FetchData from 'components/FetchData.vue';
|
import FetchData from 'components/FetchData.vue';
|
||||||
import VnPaginate from 'src/components/ui/VnPaginate.vue';
|
import VnPaginate from 'src/components/ui/VnPaginate.vue';
|
||||||
|
|
||||||
|
@ -10,6 +12,7 @@ const { t } = useI18n();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
const addresses = ref([]);
|
||||||
const client = ref(null);
|
const client = ref(null);
|
||||||
const provincesLocation = ref([]);
|
const provincesLocation = ref([]);
|
||||||
|
|
||||||
|
@ -45,6 +48,11 @@ const addressFilter = {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const setRows = (data) => {
|
||||||
|
addresses.value = data;
|
||||||
|
sortAddresses();
|
||||||
|
};
|
||||||
|
|
||||||
const setProvince = (provinceFk) => {
|
const setProvince = (provinceFk) => {
|
||||||
const result = provincesLocation.value.filter(
|
const result = provincesLocation.value.filter(
|
||||||
(province) => province.id === provinceFk
|
(province) => province.id === provinceFk
|
||||||
|
@ -56,6 +64,24 @@ const isDefaultAddress = (address) => {
|
||||||
return client?.value?.defaultAddressFk === address.id ? 1 : 0;
|
return client?.value?.defaultAddressFk === address.id ? 1 : 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const setDefault = (address) => {
|
||||||
|
const url = `Clients/${route.params.id}`;
|
||||||
|
const payload = { defaultAddressFk: address.id };
|
||||||
|
axios.patch(url, payload).then((res) => {
|
||||||
|
if (res.data) {
|
||||||
|
client.value.defaultAddressFk = res.data.defaultAddressFk;
|
||||||
|
sortAddresses();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const sortAddresses = () => {
|
||||||
|
if (!client.value || !addresses.value) return;
|
||||||
|
addresses.value = addresses.value.sort((a, b) => {
|
||||||
|
return isDefaultAddress(b) - isDefaultAddress(a);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const toCustomerAddressCreate = () => {
|
const toCustomerAddressCreate = () => {
|
||||||
router.push({ name: 'CustomerAddressCreate' });
|
router.push({ name: 'CustomerAddressCreate' });
|
||||||
};
|
};
|
||||||
|
@ -72,6 +98,12 @@ const toCustomerAddressEdit = (addressId) => {
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
<FetchData
|
||||||
|
@on-fetch="setRows"
|
||||||
|
auto-load
|
||||||
|
:filter="addressFilter"
|
||||||
|
:url="`Clients/${route.params.id}/addresses`"
|
||||||
|
/>
|
||||||
<FetchData
|
<FetchData
|
||||||
@on-fetch="(data) => (client = data)"
|
@on-fetch="(data) => (client = data)"
|
||||||
auto-load
|
auto-load
|
||||||
|
@ -83,21 +115,15 @@ const toCustomerAddressEdit = (addressId) => {
|
||||||
url="Provinces/location"
|
url="Provinces/location"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<QCard class="q-pa-lg">
|
<div class="full-width flex justify-center">
|
||||||
<VnPaginate
|
<QCard class="card-width q-pa-lg" v-if="addresses.length">
|
||||||
data-key="CustomerAddress"
|
<QCardSection>
|
||||||
:url="`Clients/${route.params.id}/addresses`"
|
<div
|
||||||
order="id"
|
v-for="(item, index) in addresses"
|
||||||
auto-load
|
|
||||||
:filter="addressFilter"
|
|
||||||
>
|
|
||||||
<template #body="{ rows }">
|
|
||||||
<QCard
|
|
||||||
v-for="(item, index) in rows"
|
|
||||||
:key="index"
|
:key="index"
|
||||||
:class="{
|
:class="{
|
||||||
'address-card': true,
|
'address-card': true,
|
||||||
'q-mb-md': index < rows.length - 1,
|
'q-mb-md': index < addresses.length - 1,
|
||||||
'item-disabled': !item.isActive,
|
'item-disabled': !item.isActive,
|
||||||
}"
|
}"
|
||||||
@click="toCustomerAddressEdit(item.id)"
|
@click="toCustomerAddressEdit(item.id)"
|
||||||
|
@ -112,7 +138,18 @@ const toCustomerAddressEdit = (addressId) => {
|
||||||
color="primary"
|
color="primary"
|
||||||
name="star"
|
name="star"
|
||||||
size="md"
|
size="md"
|
||||||
/>
|
@click.stop="!isDefaultAddress(item) && setDefault(item)"
|
||||||
|
>
|
||||||
|
<QTooltip>
|
||||||
|
{{
|
||||||
|
t(
|
||||||
|
isDefaultAddress(item)
|
||||||
|
? 'Default address'
|
||||||
|
: 'Set as default'
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
</QTooltip>
|
||||||
|
</QIcon>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div class="text-weight-bold q-mb-sm">
|
<div class="text-weight-bold q-mb-sm">
|
||||||
|
@ -156,10 +193,10 @@ const toCustomerAddressEdit = (addressId) => {
|
||||||
<div>{{ observation.description }}</div>
|
<div>{{ observation.description }}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</QCard>
|
</div>
|
||||||
</template>
|
</QCardSection>
|
||||||
</VnPaginate>
|
</QCard>
|
||||||
</QCard>
|
</div>
|
||||||
|
|
||||||
<QPageSticky :offset="[18, 18]">
|
<QPageSticky :offset="[18, 18]">
|
||||||
<QBtn @click.stop="toCustomerAddressCreate()" color="primary" fab icon="add" />
|
<QBtn @click.stop="toCustomerAddressCreate()" color="primary" fab icon="add" />
|
||||||
|
@ -192,4 +229,6 @@ es:
|
||||||
Is equalizated: Recargo de equivalencia
|
Is equalizated: Recargo de equivalencia
|
||||||
Is logiflora allowed: Compra directa en Holanda
|
Is logiflora allowed: Compra directa en Holanda
|
||||||
New consignee: Nuevo consignatario
|
New consignee: Nuevo consignatario
|
||||||
|
Default address: Consignatario predeterminado
|
||||||
|
Set as default: Establecer como predeterminado
|
||||||
</i18n>
|
</i18n>
|
||||||
|
|
Loading…
Reference in New Issue