fix(tahesab): stop repeating mande-by-codes on the customer sync list

Watching the paged array retriggered the same POST when mande was empty.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-01 21:38:19 +03:30
co-authored by Cursor
parent c7b1a75fbb
commit 848752756f
@@ -535,6 +535,7 @@ async function loadTahesab() {
status.value = res
}
tahesabOnlyList.value = res.tahesab_only_list?.data ?? []
mandeFetched.clear()
tahesabFetched.value = true
await enrichPageMande()
} catch (e) { console.error(e) }
@@ -730,21 +731,37 @@ async function linkPhones() {
}
}
const mandeFetched = new Set<number>()
let mandeInFlightKey = ''
async function enrichPageMande() {
const need = pagedTahesab.value.filter(c => c.gold == null && c.cash == null && c.code)
const need = pagedTahesab.value.filter(
c => c.code && !mandeFetched.has(c.code) && c.gold == null && c.cash == null,
)
if (!need.length) return
const key = need.map(c => c.code).join(',')
if (mandeInFlightKey === key) return
mandeInFlightKey = key
need.forEach(c => mandeFetched.add(c.code))
try {
const res = await fetchTahesabMandeByCodes(need.map(c => c.code))
const mandes = res.mandes || {}
tahesabOnlyList.value = tahesabOnlyList.value.map((c) => {
let changed = false
const next = tahesabOnlyList.value.map((c) => {
const m = mandes[String(c.code)]
if (!m) return c
return { ...c, gold: m.gold, cash: m.cash }
changed = true
return { ...c, gold: m.gold ?? 0, cash: m.cash ?? 0 }
})
} catch { /* ستون مانده اختیاری است */ }
if (changed) tahesabOnlyList.value = next
} catch {
need.forEach(c => mandeFetched.delete(c.code))
} finally {
if (mandeInFlightKey === key) mandeInFlightKey = ''
}
}
watch(pagedTahesab, () => { enrichPageMande() })
watch([tahesabPage, tahesabSearch], () => { void enrichPageMande() })
// با پیشرفت عملیات سراسری، ردیف‌های وارد شده را همین‌جا هم تیک بزن
watch(() => importStore.doneCodes.length, () => {