fix somw bug
This commit is contained in:
@@ -158,20 +158,6 @@
|
||||
title="کد حسابداری"
|
||||
:value="accountingCodeValue"
|
||||
/>
|
||||
<div
|
||||
v-if="pargarWalletSyncVisible"
|
||||
class="col-span-2 flex items-end md:col-span-3 xl:col-span-4"
|
||||
>
|
||||
<a-button
|
||||
type="primary"
|
||||
ghost
|
||||
size="small"
|
||||
:loading="pargarSyncLoading"
|
||||
@click="syncPargarWallet"
|
||||
>
|
||||
دریافت مانده از پرگار
|
||||
</a-button>
|
||||
</div>
|
||||
<BasicInfoItem
|
||||
title="تاریخ تولد"
|
||||
:value="userInfo?.birth_date ? toJalaliNoTime(userInfo?.birth_date) : '_'"
|
||||
@@ -204,22 +190,36 @@
|
||||
</BasicInfoItem>
|
||||
</div>
|
||||
|
||||
<CustomerWalletBalancePanel
|
||||
v-if="userInfo?.id && isMobile"
|
||||
ref="walletPanelMobile"
|
||||
:customer-id="userInfo.id"
|
||||
compact
|
||||
:charge-targets="infoChargeTargets"
|
||||
:interactive="false"
|
||||
class="mt-2"
|
||||
/>
|
||||
<div v-if="userInfo?.id && isMobile" class="mt-2 space-y-2">
|
||||
<PargarWalletSyncAction
|
||||
v-if="pargarWalletSyncVisible"
|
||||
:loading="pargarSyncLoading"
|
||||
:can-sync="pargarWalletCanSync"
|
||||
@sync="syncPargarWallet"
|
||||
/>
|
||||
<CustomerWalletBalancePanel
|
||||
:key="`wallet-mobile-${walletPanelKey}`"
|
||||
ref="walletPanelMobile"
|
||||
:customer-id="userInfo.id"
|
||||
compact
|
||||
:charge-targets="infoChargeTargets"
|
||||
:interactive="false"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<aside
|
||||
v-if="userInfo?.id && !isMobile"
|
||||
class="surface-muted min-w-0 rounded-xl border border-base p-2.5 lg:order-1 lg:sticky lg:top-0"
|
||||
>
|
||||
<PargarWalletSyncAction
|
||||
v-if="pargarWalletSyncVisible"
|
||||
:loading="pargarSyncLoading"
|
||||
:can-sync="pargarWalletCanSync"
|
||||
@sync="syncPargarWallet"
|
||||
/>
|
||||
<CustomerWalletBalancePanel
|
||||
:key="`wallet-desktop-${walletPanelKey}`"
|
||||
ref="walletPanelDesktop"
|
||||
:customer-id="userInfo.id"
|
||||
layout="sidebar"
|
||||
@@ -300,11 +300,11 @@ import type { DashboardHelp } from '@/pages/dashboard/dashboardSectionCopy'
|
||||
import DashboardLabelWithHelp from '@/pages/dashboard/components/DashboardLabelWithHelp.vue'
|
||||
import {
|
||||
accountingProviderSetting,
|
||||
initAccountingSettingsFromApi,
|
||||
pargarEnabledSetting
|
||||
initAccountingSettingsFromApi
|
||||
} from '@/utils/config'
|
||||
import { displayAccountingCode, isValidAccountingCode } from '@/utils/accountingCode'
|
||||
import { syncCustomerWalletFromPargar } from '@/api/pargar'
|
||||
import { syncCustomerWalletFromPargar, type PargarSyncWalletResult } from '@/api/pargar'
|
||||
import PargarWalletSyncAction from './components/PargarWalletSyncAction.vue'
|
||||
|
||||
const fnameHelp: DashboardHelp = {
|
||||
description: 'نام کوچک مشتری که در اپ و پنل نمایش داده میشود.',
|
||||
@@ -572,30 +572,67 @@ const accountingCodeValue = computed(() => {
|
||||
})
|
||||
|
||||
const pargarSyncLoading = ref(false)
|
||||
const walletPanelDesktop = ref<{ reload?: () => void } | null>(null)
|
||||
const walletPanelMobile = ref<{ reload?: () => void } | null>(null)
|
||||
const walletPanelDesktop = ref<{ reload?: () => void | Promise<void> } | null>(null)
|
||||
const walletPanelMobile = ref<{ reload?: () => void | Promise<void> } | null>(null)
|
||||
const walletPanelKey = ref(0)
|
||||
|
||||
/** فقط وقتی حسابداری روی پرگار تنظیم شده باشد */
|
||||
const pargarWalletSyncVisible = computed(
|
||||
() =>
|
||||
pargarEnabledSetting.value &&
|
||||
accountingProviderSetting.value === 'pargar' &&
|
||||
isValidAccountingCode(userInfo.value?.pargar_account_id)
|
||||
() => accountingProviderSetting.value === 'pargar'
|
||||
)
|
||||
|
||||
const pargarWalletCanSync = computed(() =>
|
||||
isValidAccountingCode(userInfo.value?.pargar_account_id)
|
||||
)
|
||||
|
||||
async function refreshWalletPanels() {
|
||||
await nextTick()
|
||||
walletPanelKey.value += 1
|
||||
await nextTick()
|
||||
await Promise.allSettled([
|
||||
Promise.resolve(walletPanelDesktop.value?.reload?.()),
|
||||
Promise.resolve(walletPanelMobile.value?.reload?.()),
|
||||
])
|
||||
}
|
||||
|
||||
async function syncPargarWallet() {
|
||||
if (!userInfo.value?.id) return
|
||||
if (!userInfo.value?.id || !pargarWalletCanSync.value) return
|
||||
pargarSyncLoading.value = true
|
||||
try {
|
||||
const res = await syncCustomerWalletFromPargar(userInfo.value.id)
|
||||
message.success(res.message || 'مانده از پرگار اعمال شد')
|
||||
walletPanelDesktop.value?.reload?.()
|
||||
walletPanelMobile.value?.reload?.()
|
||||
const applied =
|
||||
res.ok ||
|
||||
(res.result?.documents?.applied ?? 0) > 0 ||
|
||||
Boolean(res.result?.mande?.applied)
|
||||
|
||||
if (applied) {
|
||||
message.success(res.message || 'مانده از پرگار روی کیف اعمال شد')
|
||||
} else {
|
||||
message.info(res.message || 'تغییری برای اعمال نبود')
|
||||
}
|
||||
|
||||
await refreshWalletPanels()
|
||||
refreshTransactionTable()
|
||||
refreshTable()
|
||||
} catch (e: unknown) {
|
||||
const msg =
|
||||
(e as { response?: { data?: { message?: string } } })?.response?.data?.message ||
|
||||
'اعمال مانده از پرگار ناموفق بود'
|
||||
message.warning(msg)
|
||||
// فقط خطای واقعی شبکه/سرور — پیام ۴۲۲ را interceptor هم نشان میدهد؛ دوباره نزن
|
||||
const data = (e as { response?: { data?: PargarSyncWalletResult } })?.response?.data
|
||||
const status = (e as { response?: { status?: number } })?.response?.status
|
||||
const applied =
|
||||
Boolean(data?.ok) ||
|
||||
(data?.result?.documents?.applied ?? 0) > 0 ||
|
||||
Boolean(data?.result?.mande?.applied)
|
||||
|
||||
await refreshWalletPanels()
|
||||
refreshTransactionTable()
|
||||
refreshTable()
|
||||
|
||||
if (applied) {
|
||||
message.success(data?.message || 'مانده از پرگار روی کیف اعمال شد')
|
||||
} else if (status !== 422) {
|
||||
// ۴۲۲ را axios خودش با message.error نشان داده
|
||||
message.warning(data?.message || 'اعمال مانده از پرگار ناموفق بود')
|
||||
}
|
||||
} finally {
|
||||
pargarSyncLoading.value = false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user