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> <template>
<LoadingView v-if="loading"/> <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"> <div class="!items-center w-5/6 bg-white">
<Accordion value="1" class=" " @tab-open="isChartOpen=true" <Accordion value="1" class=" " @tab-open="isChartOpen=true"
@tab-close="closeChart"> @tab-close="closeChart">

View File

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

View File

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

View File

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

View File

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

View File

@@ -62,7 +62,7 @@ export const getBudgetCategoriesSums = async (budgetId) => {
return response.data; 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); let budgetInfo = await apiClient.get('/budgets/' + budget_id);
budgetInfo = budgetInfo.data; budgetInfo = budgetInfo.data;