From 44cbabfc7ed3e9ae1b5959cbc511c8ae2811603e Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 28 Nov 2024 13:27:53 +0100 Subject: [PATCH] feat: refs #7936 add number validation to VnInputNumber & new daysAgo filter in InvoiceInFilter --- src/components/common/VnInputNumber.vue | 2 ++ src/components/common/VnSelect.vue | 15 ++++++++++- src/i18n/locale/en.yml | 1 + src/i18n/locale/es.yml | 1 + src/pages/InvoiceIn/InvoiceInFilter.vue | 34 ++++++++++++++++++++++--- 5 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/components/common/VnInputNumber.vue b/src/components/common/VnInputNumber.vue index 460b39d63..165cfae3d 100644 --- a/src/components/common/VnInputNumber.vue +++ b/src/components/common/VnInputNumber.vue @@ -4,6 +4,7 @@ import VnInput from 'src/components/common/VnInput.vue'; defineProps({ step: { type: Number, default: 0.01 }, decimalPlaces: { type: Number, default: 2 }, + positive: { type: Boolean, default: true }, }); const model = defineModel({ type: [Number, String] }); @@ -17,6 +18,7 @@ const model = defineModel({ type: [Number, String] }); @input=" (evt) => { const val = evt.target.value; + if (positive && val < 0) return (model = 0); const [, decimal] = val.split('.'); if (val && decimal?.length > decimalPlaces) model = parseFloat(val).toFixed(decimalPlaces); diff --git a/src/components/common/VnSelect.vue b/src/components/common/VnSelect.vue index 7b12b2852..f62505d33 100644 --- a/src/components/common/VnSelect.vue +++ b/src/components/common/VnSelect.vue @@ -94,6 +94,10 @@ const $props = defineProps({ type: String, default: null, }, + isOutlined: { + type: Boolean, + default: false, + }, }); const mixinRules = [requiredFieldRule, ...($attrs.rules ?? [])]; @@ -108,6 +112,15 @@ const noOneOpt = ref({ [optionValue.value]: false, [optionLabel.value]: noOneText, }); +const styleAttrs = computed(() => { + return $props.isOutlined + ? { + dense: true, + outlined: true, + rounded: true, + } + : {}; +}); const isLoading = ref(false); const useURL = computed(() => $props.url); const value = computed({ @@ -267,7 +280,7 @@ defineExpose({ opts: myOptions }); :options="myOptions" :option-label="optionLabel" :option-value="optionValue" - v-bind="$attrs" + v-bind="{ ...$attrs, ...styleAttrs }" @filter="filterHandler" :emit-value="nullishToTrue($attrs['emit-value'])" :map-options="nullishToTrue($attrs['map-options'])" diff --git a/src/i18n/locale/en.yml b/src/i18n/locale/en.yml index fab1d0569..719a23217 100644 --- a/src/i18n/locale/en.yml +++ b/src/i18n/locale/en.yml @@ -341,6 +341,7 @@ globals: awbCode: AWB correctedFk: Rectified correctingFk: Rectificative + daysOnward: Days onward changePass: Change password deleteConfirmTitle: Delete selected elements changeState: Change state diff --git a/src/i18n/locale/es.yml b/src/i18n/locale/es.yml index e1080421d..40b9e4233 100644 --- a/src/i18n/locale/es.yml +++ b/src/i18n/locale/es.yml @@ -343,6 +343,7 @@ globals: serial: Serie amount: Importe awbCode: AWB + daysOnward: Días adelante changePass: Cambiar contraseña deleteConfirmTitle: Eliminar los elementos seleccionados changeState: Cambiar estado diff --git a/src/pages/InvoiceIn/InvoiceInFilter.vue b/src/pages/InvoiceIn/InvoiceInFilter.vue index 8f69bf262..653692026 100644 --- a/src/pages/InvoiceIn/InvoiceInFilter.vue +++ b/src/pages/InvoiceIn/InvoiceInFilter.vue @@ -4,12 +4,28 @@ import VnFilterPanel from 'src/components/ui/VnFilterPanel.vue'; import VnInput from 'src/components/common/VnInput.vue'; import VnInputDate from 'components/common/VnInputDate.vue'; import VnInputNumber from 'src/components/common/VnInputNumber.vue'; +import { dateRange } from 'src/filters'; +import { date } from 'quasar'; defineProps({ dataKey: { type: String, required: true } }); +const dateFormat = 'YYYY-MM-DDTHH:mm:ss.SSSZ'; + +function handleDaysAgo(params, daysAgo) { + const [from, to] = dateRange(Date.vnNew()); + if (!daysAgo && daysAgo !== 0) { + Object.assign(params, { from: undefined, to: undefined }); + } else { + from.setDate(from.getDate() - daysAgo); + Object.assign(params, { + from: date.formatDate(from, dateFormat), + to: date.formatDate(to, dateFormat), + }); + } +}