This commit is contained in:
xds
2025-02-01 16:27:54 +03:00
parent 9369285b44
commit 98f3d4baa4
6 changed files with 73 additions and 58 deletions

View File

@@ -227,7 +227,7 @@ onMounted(async () => {
<template>
<LoadingView v-if="loading"/>
<div v-else class="p-4 bg-gray-100 flex flex-col gap-4 items-center justify-items-center ">
<div v-else class="p-4 pb-20 lg:pb-4 bg-gray-100 flex flex-col gap-4 items-center justify-items-center ">
<div class="!items-center w-5/6 bg-white">
<Accordion value="1" class=" " @tab-open="isChartOpen=true"
@tab-close="closeChart">

View File

@@ -89,8 +89,6 @@ const creationOpened = ref(false)
const creationSuccessModal = ref(false)
const creationSuccessShow = async (budget, createRecurrentPayments) => {
try {
await createBudget(budget, createRecurrentPayments)
budgetInfos.value = await getBudgetInfos()

View File

@@ -562,11 +562,10 @@ const fetchBudgetTransactions = async () => {
}
const updateTransactions = async () => {
setTimeout(async () => {
await Promise.all([fetchBudgetInfo(),fetchWarns()])
}, 10)
}, )
}
@@ -608,14 +607,16 @@ const transactionCategoriesSums = computed(() => {
const budgetInfo = ref<Budget>();
const fetchBudgetInfo = async () => {
budget.value = await getBudgetInfo(route.params.id);
plannedExpenses.value = budget.value?.plannedExpenses.copyWithin()
plannedIncomes.value = budget.value?.plannedIncomes.copyWithin()
transactions.value = budget.value?.transactions.copyWithin()
await getBudgetInfo(route.params.id).then((data) => {
budget.value = data
plannedExpenses.value = budget.value?.plannedExpenses
plannedIncomes.value = budget.value?.plannedIncomes
transactions.value = budget.value?.transactions
categories.value = budget.value?.categories
updateLoading.value = false
}
)
}
@@ -626,7 +627,7 @@ const updateBudgetCategory = async (category) => {
await fetchBudgetInfo()
setTimeout(async () => {
await fetchWarns()
}, 500)
}, 0)
// categories.value = await getBudgetCategories(route.params.id)
@@ -861,10 +862,6 @@ onMounted(async () => {
} finally {
loading.value = false
}
setTimeout(() => {
}, 100)
});
</script>

View File

@@ -164,11 +164,14 @@ const createTransaction = async () => {
if (editedTransaction.value.transactionType.code === 'INSTANT') {
editedTransaction.value.isDone = true;
}
await createTransactionRequest(editedTransaction.value);
await createTransactionRequest(editedTransaction.value).then((result) => {
console.log("hereeeee");
toast.add({severity: 'success', summary: 'Transaction created!', detail: 'Транзакция создана!', life: 3000});
emit('create-transaction', editedTransaction.value);
computeResult(true)
resetForm();
})
} catch (error) {
computeResult(false, error)
console.error('Error creating transaction:', error);

View File

@@ -159,44 +159,60 @@ const showError = (message) => {
// Создание транзакции
const amountInput = ref(null);
const createTransaction = async () => {
if (checkForm()) {
const createTransaction = async (): Promise<void> => {
if (!checkForm()) return;
try {
// loading.value = true;
// Если тип транзакции INSTANT, помечаем её как выполненную
if (editedTransaction.value.type.code === 'INSTANT') {
editedTransaction.value.isDone = true;
}
await createTransactionRequest(editedTransaction.value).then
{
// Отправляем запрос на создание транзакции и ждём результата
const result = await createTransactionRequest(editedTransaction.value);
// Сбрасываем состояние загрузки
loading.value = false;
amountInput.value.$el.querySelector('input').focus()
// Фокусируем поле ввода суммы (при наличии)
const inputEl = amountInput.value.$el.querySelector('input') as HTMLInputElement | null;
if (inputEl) {
inputEl.focus();
}
// setTimeout(async () => {
//
// amountInput.value.$el.querySelector('input').focus()
// }, 0)
// Вызываем событие создания транзакции и обновляем список транзакций
emit('create-transaction', editedTransaction.value);
await transactionsUpdatedEmit()
toast.add({severity: 'success', summary: 'Успешно!', detail: 'Транзакция создана!', life: 3000});
// computeResult(true)
await transactionsUpdatedEmit();
// Показываем уведомление об успешном создании транзакции
toast.add({
severity: 'success',
summary: 'Успешно!',
detail: 'Транзакция создана!',
life: 3000
});
// Сбрасываем форму
resetForm();
} catch (error) {
// computeResult(false, error)
toast.add({severity: 'error', summary: 'Ошибка!', detail: error.response.data["message"], life: 3000});
} catch (error: any) {
// Обработка ошибки: выводим уведомление с сообщением об ошибке
toast.add({
severity: 'error',
summary: 'Ошибка!',
detail: error.response?.data?.message || 'Ошибка при создании транзакции',
life: 3000
});
console.error('Error creating transaction:', error);
} finally {
loading.value = false;
}
}
// Через 1 секунду обнуляем дополнительные значения
setTimeout(() => {
result.value = false
resultText.value = ''
}, 1000)
result.value = false;
resultText.value = '';
}, 1000);
};
@@ -439,7 +455,8 @@ onMounted(async () => {
</FloatLabel>
</div>
<div class="flex flex-col gap-1">
<BudgetTransactionView v-if="!isEditing && transactions" v-for="transaction in transactions" :is-list="true" class="flex flexgap-4"
<BudgetTransactionView v-if="!isEditing && transactions" v-for="transaction in transactions" :is-list="true"
class="flex flexgap-4"
:transaction="transaction"/>
</div>

View File

@@ -62,7 +62,7 @@ export const getBudgetCategoriesSums = async (budgetId) => {
return response.data;
}
export const getBudgetInfo = async (budget_id: number) => {
export const getBudgetInfo = async (budget_id: string) => {
let budgetInfo = await apiClient.get('/budgets/' + budget_id);
budgetInfo = budgetInfo.data;