This commit is contained in:
parent
b3cb67f217
commit
a89748827f
|
@ -45,7 +45,7 @@ onMounted(async () => {
|
||||||
async function fetch(fetchFilter = {}) {
|
async function fetch(fetchFilter = {}) {
|
||||||
try {
|
try {
|
||||||
const filter = Object.assign(fetchFilter, $props.filter); // eslint-disable-line vue/no-dupe-keys
|
const filter = Object.assign(fetchFilter, $props.filter); // eslint-disable-line vue/no-dupe-keys
|
||||||
if ($props.where) filter.where = $props.where;
|
if ($props.where && !fetchFilter.where) filter.where = $props.where;
|
||||||
if ($props.sortBy) filter.order = $props.sortBy;
|
if ($props.sortBy) filter.order = $props.sortBy;
|
||||||
if ($props.limit) filter.limit = $props.limit;
|
if ($props.limit) filter.limit = $props.limit;
|
||||||
|
|
||||||
|
@ -54,6 +54,7 @@ async function fetch(fetchFilter = {}) {
|
||||||
});
|
});
|
||||||
|
|
||||||
emit('onFetch', data);
|
emit('onFetch', data);
|
||||||
|
return data;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import FetchData from 'src/components/FetchData.vue';
|
import FetchData from 'src/components/FetchData.vue';
|
||||||
|
import { onMounted } from 'vue';
|
||||||
import { ref, toRefs, computed, watch } from 'vue';
|
import { ref, toRefs, computed, watch } from 'vue';
|
||||||
const emit = defineEmits(['update:modelValue', 'update:options']);
|
const emit = defineEmits(['update:modelValue', 'update:options']);
|
||||||
const dataRef = ref();
|
|
||||||
|
|
||||||
const $props = defineProps({
|
const $props = defineProps({
|
||||||
modelValue: {
|
modelValue: {
|
||||||
|
@ -37,12 +37,29 @@ const $props = defineProps({
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true,
|
default: true,
|
||||||
},
|
},
|
||||||
|
fields: {
|
||||||
|
type: Array,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
type: Object,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
sortBy: {
|
||||||
|
type: String,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
limit: {
|
||||||
|
type: Number,
|
||||||
|
default: 30,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const { optionLabel, options } = toRefs($props);
|
const { optionLabel, optionValue, options, modelValue } = toRefs($props);
|
||||||
const myOptions = ref([]);
|
const myOptions = ref([]);
|
||||||
const myOptionsOriginal = ref([]);
|
const myOptionsOriginal = ref([]);
|
||||||
const vnSelectRef = ref();
|
const vnSelectRef = ref();
|
||||||
|
const dataRef = ref();
|
||||||
|
|
||||||
const value = computed({
|
const value = computed({
|
||||||
get() {
|
get() {
|
||||||
|
@ -57,8 +74,12 @@ function setOptions(data) {
|
||||||
myOptions.value = JSON.parse(JSON.stringify(data));
|
myOptions.value = JSON.parse(JSON.stringify(data));
|
||||||
myOptionsOriginal.value = JSON.parse(JSON.stringify(data));
|
myOptionsOriginal.value = JSON.parse(JSON.stringify(data));
|
||||||
}
|
}
|
||||||
setOptions(options.value);
|
onMounted(() => {
|
||||||
const filter = (val, options) => {
|
setOptions(options.value);
|
||||||
|
if ($props.url && $props.modelValue) fetchFilter($props.modelValue);
|
||||||
|
});
|
||||||
|
|
||||||
|
async function filter(val, options) {
|
||||||
const search = val.toString().toLowerCase();
|
const search = val.toString().toLowerCase();
|
||||||
|
|
||||||
if (!search) return options;
|
if (!search) return options;
|
||||||
|
@ -76,14 +97,30 @@ const filter = (val, options) => {
|
||||||
|
|
||||||
return id == search || optionLabel.includes(search);
|
return id == search || optionLabel.includes(search);
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
const filterHandler = (val, update) => {
|
async function fetchFilter(val) {
|
||||||
|
console.log('ENTRY PA', dataRef.value);
|
||||||
|
if (!$props.url || !dataRef.value) return;
|
||||||
|
|
||||||
|
const { fields, sortBy, limit } = $props;
|
||||||
|
let key = optionLabel.value;
|
||||||
|
|
||||||
|
if (new RegExp(/\d/g).test(val)) key = optionValue.value;
|
||||||
|
|
||||||
|
const where = { [key]: { like: `%${val}%` } };
|
||||||
|
return dataRef.value.fetch({ fields, where, order: sortBy, limit });
|
||||||
|
}
|
||||||
|
|
||||||
|
async function filterHandler(val, update) {
|
||||||
update(
|
update(
|
||||||
() => {
|
async () => {
|
||||||
if ($props.url) return;
|
if (!$props.defaultFilter) return;
|
||||||
if ($props.defaultFilter)
|
if ($props.url) {
|
||||||
myOptions.value = filter(val, myOptionsOriginal.value);
|
myOptions.value = await fetchFilter(val);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
myOptions.value = await filter(val, myOptionsOriginal.value);
|
||||||
},
|
},
|
||||||
(ref) => {
|
(ref) => {
|
||||||
if (val !== '' && ref.options.length > 0) {
|
if (val !== '' && ref.options.length > 0) {
|
||||||
|
@ -92,25 +129,34 @@ const filterHandler = (val, update) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
watch(options, (newValue) => {
|
watch(options, (newValue) => {
|
||||||
|
console.log(newValue);
|
||||||
setOptions(newValue);
|
setOptions(newValue);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
watch(modelValue, (newValue) => {
|
||||||
|
if (!myOptions.value.some((option) => option[optionValue.value] == newValue))
|
||||||
|
fetchFilter(newValue);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<FetchData
|
<FetchData
|
||||||
v-if="$props.url"
|
|
||||||
ref="dataRef"
|
ref="dataRef"
|
||||||
:url="$props.url"
|
:url="$props.url"
|
||||||
@on-fetch="(data) => setOptions(data)"
|
@on-fetch="(data) => setOptions(data)"
|
||||||
auto-load
|
:where="where || { [optionValue]: value }"
|
||||||
|
:limit="limit || 30"
|
||||||
|
:order-by="orderBy"
|
||||||
|
:fields="fields"
|
||||||
/>
|
/>
|
||||||
<QSelect
|
<QSelect
|
||||||
v-model="value"
|
v-model="value"
|
||||||
:options="myOptions"
|
:options="myOptions"
|
||||||
:option-label="optionLabel"
|
:option-label="optionLabel"
|
||||||
|
:option-value="optionValue"
|
||||||
v-bind="$attrs"
|
v-bind="$attrs"
|
||||||
emit-value
|
emit-value
|
||||||
map-options
|
map-options
|
||||||
|
|
|
@ -182,8 +182,8 @@ const columns = computed(() => [
|
||||||
</QItemLabel>
|
</QItemLabel>
|
||||||
</QItemSection>
|
</QItemSection>
|
||||||
</QItem>
|
</QItem>
|
||||||
</template>
|
</template> </VnSelectFilter
|
||||||
</VnSelectFilter>
|
>s
|
||||||
</QTd>
|
</QTd>
|
||||||
</template>
|
</template>
|
||||||
<template #item="props">
|
<template #item="props">
|
||||||
|
|
|
@ -4,10 +4,12 @@ import { useRoute } from 'vue-router';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useQuasar } from 'quasar';
|
import { useQuasar } from 'quasar';
|
||||||
import { useArrayData } from 'src/composables/useArrayData';
|
import { useArrayData } from 'src/composables/useArrayData';
|
||||||
|
|
||||||
import { downloadFile } from 'src/composables/downloadFile';
|
import { downloadFile } from 'src/composables/downloadFile';
|
||||||
|
|
||||||
import FormModel from 'components/FormModel.vue';
|
import FormModel from 'components/FormModel.vue';
|
||||||
import VnSelectFilter from 'src/components/common/VnSelectFilter.vue';
|
import VnSelectFilter from 'src/components/common/VnSelectFilter.vue';
|
||||||
|
import FetchData from 'src/components/FetchData.vue';
|
||||||
|
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
const quasar = useQuasar();
|
const quasar = useQuasar();
|
||||||
|
@ -20,9 +22,6 @@ const arrayData = useArrayData('InvoiceIn');
|
||||||
const invoiceIn = computed(() => arrayData.store.data);
|
const invoiceIn = computed(() => arrayData.store.data);
|
||||||
const userConfig = ref(null);
|
const userConfig = ref(null);
|
||||||
|
|
||||||
const suppliers = ref([]);
|
|
||||||
const suppliersRef = ref();
|
|
||||||
const suppliersRefFilter = ref({ fields: ['id', 'nickname'], limit: 30 });
|
|
||||||
const currencies = ref([]);
|
const currencies = ref([]);
|
||||||
const currenciesRef = ref();
|
const currenciesRef = ref();
|
||||||
const companies = ref([]);
|
const companies = ref([]);
|
||||||
|
@ -130,31 +129,13 @@ async function upsert() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function supplierRefFilter(val) {
|
|
||||||
let where = { limit: 30 };
|
|
||||||
let params = {};
|
|
||||||
let key = 'nickname';
|
|
||||||
|
|
||||||
if (new RegExp(/\d/g).test(val)) {
|
|
||||||
key = 'id';
|
|
||||||
}
|
|
||||||
params = { [key]: { like: `%${val}%` } };
|
|
||||||
where = Object.assign(where, params);
|
|
||||||
suppliersRef.value.fetch({ where });
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<!-- <FetchData
|
<FetchData
|
||||||
ref="suppliersRef"
|
|
||||||
url="Suppliers"
|
|
||||||
@on-fetch="(data) => (suppliers = data)"
|
|
||||||
/> -->
|
|
||||||
<!-- <FetchData
|
|
||||||
ref="currenciesRef"
|
ref="currenciesRef"
|
||||||
url="Currencies"
|
url="Currencies"
|
||||||
:filter="{ fields: ['id', 'code'] }"
|
:filter="{ fields: ['id', 'code'] }"
|
||||||
order="code"
|
sort-by="code"
|
||||||
@on-fetch="(data) => (currencies = data)"
|
@on-fetch="(data) => (currencies = data)"
|
||||||
auto-load
|
auto-load
|
||||||
/>
|
/>
|
||||||
|
@ -162,7 +143,7 @@ function supplierRefFilter(val) {
|
||||||
ref="companiesRef"
|
ref="companiesRef"
|
||||||
url="Companies"
|
url="Companies"
|
||||||
:filter="{ fields: ['id', 'code'] }"
|
:filter="{ fields: ['id', 'code'] }"
|
||||||
order="code"
|
sort-by="code"
|
||||||
@on-fetch="(data) => (companies = data)"
|
@on-fetch="(data) => (companies = data)"
|
||||||
auto-load
|
auto-load
|
||||||
/>
|
/>
|
||||||
|
@ -170,7 +151,7 @@ function supplierRefFilter(val) {
|
||||||
ref="dmsTypesRef"
|
ref="dmsTypesRef"
|
||||||
url="DmsTypes"
|
url="DmsTypes"
|
||||||
:filter="{ fields: ['id', 'name'] }"
|
:filter="{ fields: ['id', 'name'] }"
|
||||||
order="name"
|
sort-by="name"
|
||||||
@on-fetch="(data) => (dmsTypes = data)"
|
@on-fetch="(data) => (dmsTypes = data)"
|
||||||
auto-load
|
auto-load
|
||||||
/>
|
/>
|
||||||
|
@ -178,7 +159,7 @@ function supplierRefFilter(val) {
|
||||||
ref="warehousesRef"
|
ref="warehousesRef"
|
||||||
url="Warehouses"
|
url="Warehouses"
|
||||||
:filter="{ fields: ['id', 'name'] }"
|
:filter="{ fields: ['id', 'name'] }"
|
||||||
order="name"
|
sort-by="name"
|
||||||
@on-fetch="(data) => (warehouses = data)"
|
@on-fetch="(data) => (warehouses = data)"
|
||||||
auto-load
|
auto-load
|
||||||
/>
|
/>
|
||||||
|
@ -192,7 +173,7 @@ function supplierRefFilter(val) {
|
||||||
url="UserConfigs/getUserConfig"
|
url="UserConfigs/getUserConfig"
|
||||||
@on-fetch="(data) => (userConfig = data)"
|
@on-fetch="(data) => (userConfig = data)"
|
||||||
auto-load
|
auto-load
|
||||||
/> -->
|
/>
|
||||||
<FormModel v-if="invoiceIn" :url="`InvoiceIns/${route.params.id}`" model="invoiceIn">
|
<FormModel v-if="invoiceIn" :url="`InvoiceIns/${route.params.id}`" model="invoiceIn">
|
||||||
<template #form="{ data }">
|
<template #form="{ data }">
|
||||||
<div class="row q-gutter-md q-mb-md">
|
<div class="row q-gutter-md q-mb-md">
|
||||||
|
@ -200,12 +181,11 @@ function supplierRefFilter(val) {
|
||||||
<VnSelectFilter
|
<VnSelectFilter
|
||||||
:label="t('supplierFk')"
|
:label="t('supplierFk')"
|
||||||
v-model="data.supplierFk"
|
v-model="data.supplierFk"
|
||||||
option-value="id
|
option-value="id"
|
||||||
"
|
|
||||||
option-label="nickname"
|
option-label="nickname"
|
||||||
url="Suppliers"
|
url="Suppliers"
|
||||||
:filter="{ fields: ['id', 'code'], order: 'code' }"
|
:fields="['id', 'nickname']"
|
||||||
@update-options="(data) => (suppliersRef = data)"
|
sort-by="nickname"
|
||||||
>
|
>
|
||||||
<template #option="scope">
|
<template #option="scope">
|
||||||
<QItem v-bind="scope.itemProps">
|
<QItem v-bind="scope.itemProps">
|
||||||
|
@ -416,7 +396,6 @@ function supplierRefFilter(val) {
|
||||||
<div class="row q-gutter-md q-mb-md">
|
<div class="row q-gutter-md q-mb-md">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<VnSelectFilter
|
<VnSelectFilter
|
||||||
url="Currencies"
|
|
||||||
:label="t('Currency')"
|
:label="t('Currency')"
|
||||||
v-model="data.currencyFk"
|
v-model="data.currencyFk"
|
||||||
:options="currencies"
|
:options="currencies"
|
||||||
|
|
Loading…
Reference in New Issue