0
0
Fork 0

fix(TicketBasicData_zone): refs #6233 add acls and fix get zones

This commit is contained in:
Alex Moreno 2024-10-21 08:41:19 +02:00
parent 55f8b78eba
commit f2147311d3
2 changed files with 34 additions and 19 deletions

View File

@ -141,6 +141,7 @@ function findKeyInOptions() {
function setOptions(data) {
myOptions.value = JSON.parse(JSON.stringify(data));
myOptionsOriginal.value = JSON.parse(JSON.stringify(data));
emit('update:options', data);
}
function filter(val, options) {

View File

@ -12,6 +12,7 @@ import VnInputTime from 'components/common/VnInputTime.vue';
import axios from 'axios';
import useNotify from 'src/composables/useNotify.js';
import { useAcl } from 'src/composables/useAcl';
import { useValidator } from 'src/composables/useValidator';
import { toTimeFormat } from 'filters/date.js';
@ -28,14 +29,17 @@ const { validate } = useValidator();
const { notify } = useNotify();
const router = useRouter();
const { t } = useI18n();
const agencyFetchRef = ref(null);
const zonesFetchRef = ref(null);
const canEditZone = useAcl().hasAny([
{ model: 'Ticket', props: 'editZone', accessType: 'WRITE' },
]);
const agencyFetchRef = ref();
const warehousesOptions = ref([]);
const companiesOptions = ref([]);
const agenciesOptions = ref([]);
const zonesOptions = ref([]);
const addresses = ref([]);
const zoneSelectRef = ref();
const formData = ref($props.formData);
watch(
@ -44,6 +48,8 @@ watch(
{ deep: true }
);
onMounted(() => onFormModelInit());
const agencyByWarehouseFilter = computed(() => ({
fields: ['id', 'name'],
order: 'name ASC',
@ -52,18 +58,16 @@ const agencyByWarehouseFilter = computed(() => ({
},
}));
function zoneWhere() {
if (formData?.value?.agencyModeFk) {
return formData.value?.agencyModeFk
? {
shipped: formData.value?.shipped,
addressFk: formData.value?.addressFk,
agencyModeFk: formData.value?.agencyModeFk,
warehouseFk: formData.value?.warehouseFk,
}
: {};
}
}
const zoneWhere = computed(() => {
return formData.value?.agencyModeFk
? {
shipped: formData.value?.shipped,
addressFk: formData.value?.addressFk,
agencyModeFk: formData.value?.agencyModeFk,
warehouseFk: formData.value?.warehouseFk,
}
: {};
});
const getLanded = async (params) => {
try {
@ -270,7 +274,17 @@ const redirectToCustomerAddress = () => {
});
};
onMounted(() => onFormModelInit());
async function getZone(options) {
if (!zoneId.value) return;
const zone = options.find((z) => z.id == zoneId.value);
if (zone) return;
const { data } = await axios.get('Zones/' + zoneId.value, {
params: { filter: JSON.stringify({ fields: ['id', 'name'] }) },
});
zoneSelectRef.value.opts.push(data);
}
</script>
<template>
<FetchData
@ -416,6 +430,7 @@ onMounted(() => onFormModelInit());
:rules="validate('basicData.agency')"
/>
<VnSelect
ref="zoneSelectRef"
:label="t('basicData.zone')"
v-model="zoneId"
option-value="id"
@ -424,11 +439,10 @@ onMounted(() => onFormModelInit());
:fields="['id', 'name']"
sort-by="id"
:where="zoneWhere"
hide-selected
map-options
:required="true"
@focus="zonesFetchRef.fetch()"
:rules="validate('basicData.zone')"
:required="true"
:disable="!canEditZone"
@update:options="getZone"
>
<template #option="scope">
<QItem v-bind="scope.itemProps">