feat: handle same multiple CP
This commit is contained in:
parent
92130b4c9c
commit
55b9cd9ff4
|
@ -2,20 +2,32 @@
|
||||||
import CreateNewPostcode from 'src/components/CreateNewPostcodeForm.vue';
|
import CreateNewPostcode from 'src/components/CreateNewPostcodeForm.vue';
|
||||||
import VnSelectDialog from 'components/common/VnSelectDialog.vue';
|
import VnSelectDialog from 'components/common/VnSelectDialog.vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
import { ref } from 'vue';
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const value = defineModel({ type: [String, Number, Object] });
|
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
location: {
|
||||||
|
type: Object,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const modelValue = ref(
|
||||||
|
props.location
|
||||||
|
? `${props.location?.postcode} - ${props.location?.city}(${props.location?.province?.name}), ${props.location?.country?.name}`
|
||||||
|
: null
|
||||||
|
);
|
||||||
function showLabel(data) {
|
function showLabel(data) {
|
||||||
return `${data.code} - ${data.town}(${data.province}), ${data.country}`;
|
return `${data.code} - ${data.town}(${data.province}), ${data.country}`;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
|
{{ modelValue }}
|
||||||
<VnSelectDialog
|
<VnSelectDialog
|
||||||
v-model="value"
|
v-model="modelValue"
|
||||||
option-value="code"
|
|
||||||
option-filter-value="search"
|
option-filter-value="search"
|
||||||
:option-label="(opt) => showLabel(opt)"
|
:option-label="
|
||||||
|
(opt) => (typeof modelValue === 'string' ? modelValue : showLabel(opt))
|
||||||
|
"
|
||||||
url="Postcodes/filter"
|
url="Postcodes/filter"
|
||||||
:use-like="false"
|
:use-like="false"
|
||||||
:label="t('Location')"
|
:label="t('Location')"
|
||||||
|
@ -27,7 +39,7 @@ function showLabel(data) {
|
||||||
:emit-value="false"
|
:emit-value="false"
|
||||||
>
|
>
|
||||||
<template #form>
|
<template #form>
|
||||||
<CreateNewPostcode @on-data-saved="(newValue) => (value = newValue)" />
|
<CreateNewPostcode @on-data-saved="(newValue) => (modelValue = newValue)" />
|
||||||
</template>
|
</template>
|
||||||
<template #option="{ itemProps, opt }">
|
<template #option="{ itemProps, opt }">
|
||||||
<QItem v-bind="itemProps">
|
<QItem v-bind="itemProps">
|
||||||
|
|
|
@ -95,6 +95,7 @@ globals:
|
||||||
to: To
|
to: To
|
||||||
pageTitles:
|
pageTitles:
|
||||||
logIn: Login
|
logIn: Login
|
||||||
|
addressEdit: Update address
|
||||||
summary: Summary
|
summary: Summary
|
||||||
basicData: Basic data
|
basicData: Basic data
|
||||||
log: Logs
|
log: Logs
|
||||||
|
|
|
@ -95,6 +95,7 @@ globals:
|
||||||
to: Hasta
|
to: Hasta
|
||||||
pageTitles:
|
pageTitles:
|
||||||
logIn: Inicio de sesión
|
logIn: Inicio de sesión
|
||||||
|
addressEdit: Modificar consignatario
|
||||||
summary: Resumen
|
summary: Resumen
|
||||||
basicData: Datos básicos
|
basicData: Datos básicos
|
||||||
log: Historial
|
log: Historial
|
||||||
|
|
|
@ -5,15 +5,12 @@ import { useRoute, useRouter } from 'vue-router';
|
||||||
|
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
import FetchData from 'components/FetchData.vue';
|
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const addresses = ref([]);
|
const addresses = ref([]);
|
||||||
const client = ref(null);
|
const client = ref(null);
|
||||||
const provincesLocation = ref([]);
|
|
||||||
|
|
||||||
const addressFilter = {
|
const addressFilter = {
|
||||||
fields: [
|
fields: [
|
||||||
|
@ -41,7 +38,13 @@ const addressFilter = {
|
||||||
{
|
{
|
||||||
relation: 'province',
|
relation: 'province',
|
||||||
scope: {
|
scope: {
|
||||||
fields: ['id', 'name'],
|
fields: ['id', 'name', 'countryFk'],
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
relation: 'country',
|
||||||
|
scope: { fields: ['id', 'name'] },
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -83,13 +86,6 @@ const getClientData = async (id) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const setProvince = (provinceFk) => {
|
|
||||||
const result = provincesLocation.value.filter(
|
|
||||||
(province) => province.id === provinceFk
|
|
||||||
);
|
|
||||||
return result[0]?.name || '';
|
|
||||||
};
|
|
||||||
|
|
||||||
const isDefaultAddress = (address) => {
|
const isDefaultAddress = (address) => {
|
||||||
return client?.value?.defaultAddressFk === address.id ? 1 : 0;
|
return client?.value?.defaultAddressFk === address.id ? 1 : 0;
|
||||||
};
|
};
|
||||||
|
@ -128,12 +124,6 @@ const toCustomerAddressEdit = (addressId) => {
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<FetchData
|
|
||||||
@on-fetch="(data) => (provincesLocation = data)"
|
|
||||||
auto-load
|
|
||||||
url="Provinces/location"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div class="full-width flex justify-center">
|
<div class="full-width flex justify-center">
|
||||||
<QCard class="card-width q-pa-lg" v-if="addresses.length">
|
<QCard class="card-width q-pa-lg" v-if="addresses.length">
|
||||||
<QCardSection>
|
<QCardSection>
|
||||||
|
@ -177,7 +167,7 @@ const toCustomerAddressEdit = (addressId) => {
|
||||||
<div>{{ item.street }}</div>
|
<div>{{ item.street }}</div>
|
||||||
<div>
|
<div>
|
||||||
{{ item.postalCode }} - {{ item.city }},
|
{{ item.postalCode }} - {{ item.city }},
|
||||||
{{ setProvince(item.provinceFk) }}
|
{{ item.province.name }}
|
||||||
</div>
|
</div>
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<QCheckbox
|
<QCheckbox
|
||||||
|
|
|
@ -94,7 +94,7 @@ function handleLocation(data, location) {
|
||||||
<VnLocation
|
<VnLocation
|
||||||
:rules="validate('Worker.postcode')"
|
:rules="validate('Worker.postcode')"
|
||||||
:roles-allowed-to-create="['deliveryAssistant']"
|
:roles-allowed-to-create="['deliveryAssistant']"
|
||||||
v-model="data.postcode"
|
:location="data"
|
||||||
@update:model-value="(location) => handleLocation(data, location)"
|
@update:model-value="(location) => handleLocation(data, location)"
|
||||||
/>
|
/>
|
||||||
</VnRow>
|
</VnRow>
|
||||||
|
|
|
@ -87,7 +87,6 @@ function handleLocation(data, location) {
|
||||||
<VnLocation
|
<VnLocation
|
||||||
:rules="validate('Worker.postcode')"
|
:rules="validate('Worker.postcode')"
|
||||||
:roles-allowed-to-create="['deliveryAssistant']"
|
:roles-allowed-to-create="['deliveryAssistant']"
|
||||||
v-model="data.location"
|
|
||||||
@update:model-value="(location) => handleLocation(data, location)"
|
@update:model-value="(location) => handleLocation(data, location)"
|
||||||
>
|
>
|
||||||
</VnLocation>
|
</VnLocation>
|
||||||
|
|
|
@ -413,7 +413,6 @@ function handleLocation(data, location) {
|
||||||
<template #more-create-dialog="{ data }">
|
<template #more-create-dialog="{ data }">
|
||||||
<VnLocation
|
<VnLocation
|
||||||
:roles-allowed-to-create="['deliveryAssistant']"
|
:roles-allowed-to-create="['deliveryAssistant']"
|
||||||
v-model="data.location"
|
|
||||||
@update:model-value="(location) => handleLocation(data, location)"
|
@update:model-value="(location) => handleLocation(data, location)"
|
||||||
/>
|
/>
|
||||||
<QInput v-model="data.userName" :label="t('Web user')" />
|
<QInput v-model="data.userName" :label="t('Web user')" />
|
||||||
|
|
|
@ -93,7 +93,6 @@ function handleLocation(data, location) {
|
||||||
<VnLocation
|
<VnLocation
|
||||||
:rules="validate('Worker.postcode')"
|
:rules="validate('Worker.postcode')"
|
||||||
:roles-allowed-to-create="['deliveryAssistant']"
|
:roles-allowed-to-create="['deliveryAssistant']"
|
||||||
v-model="data.location"
|
|
||||||
@update:model-value="(location) => handleLocation(data, location)"
|
@update:model-value="(location) => handleLocation(data, location)"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
|
@ -177,7 +177,12 @@ function handleLocation(data, location) {
|
||||||
<VnLocation
|
<VnLocation
|
||||||
:rules="validate('Worker.postcode')"
|
:rules="validate('Worker.postcode')"
|
||||||
:roles-allowed-to-create="['deliveryAssistant']"
|
:roles-allowed-to-create="['deliveryAssistant']"
|
||||||
v-model="data.postalCode"
|
:location="{
|
||||||
|
postcode: data.postalCode,
|
||||||
|
city: data.city,
|
||||||
|
province: data.province,
|
||||||
|
country: data.province.country,
|
||||||
|
}"
|
||||||
@update:model-value="(location) => handleLocation(data, location)"
|
@update:model-value="(location) => handleLocation(data, location)"
|
||||||
></VnLocation>
|
></VnLocation>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -26,7 +26,13 @@ const addressesFilter = {
|
||||||
{
|
{
|
||||||
relation: 'province',
|
relation: 'province',
|
||||||
scope: {
|
scope: {
|
||||||
fields: ['id', 'name'],
|
fields: ['id', 'name', 'countryFk'],
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
relation: 'country',
|
||||||
|
scope: { fields: ['id', 'name'] },
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -21,6 +21,7 @@ const newAddressForm = reactive({
|
||||||
provinceFk: null,
|
provinceFk: null,
|
||||||
phone: null,
|
phone: null,
|
||||||
mobile: null,
|
mobile: null,
|
||||||
|
province: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
const onDataSaved = () => {
|
const onDataSaved = () => {
|
||||||
|
@ -84,7 +85,16 @@ function handleLocation(data, location) {
|
||||||
<VnLocation
|
<VnLocation
|
||||||
:rules="validate('Worker.postcode')"
|
:rules="validate('Worker.postcode')"
|
||||||
:roles-allowed-to-create="['deliveryAssistant']"
|
:roles-allowed-to-create="['deliveryAssistant']"
|
||||||
v-model="data.location"
|
:location="
|
||||||
|
data.postalCode
|
||||||
|
? {
|
||||||
|
postcode: data.postalCode,
|
||||||
|
city: data.city,
|
||||||
|
province: data.province,
|
||||||
|
country: data.province.country,
|
||||||
|
}
|
||||||
|
: null
|
||||||
|
"
|
||||||
@update:model-value="(location) => handleLocation(data, location)"
|
@update:model-value="(location) => handleLocation(data, location)"
|
||||||
>
|
>
|
||||||
</VnLocation>
|
</VnLocation>
|
||||||
|
|
|
@ -51,6 +51,23 @@ function handleLocation(data, location) {
|
||||||
:url="`Suppliers/${route.params.id}`"
|
:url="`Suppliers/${route.params.id}`"
|
||||||
:url-update="`Suppliers/${route.params.id}/updateFiscalData`"
|
:url-update="`Suppliers/${route.params.id}/updateFiscalData`"
|
||||||
model="supplier"
|
model="supplier"
|
||||||
|
:filter="{
|
||||||
|
fields: ['id', 'name', 'city', 'postCode', 'countryFk', 'provinceFk'],
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
relation: 'province',
|
||||||
|
scope: {
|
||||||
|
fields: ['id', 'name'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
relation: 'country',
|
||||||
|
scope: {
|
||||||
|
fields: ['id', 'name'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}"
|
||||||
auto-load
|
auto-load
|
||||||
:clear-store-on-unmount="false"
|
:clear-store-on-unmount="false"
|
||||||
>
|
>
|
||||||
|
@ -130,7 +147,12 @@ function handleLocation(data, location) {
|
||||||
<VnLocation
|
<VnLocation
|
||||||
:rules="validate('Worker.postcode')"
|
:rules="validate('Worker.postcode')"
|
||||||
:roles-allowed-to-create="['deliveryAssistant']"
|
:roles-allowed-to-create="['deliveryAssistant']"
|
||||||
v-model="data.postCode"
|
:location="{
|
||||||
|
postcode: data.postCode,
|
||||||
|
city: data.city,
|
||||||
|
province: data.province,
|
||||||
|
country: data.country,
|
||||||
|
}"
|
||||||
@update:model-value="(location) => handleLocation(data, location)"
|
@update:model-value="(location) => handleLocation(data, location)"
|
||||||
>
|
>
|
||||||
</VnLocation>
|
</VnLocation>
|
||||||
|
|
|
@ -172,7 +172,6 @@ onBeforeMount(async () => {
|
||||||
<VnLocation
|
<VnLocation
|
||||||
:rules="validate('Worker.postcode')"
|
:rules="validate('Worker.postcode')"
|
||||||
:roles-allowed-to-create="['deliveryAssistant']"
|
:roles-allowed-to-create="['deliveryAssistant']"
|
||||||
v-model="data.location"
|
|
||||||
@update:model-value="(location) => handleLocation(data, location)"
|
@update:model-value="(location) => handleLocation(data, location)"
|
||||||
:disable="formData.isFreelance"
|
:disable="formData.isFreelance"
|
||||||
>
|
>
|
||||||
|
|
|
@ -223,7 +223,6 @@ function uppercaseStreetModel(data) {
|
||||||
<VnLocation
|
<VnLocation
|
||||||
:roles-allowed-to-create="['deliveryAssistant']"
|
:roles-allowed-to-create="['deliveryAssistant']"
|
||||||
:options="postcodesOptions"
|
:options="postcodesOptions"
|
||||||
v-model="data.location"
|
|
||||||
@update:model-value="(location) => handleLocation(data, location)"
|
@update:model-value="(location) => handleLocation(data, location)"
|
||||||
:disable="data.isFreelance"
|
:disable="data.isFreelance"
|
||||||
>
|
>
|
||||||
|
|
|
@ -174,7 +174,7 @@ export default {
|
||||||
path: 'edit',
|
path: 'edit',
|
||||||
name: 'CustomerAddressEdit',
|
name: 'CustomerAddressEdit',
|
||||||
meta: {
|
meta: {
|
||||||
title: 'address-edit',
|
title: 'addressEdit',
|
||||||
},
|
},
|
||||||
component: () =>
|
component: () =>
|
||||||
import(
|
import(
|
||||||
|
|
Loading…
Reference in New Issue