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 = {
|
const updated: LedgerEntry = {
|
||||||
...existing,
|
...existing,
|
||||||
...entry,
|
...entry,
|
||||||
|
ledgerIds: [...new Set(entry.ledgerIds)],
|
||||||
updatedAt: new Date().toISOString(),
|
updatedAt: new Date().toISOString(),
|
||||||
updatedBy: auth.user?.id ?? existing.updatedBy,
|
updatedBy: auth.user?.id ?? existing.updatedBy,
|
||||||
version: existing.version + 1,
|
version: existing.version + 1,
|
||||||
|
|
|
||||||
|
|
@ -163,21 +163,27 @@ async function saveEntry() {
|
||||||
|
|
||||||
saving.value = true;
|
saving.value = true;
|
||||||
errorMessage.value = "";
|
errorMessage.value = "";
|
||||||
|
try {
|
||||||
const cents = Math.round(numericAmount * 100);
|
const cents = Math.round(numericAmount * 100);
|
||||||
const exchangeRate = Number(entry.value.exchangeRate) || 1;
|
const exchangeRate = Number(entry.value.exchangeRate) || 1;
|
||||||
const updated = await store.updateEntry({
|
const updated = await store.updateEntry({
|
||||||
...entry.value,
|
...entry.value,
|
||||||
amount: cents,
|
amount: cents,
|
||||||
baseAmount: Math.round(cents * exchangeRate),
|
baseAmount: Math.round(cents * exchangeRate),
|
||||||
ledgerIds: ledgerIds.value,
|
ledgerIds: [...ledgerIds.value],
|
||||||
categoryId: childCategoryId.value || parentCategoryId.value,
|
categoryId: childCategoryId.value || parentCategoryId.value,
|
||||||
note: note.value.trim(),
|
note: note.value.trim(),
|
||||||
occurredAt: occurredDate.toISOString(),
|
occurredAt: occurredDate.toISOString(),
|
||||||
});
|
});
|
||||||
hydrate(updated);
|
hydrate(updated);
|
||||||
saving.value = false;
|
|
||||||
savedToast.value = true;
|
savedToast.value = true;
|
||||||
window.setTimeout(() => (savedToast.value = false), 1600);
|
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() {
|
async function deleteEntry() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue