0
0
Fork 0

Add required rule to VnInputTime and VnInputDate

This commit is contained in:
William Buezas 2024-06-25 08:43:10 -03:00
commit ba8145eabb
2 changed files with 74 additions and 65 deletions

View File

@ -45,15 +45,18 @@ watch(
const columns = computed(() => [
{
required: true,
label: t('basicData.item'),
name: 'item',
align: 'left',
format: (val) => val.name,
},
{
required: true,
label: t('basicData.description'),
name: 'description',
align: 'left',
hidden: true,
},
{
label: t('basicData.movable'),
@ -61,12 +64,14 @@ const columns = computed(() => [
align: 'left',
},
{
required: true,
label: t('basicData.quantity'),
name: 'quantity',
field: 'quantity',
align: 'left',
},
{
required: true,
label: t('basicData.pricePPU'),
name: 'price',
field: 'price',
@ -74,6 +79,7 @@ const columns = computed(() => [
format: (val) => toCurrency(val),
},
{
required: true,
label: t('basicData.newPricePPU'),
name: 'newPrice',
field: (row) => row.component.newPrice,
@ -81,6 +87,7 @@ const columns = computed(() => [
format: (val) => toCurrency(val),
},
{
required: true,
label: t('basicData.difference'),
name: 'difference',
field: (row) => row.component.difference,
@ -108,18 +115,18 @@ const totalNewPrice = computed(() => {
const totalDifference = computed(() => {
return rows.value.reduce((acc, item) => acc + item.component?.difference || 0, 0);
});
const showMovablecolumn = computed(() => (haveDifferences.value > 0 ? ['movable'] : []));
const haveDifferences = computed(() => _ticketData.value.sale.haveDifferences);
const ticketHaveNegatives = () => {
let _haveNegatives = false;
let haveNotNegatives = false;
_ticketData.value.withoutNegatives = false;
const haveDifferences = _ticketData.value.sale.haveDifferences;
_ticketData.value.sale.items.forEach((item) => {
if (item.quantity > item.movable) _haveNegatives = true;
else haveNotNegatives = true;
});
haveNegatives.value = _haveNegatives && haveNotNegatives && haveDifferences;
haveNegatives.value = _haveNegatives && haveNotNegatives && haveDifferences.value;
if (haveNegatives.value) _ticketData.value.withoutNegatives = true;
};
@ -216,12 +223,14 @@ onUnmounted(() => (stateStore.rightDrawer = false));
</template>
</RightMenu>
<QTable
:visible-columns="showMovablecolumn"
:rows="rows"
:columns="columns"
row-key="id"
:pagination="{ rowsPerPage: 0 }"
class="full-width q-mt-md"
:no-data-label="t('globals.noResults')"
flat
>
<template #body-cell-item="{ row }">
<QTd>

View File

@ -36,10 +36,10 @@ const companiesOptions = ref([]);
const agenciesOptions = ref([]);
const zonesOptions = ref([]);
const addresses = ref([]);
const _formData = ref($props.formData);
const formData = ref($props.formData);
watch(
() => _formData.value,
() => formData.value,
(val) => emit('updateForm', val),
{ deep: true }
);
@ -55,12 +55,12 @@ const agencyByWarehouseFilter = computed(() => ({
const zonesFilter = computed(() => ({
fields: ['id', 'name'],
order: 'name ASC',
where: _formData.value?.agencyModeFk
where: formData.value?.agencyModeFk
? {
shipped: _formData.value?.shipped,
addressFk: _formData.value?.addressFk,
agencyModeFk: _formData.value?.agencyModeFk,
warehouseFk: _formData.value?.warehouseFk,
shipped: formData.value?.shipped,
addressFk: formData.value?.addressFk,
agencyModeFk: formData.value?.agencyModeFk,
warehouseFk: formData.value?.warehouseFk,
}
: {},
}));
@ -71,13 +71,13 @@ const getLanded = async (params) => {
shipped.value && addressId.value && agencyModeId.value && warehouseId.value;
if (!validParams) return;
_formData.value.zoneFk = null;
formData.value.zoneFk = null;
zonesOptions.value = [];
const { data } = await axios.get(`Agencies/getLanded`, { params });
if (data) {
_formData.value.zoneFk = data.zoneFk;
_formData.value.landed = data.landed;
_formData.value.shipped = params.shipped;
formData.value.zoneFk = data.zoneFk;
formData.value.landed = data.landed;
formData.value.shipped = params.shipped;
}
} catch (error) {
console.error(error);
@ -91,13 +91,13 @@ const getShipped = async (params) => {
landed.value && addressId.value && agencyModeId.value && warehouseId.value;
if (!validParams) return;
_formData.value.zoneFk = null;
formData.value.zoneFk = null;
zonesOptions.value = [];
const { data } = await axios.get(`Agencies/getShipped`, { params });
if (data) {
_formData.value.zoneFk = data.zoneFk;
_formData.value.landed = params.landed;
_formData.value.shipped = data.shipped;
formData.value.zoneFk = data.zoneFk;
formData.value.landed = params.landed;
formData.value.shipped = data.shipped;
} else {
notify(t('basicData.noDeliveryZoneAvailable'), 'negative');
}
@ -109,9 +109,9 @@ const getShipped = async (params) => {
const onChangeZone = async (zoneId) => {
try {
_formData.value.agencyModeFk = null;
formData.value.agencyModeFk = null;
const { data } = await axios.get(`Zones/${zoneId}`);
_formData.value.agencyModeFk = data.agencyModeFk;
formData.value.agencyModeFk = data.agencyModeFk;
} catch (error) {
console.error(error);
}
@ -119,9 +119,9 @@ const onChangeZone = async (zoneId) => {
const onChangeAddress = async (addressId) => {
try {
_formData.value.nickname = null;
formData.value.nickname = null;
const { data } = await axios.get(`Addresses/${addressId}`);
_formData.value.nickname = data.nickname;
formData.value.nickname = data.nickname;
} catch (error) {
console.error(error);
}
@ -159,26 +159,26 @@ const clientAddressesList = async (value) => {
};
const addressId = computed({
get: () => _formData.value?.addressFk,
get: () => formData.value?.addressFk,
set: (val) => {
if (val != _formData.value?.addressFk) {
_formData.value.addressFk = val;
if (val != formData.value?.addressFk) {
formData.value.addressFk = val;
onChangeAddress(val);
getShipped({
landed: _formData.value?.landed,
landed: formData.value?.landed,
addressFk: val,
agencyModeFk: _formData.value?.agencyModeFk,
warehouseFk: _formData.value?.warehouseFk,
agencyModeFk: formData.value?.agencyModeFk,
warehouseFk: formData.value?.warehouseFk,
});
}
},
});
const clientId = computed({
get: () => _formData.value?.clientFk,
get: () => formData.value?.clientFk,
set: (val) => {
_formData.value.clientFk = val;
_formData.value.addressFk = null;
formData.value.clientFk = val;
formData.value.addressFk = null;
if (!val) return;
getClientDefaultAddress(val);
clientAddressesList(val);
@ -186,81 +186,81 @@ const clientId = computed({
});
const landed = computed({
get: () => _formData.value?.landed,
get: () => formData.value?.landed,
set: (val) => {
_formData.value.landed = val;
formData.value.landed = val;
getShipped({
landed: val,
addressFk: _formData.value?.addressFk,
agencyModeFk: _formData.value?.agencyModeFk,
warehouseFk: _formData.value?.warehouseFk,
addressFk: formData.value?.addressFk,
agencyModeFk: formData.value?.agencyModeFk,
warehouseFk: formData.value?.warehouseFk,
});
},
});
const agencyModeId = computed({
get: () => _formData.value.agencyModeFk,
get: () => formData.value.agencyModeFk,
set: (val) => {
if (val != _formData.value.agencyModeFk) {
_formData.value.agencyModeFk = val;
if (val != formData.value.agencyModeFk) {
formData.value.agencyModeFk = val;
if (!val) return;
const agencyMode = agenciesOptions.value.find((a) => a.id == val);
_formData.value.warehouseFk = agencyMode.warehouseFk;
formData.value.warehouseFk = agencyMode.warehouseFk;
getLanded({
shipped: _formData.value?.shipped,
addressFk: _formData.value?.addressFk,
shipped: formData.value?.shipped,
addressFk: formData.value?.addressFk,
agencyModeFk: val,
warehouseFk: _formData.value?.warehouseFk,
warehouseFk: formData.value?.warehouseFk,
});
}
},
});
const zoneId = computed({
get: () => _formData.value?.zoneFk,
get: () => formData.value?.zoneFk,
set: (val) => {
if (val != _formData.value?.zoneFk) {
_formData.value.zoneFk = val;
if (val != formData.value?.zoneFk) {
formData.value.zoneFk = val;
onChangeZone(val);
}
},
});
const warehouseId = computed({
get: () => _formData.value?.warehouseFk,
get: () => formData.value?.warehouseFk,
set: (val) => {
if (val != _formData.value?.warehouseFk) {
_formData.value.warehouseFk = val;
if (val != formData.value?.warehouseFk) {
formData.value.warehouseFk = val;
getShipped({
landed: _formData.value?.landed,
addressFk: _formData.value?.addressFk,
agencyModeFk: _formData.value?.agencyModeFk,
landed: formData.value?.landed,
addressFk: formData.value?.addressFk,
agencyModeFk: formData.value?.agencyModeFk,
warehouseFk: val,
}).then(() => {
if (zoneId.value == null) _formData.value.agencyModeFk = null;
if (zoneId.value == null) formData.value.agencyModeFk = null;
});
}
},
});
const shipped = computed({
get: () => _formData.value?.shipped,
get: () => formData.value?.shipped,
set: (val) => {
if (new Date(_formData.value?.shipped).toDateString() != val.toDateString())
if (new Date(formData.value?.shipped).toDateString() != val.toDateString())
val.setHours(0, 0, 0, 0);
_formData.value.shipped = val;
formData.value.shipped = val;
getLanded({
shipped: val,
addressFk: _formData.value?.addressFk,
agencyModeFk: _formData.value?.agencyModeFk,
warehouseFk: _formData.value?.warehouseFk,
addressFk: formData.value?.addressFk,
agencyModeFk: formData.value?.agencyModeFk,
warehouseFk: formData.value?.warehouseFk,
});
},
});
const onFormModelInit = () => {
if (_formData.value?.clientFk) clientAddressesList(_formData.value?.clientFk);
if (formData.value?.clientFk) clientAddressesList(formData.value?.clientFk);
};
const redirectToCustomerAddress = () => {
@ -398,14 +398,14 @@ onMounted(() => onFormModelInit());
</VnSelect>
<VnInput
:label="t('basicData.alias')"
v-model="_formData.nickname"
v-model="formData.nickname"
:required="true"
/>
</VnRow>
<VnRow class="row q-gutter-md q-mb-md no-wrap">
<VnSelect
:label="t('basicData.company')"
v-model="_formData.companyFk"
v-model="formData.companyFk"
option-value="id"
option-label="code"
:options="companiesOptions"
@ -450,17 +450,17 @@ onMounted(() => onFormModelInit());
<VnRow class="row q-gutter-md q-mb-md">
<VnInputDate
:label="t('basicData.shipped')"
v-model="_formData.shipped"
v-model="formData.shipped"
:required="true"
/>
<VnInputTime
:label="t('basicData.shippedHour')"
v-model="_formData.shipped"
v-model="formData.shipped"
:required="true"
/>
<VnInputDate
:label="t('basicData.landed')"
v-model="_formData.landed"
v-model="formData.landed"
:required="true"
/>
</VnRow>