From e97f5f8d5fa6860128fbab52fca44be382bedbf9 Mon Sep 17 00:00:00 2001 From: xds Date: Mon, 7 Apr 2025 18:26:54 +0300 Subject: [PATCH] + prediction --- .../transactions/TransactionFormContent.vue | 94 ++++++++++++++----- src/services/categoryService.ts | 14 ++- 2 files changed, 82 insertions(+), 26 deletions(-) diff --git a/src/components/transactions/TransactionFormContent.vue b/src/components/transactions/TransactionFormContent.vue index 89a6682..2f651cc 100644 --- a/src/components/transactions/TransactionFormContent.vue +++ b/src/components/transactions/TransactionFormContent.vue @@ -16,7 +16,7 @@ import { updateTransactionRequest, deleteTransactionRequest, getTransactions } from "@/services/transactionService"; -import {getCategories, getCategoryTypes} from "@/services/categoryService"; +import {getCategories, getCategoriesPredict, getCategoryTypes} from "@/services/categoryService"; import {useToast} from "primevue/usetoast"; import LoadingView from "@/components/LoadingView.vue"; import BudgetTransactionView from "@/components/budgets/BudgetTransactionView.vue"; @@ -53,9 +53,13 @@ const categoryTypeChanged = () => { editedTransaction.value.category = selectedCategoryType.value.code == "EXPENSE" ? expenseCategories.value[0] : incomeCategories.value[0]; } -const selectCategory = (category) => { + +const isSelectedFromPredict = ref(); + +const selectCategory = (category, fromPredict: boolean) => { isCategorySelectorOpened.value = false; editedTransaction.value.category = category; + isSelectedFromPredict.value = fromPredict; }; @@ -70,6 +74,7 @@ const selectedTransactionType = ref(null); const selectedCategory = ref(null); const entireCategories = ref([]); +const predictedCategories = ref([]); const expenseCategories = ref([]); const incomeCategories = ref([]); const categoryTypes = ref([]); @@ -231,7 +236,18 @@ const createTransaction = async (): Promise => { }, 1000); }; - +const predictionsLoading = ref(false); +const anotherCategories = ref([]); +const fetchPredictions = async () => { + if (editedTransaction.value?.comment) { + predictedCategories.value = await getCategoriesPredict(editedTransaction.value?.comment); + } else { + predictedCategories.value = [] + } + predictedCategories.value.forEach((predictedCategory) => { + anotherCategories.value.push(entireCategories.value.find(category => predictedCategory.id != category.id)); + }) +} const transactionsUpdatedEmit = async () => { await getTransactions('INSTANT', 'EXPENSE', null, user.value.id, false, 3).then(transactionsResponse => transactions.value = transactionsResponse.data); @@ -286,7 +302,7 @@ const deleteTransaction = async () => { // Сброс формы const resetForm = () => { - + predictedCategories.value = [] // editedTransaction.value.date = new Date(); editedTransaction.value.amount = null; editedTransaction.value.comment = ''; @@ -387,26 +403,7 @@ onMounted(async () => { aria-labelledby="basic" @change="categoryTypeChanged" class="justify-center"/> - + @@ -417,7 +414,7 @@ onMounted(async () => { + + +
diff --git a/src/services/categoryService.ts b/src/services/categoryService.ts index 4506490..919857c 100644 --- a/src/services/categoryService.ts +++ b/src/services/categoryService.ts @@ -15,6 +15,16 @@ export const getCategories = async (type = null) => { }); }; +export const getCategoriesPredict = async (comment:string) => { + const spaceStore = await useSpaceStore(); + return await apiClient.get(`/spaces/${spaceStore.space?.id}/category-predict?comment=${comment}&cloud=0`) + .then(res => res.data) + .catch(err => { + throw err; + }); + +} + export const getCategoryTypes = async () => { const spaceStore = useSpaceStore(); return await apiClient.get(`/spaces/${spaceStore.space?.id}/categories/types`); @@ -42,7 +52,9 @@ export const deleteCategoryRequest = async (id: string) => { const spaceStore = useSpaceStore(); return await apiClient.delete(`/spaces/${spaceStore.space?.id}/categories/${id}`) .then(res => res.data) - .catch(err => {throw err}) + .catch(err => { + throw err + }) }; export const getCategoriesSumsRequest = async (spaceId: string) => {