From db783e15384163fdb7221afae2fc4e509e0c4c52 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 17 Sep 2024 15:03:30 +0200 Subject: [PATCH] refs #7283 item Descriptor --- src/composables/useArrayData.js | 1 + src/pages/Item/Card/ItemDescriptor.vue | 70 ++++++------- src/pages/Item/Card/ItemDescriptorImage.vue | 8 +- src/pages/Item/Card/ItemDiary.vue | 110 +++++++++++--------- 4 files changed, 98 insertions(+), 91 deletions(-) diff --git a/src/composables/useArrayData.js b/src/composables/useArrayData.js index 651bcefb0..6671632b3 100644 --- a/src/composables/useArrayData.js +++ b/src/composables/useArrayData.js @@ -246,6 +246,7 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) { } function updateStateParams() { + if (!route) return; const newUrl = { path: route.path, query: { ...(route.query ?? {}) } }; newUrl.query[store.searchUrl] = JSON.stringify(store.currentFilter); diff --git a/src/pages/Item/Card/ItemDescriptor.vue b/src/pages/Item/Card/ItemDescriptor.vue index baac0c608..a14ee1446 100644 --- a/src/pages/Item/Card/ItemDescriptor.vue +++ b/src/pages/Item/Card/ItemDescriptor.vue @@ -14,6 +14,7 @@ import useCardDescription from 'src/composables/useCardDescription'; import { getUrl } from 'src/composables/getUrl'; import axios from 'axios'; import { dashIfEmpty } from 'src/filters'; +import { useArrayData } from 'src/composables/useArrayData'; const $props = defineProps({ id: { @@ -49,58 +50,49 @@ const entityId = computed(() => { }); const regularizeStockFormDialog = ref(null); -const available = ref(null); -const visible = ref(null); const salixUrl = ref(); +const mounted = ref(); + +const arrayDataStock = useArrayData('descriptorStock', { + url: `Items/${entityId.value}/getVisibleAvailable`, +}); onMounted(async () => { - salixUrl.value = await getUrl(''); + salixUrl.value = await getUrl('getVisibleAvailable'); await getItemConfigs(); - await updateStock(); + mounted.value = true; }); const data = ref(useCardDescription()); const setData = async (entity) => { - try { - if (!entity) return; - data.value = useCardDescription(entity.name, entity.id); - await updateStock(); - } catch (err) { - console.error('Error item'); - } + if (!entity) return; + data.value = useCardDescription(entity.name, entity.id); + await updateStock(); }; const getItemConfigs = async () => { - try { - const { data } = await axios.get('ItemConfigs/findOne'); - if (!data) return; - return (warehouseConfig.value = data.warehouseFk); - } catch (err) { - console.error('Error item'); - } + const { data } = await axios.get('ItemConfigs/findOne'); + if (!data) return; + return (warehouseConfig.value = data.warehouseFk); }; const updateStock = async () => { - try { - available.value = null; - visible.value = null; + if (!mounted.value) return; + await getItemConfigs(); - const params = { - warehouseFk: $props.warehouseFk, - dated: $props.dated, - }; + const params = { + warehouseFk: $props.warehouseFk ?? warehouseConfig.value, + dated: $props.dated, + }; - await getItemConfigs(); - if (!params.warehouseFk) { - params.warehouseFk = warehouseConfig.value; - } - const { data } = await axios.get(`Items/${entityId.value}/getVisibleAvailable`, { - params, - }); - available.value = data.available; - visible.value = data.visible; - } catch (err) { - console.error('Error updating stock'); - } + if (!params.warehouseFk) return; + + const stock = useArrayData('descriptorStock', { + url: `Items/${entityId.value}/getVisibleAvailable`, + userParams: params, + }); + const storeData = stock.store.data; + if (storeData?.itemFk == entityId.value) return; + await stock.fetch({}); }; const openRegularizeStockForm = () => { @@ -163,8 +155,8 @@ const openCloneDialog = async () => {