Fix offline entry detail saving
This commit is contained in:
parent
0150a29e88
commit
c2bb2e63a2
|
|
@ -147,6 +147,7 @@ export const useEntryStore = defineStore("entries", {
|
|||
const updated: LedgerEntry = {
|
||||
...existing,
|
||||
...entry,
|
||||
ledgerIds: [...new Set(entry.ledgerIds)],
|
||||
updatedAt: new Date().toISOString(),
|
||||
updatedBy: auth.user?.id ?? existing.updatedBy,
|
||||
version: existing.version + 1,
|
||||
|
|
|
|||
|
|
@ -163,21 +163,27 @@ async function saveEntry() {
|
|||
|
||||
saving.value = true;
|
||||
errorMessage.value = "";
|
||||
const cents = Math.round(numericAmount * 100);
|
||||
const exchangeRate = Number(entry.value.exchangeRate) || 1;
|
||||
const updated = await store.updateEntry({
|
||||
...entry.value,
|
||||
amount: cents,
|
||||
baseAmount: Math.round(cents * exchangeRate),
|
||||
ledgerIds: ledgerIds.value,
|
||||
categoryId: childCategoryId.value || parentCategoryId.value,
|
||||
note: note.value.trim(),
|
||||
occurredAt: occurredDate.toISOString(),
|
||||
});
|
||||
hydrate(updated);
|
||||
saving.value = false;
|
||||
savedToast.value = true;
|
||||
window.setTimeout(() => (savedToast.value = false), 1600);
|
||||
try {
|
||||
const cents = Math.round(numericAmount * 100);
|
||||
const exchangeRate = Number(entry.value.exchangeRate) || 1;
|
||||
const updated = await store.updateEntry({
|
||||
...entry.value,
|
||||
amount: cents,
|
||||
baseAmount: Math.round(cents * exchangeRate),
|
||||
ledgerIds: [...ledgerIds.value],
|
||||
categoryId: childCategoryId.value || parentCategoryId.value,
|
||||
note: note.value.trim(),
|
||||
occurredAt: occurredDate.toISOString(),
|
||||
});
|
||||
hydrate(updated);
|
||||
savedToast.value = true;
|
||||
window.setTimeout(() => (savedToast.value = false), 1600);
|
||||
} catch (error) {
|
||||
console.error("Failed to save entry locally", error);
|
||||
errorMessage.value = "保存失败,请重试";
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteEntry() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue