forked from verdnatura/salix-front
Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix-front into 7197-fixInvoiceIn
This commit is contained in:
commit
976f527107
|
@ -112,9 +112,7 @@ async function search(evt) {
|
|||
isLoading.value = true;
|
||||
const filter = { ...userParams.value };
|
||||
store.userParamsChanged = true;
|
||||
store.filter.skip = 0;
|
||||
store.skip = 0;
|
||||
store.page = 1;
|
||||
arrayData.reset(['skip', 'filter.skip', 'page']);
|
||||
const { params: newParams } = await arrayData.addFilter({ params: userParams.value });
|
||||
userParams.value = newParams;
|
||||
|
||||
|
@ -138,9 +136,7 @@ async function reload() {
|
|||
async function clearFilters() {
|
||||
isLoading.value = true;
|
||||
store.userParamsChanged = true;
|
||||
store.filter.skip = 0;
|
||||
store.skip = 0;
|
||||
store.page = 1;
|
||||
arrayData.reset(['skip', 'filter.skip', 'page']);
|
||||
// Filtrar los params no removibles
|
||||
const removableFilters = Object.keys(userParams.value).filter((param) =>
|
||||
$props.unremovableParams.includes(param)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<script setup>
|
||||
import { onMounted, ref, watch } from 'vue';
|
||||
import { onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useArrayData } from 'composables/useArrayData';
|
||||
|
||||
|
@ -95,6 +95,8 @@ onMounted(async () => {
|
|||
mounted.value = true;
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => arrayData.reset());
|
||||
|
||||
watch(
|
||||
() => props.data,
|
||||
() => {
|
||||
|
@ -118,8 +120,7 @@ const addFilter = async (filter, params) => {
|
|||
|
||||
async function fetch(params) {
|
||||
useArrayData(props.dataKey, params);
|
||||
store.filter.skip = 0;
|
||||
store.skip = 0;
|
||||
arrayData.reset(['filter.skip', 'skip']);
|
||||
await arrayData.fetch({ append: false });
|
||||
if (!store.hasMoreData) {
|
||||
isLoading.value = false;
|
||||
|
|
|
@ -103,8 +103,7 @@ async function search() {
|
|||
const staticParams = Object.entries(store.userParams).filter(
|
||||
([key, value]) => value && (props.staticParams || []).includes(key)
|
||||
);
|
||||
store.skip = 0;
|
||||
store.page = 1;
|
||||
arrayData.reset(['skip', 'page']);
|
||||
|
||||
if (props.makeFetch)
|
||||
await arrayData.applyFilter({
|
||||
|
|
|
@ -18,7 +18,8 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
|
|||
|
||||
onMounted(() => {
|
||||
setOptions();
|
||||
store.skip = 0;
|
||||
arrayDataStore.reset(['skip']);
|
||||
|
||||
const query = route.query;
|
||||
const searchUrl = store.searchUrl;
|
||||
if (query[searchUrl]) {
|
||||
|
@ -126,6 +127,10 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
|
|||
delete store[option];
|
||||
}
|
||||
|
||||
function reset(opts = []) {
|
||||
if (arrayDataStore.get(key)) arrayDataStore.reset(key, opts);
|
||||
}
|
||||
|
||||
function cancelRequest() {
|
||||
if (canceller) {
|
||||
canceller.abort();
|
||||
|
@ -149,9 +154,8 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
|
|||
userParams = sanitizerParams(userParams, store?.exprBuilder);
|
||||
|
||||
store.userParams = userParams;
|
||||
store.skip = 0;
|
||||
store.filter.skip = 0;
|
||||
store.page = 1;
|
||||
arrayDataStore.reset(['skip', 'filter.skip', 'page']);
|
||||
|
||||
await fetch({ append: false });
|
||||
return { filter, params };
|
||||
}
|
||||
|
@ -187,7 +191,6 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
|
|||
store.page += 1;
|
||||
|
||||
await fetch({ append: true });
|
||||
updateStateParams();
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
|
@ -241,5 +244,6 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
|
|||
updateStateParams,
|
||||
isLoading,
|
||||
deleteOption,
|
||||
reset,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ const { t } = useI18n();
|
|||
const route = useRoute();
|
||||
const stateStore = computed(() => useStateStore());
|
||||
const rows = ref([]);
|
||||
const totalAmount = ref(0);
|
||||
const totalAmount = ref();
|
||||
|
||||
const filter = {
|
||||
include: [
|
||||
|
@ -75,7 +75,7 @@ const columns = computed(() => [
|
|||
},
|
||||
{
|
||||
align: 'left',
|
||||
field: (value) => value.user.name,
|
||||
field: (value) => value?.user?.name,
|
||||
label: t('Created by'),
|
||||
name: 'createdBy',
|
||||
},
|
||||
|
@ -87,7 +87,7 @@ const columns = computed(() => [
|
|||
},
|
||||
{
|
||||
align: 'left',
|
||||
field: (value) => value.greugeType.name,
|
||||
field: (value) => value?.greugeType?.name,
|
||||
label: t('Type'),
|
||||
name: 'type',
|
||||
},
|
||||
|
@ -108,26 +108,9 @@ const setRows = (data) => {
|
|||
|
||||
<template>
|
||||
<FetchData :filter="filter" @on-fetch="setRows" auto-load url="greuges" />
|
||||
<template v-if="stateStore.isHeaderMounted()">
|
||||
<Teleport to="#actions-append">
|
||||
<div class="row q-gutter-x-sm">
|
||||
<QBtn
|
||||
flat
|
||||
@click="stateStore.toggleRightDrawer()"
|
||||
round
|
||||
dense
|
||||
icon="menu"
|
||||
>
|
||||
<QTooltip bottom anchor="bottom right">
|
||||
{{ t('globals.collapseMenu') }}
|
||||
</QTooltip>
|
||||
</QBtn>
|
||||
</div>
|
||||
</Teleport>
|
||||
</template>
|
||||
<QDrawer v-model="stateStore.rightDrawer" side="right" :width="300" show-if-above>
|
||||
<QCard class="full-width q-pa-sm">
|
||||
<h6 class="flex justify-end q-my-lg q-pr-lg" v-if="totalAmount">
|
||||
<h6 class="flex justify-end q-my-lg q-pr-lg" v-if="totalAmount !== undefined">
|
||||
<span class="color-vn-label q-mr-md">{{ t('Total') }}:</span>
|
||||
{{ toCurrency(totalAmount) }}
|
||||
</h6>
|
||||
|
|
|
@ -3,13 +3,7 @@ import { defineStore } from 'pinia';
|
|||
|
||||
export const useArrayDataStore = defineStore('arrayDataStore', () => {
|
||||
const state = ref({});
|
||||
|
||||
function get(key) {
|
||||
return state.value[key];
|
||||
}
|
||||
|
||||
function set(key) {
|
||||
state.value[key] = {
|
||||
const defaultOpts = {
|
||||
filter: {},
|
||||
userFilter: {},
|
||||
userParams: {},
|
||||
|
@ -17,7 +11,6 @@ export const useArrayDataStore = defineStore('arrayDataStore', () => {
|
|||
limit: 10,
|
||||
skip: 0,
|
||||
order: '',
|
||||
data: ref(),
|
||||
isLoading: false,
|
||||
userParamsChanged: false,
|
||||
exprBuilder: null,
|
||||
|
@ -25,15 +18,41 @@ export const useArrayDataStore = defineStore('arrayDataStore', () => {
|
|||
navigate: null,
|
||||
page: 1,
|
||||
};
|
||||
|
||||
function get(key) {
|
||||
return state.value[key];
|
||||
}
|
||||
|
||||
function set(key) {
|
||||
state.value[key] = getDefaultState();
|
||||
}
|
||||
|
||||
function clear(key) {
|
||||
delete state.value[key];
|
||||
}
|
||||
|
||||
function reset(key, opts = []) {
|
||||
if (!opts.length) state.value[key] = getDefaultState();
|
||||
else
|
||||
opts.forEach((opt) => {
|
||||
if (opt.includes('.')) {
|
||||
const [parent, child] = opt.split('.');
|
||||
state.value[key][parent][child] = defaultOpts[child];
|
||||
} else if (Object.hasOwn(state.value[key], opt))
|
||||
state.value[key][opt] = defaultOpts[opt];
|
||||
});
|
||||
}
|
||||
|
||||
function getDefaultState() {
|
||||
return Object.assign(JSON.parse(JSON.stringify(defaultOpts)), {
|
||||
data: ref(),
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
get,
|
||||
set,
|
||||
clear,
|
||||
reset,
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue