fix somw bug
This commit is contained in:
+5
-2
@@ -44,8 +44,11 @@ export interface PargarSyncWalletResult {
|
||||
}
|
||||
}
|
||||
|
||||
export const syncCustomerWalletFromPargar = async (customerId: number) =>
|
||||
await useAxios.post<PargarSyncWalletResult>(`/admin/customer/${customerId}/pargar/sync-wallet`)
|
||||
export const syncCustomerWalletFromPargar = async (customerId: number, force = false) =>
|
||||
await useAxios.post<PargarSyncWalletResult>(
|
||||
`/admin/customer/${customerId}/pargar/sync-wallet`,
|
||||
{ force }
|
||||
)
|
||||
|
||||
export interface PanelOnlyCustomer {
|
||||
id: number
|
||||
|
||||
@@ -333,7 +333,9 @@ function linesForMetal(metalId: number) {
|
||||
return lines
|
||||
}
|
||||
|
||||
defineExpose({ reload: () => props.customerId && load(props.customerId) })
|
||||
defineExpose({
|
||||
reload: () => (props.customerId ? load(props.customerId) : Promise.resolve())
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<template>
|
||||
<div class="pargar-wallet-sync">
|
||||
<div class="pargar-wallet-sync__head">
|
||||
<div class="pargar-wallet-sync__icon" aria-hidden="true">
|
||||
<Icon icon="vuesax-linear:refresh-circle" :size="18" color="var(--admin-primary, #10913A)" />
|
||||
</div>
|
||||
<div class="pargar-wallet-sync__copy min-w-0 flex-1">
|
||||
<p class="pargar-wallet-sync__title">همگامسازی با پرگار</p>
|
||||
<p class="pargar-wallet-sync__hint">
|
||||
{{
|
||||
canSync
|
||||
? 'اول اسنادِ اعمالنشده، بعد همترازی مانده — خودکار از پرگار کیف عوض نمیشود'
|
||||
: 'ابتدا کد حسابداری پرگار را برای این مشتری ثبت کنید'
|
||||
}}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<a-button
|
||||
type="primary"
|
||||
block
|
||||
size="small"
|
||||
class="pargar-wallet-sync__btn"
|
||||
:loading="loading"
|
||||
:disabled="!canSync"
|
||||
@click="$emit('sync')"
|
||||
>
|
||||
همگامسازی مانده و اسناد
|
||||
</a-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import Icon from '@core/components/BaseIcon/src/Icon.vue'
|
||||
|
||||
defineProps<{
|
||||
loading?: boolean
|
||||
canSync?: boolean
|
||||
}>()
|
||||
|
||||
defineEmits<{
|
||||
(e: 'sync'): void
|
||||
}>()
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.pargar-wallet-sync {
|
||||
@apply mb-2.5 rounded-xl border border-base p-2.5;
|
||||
background: var(--admin-surface-muted, var(--admin-bg-muted, #f8fafc));
|
||||
}
|
||||
|
||||
.pargar-wallet-sync__head {
|
||||
@apply mb-2.5 flex items-start gap-2;
|
||||
}
|
||||
|
||||
.pargar-wallet-sync__icon {
|
||||
@apply flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-gray-50;
|
||||
}
|
||||
|
||||
.pargar-wallet-sync__title {
|
||||
@apply m-0 text-sm font-700;
|
||||
color: var(--admin-text, inherit);
|
||||
}
|
||||
|
||||
.pargar-wallet-sync__hint {
|
||||
@apply m-0 mt-0.5 text-xs leading-5;
|
||||
color: var(--admin-text-secondary, #6b7280);
|
||||
}
|
||||
|
||||
.pargar-wallet-sync__btn {
|
||||
@apply font-600;
|
||||
}
|
||||
</style>
|
||||
@@ -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