From 0106c94d240cc37df587fdd81a30b39e1df5fcfa Mon Sep 17 00:00:00 2001 From: adonis Date: Sun, 19 Jul 2026 21:49:31 +0330 Subject: [PATCH] fix some bugs --- src/utils/walletMinAmount.ts | 27 +++++++++++++++++++ .../base/wallet/composables/useWalletPage.ts | 27 +++++++++++++++++-- .../base/wallet/desktop/DesktopWalletView.vue | 6 +++-- 3 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 src/utils/walletMinAmount.ts diff --git a/src/utils/walletMinAmount.ts b/src/utils/walletMinAmount.ts new file mode 100644 index 0000000..b6465aa --- /dev/null +++ b/src/utils/walletMinAmount.ts @@ -0,0 +1,27 @@ +import { usePriceWithoutType } from '@/utils/usePrice' + +/** پیش‌فرض تاریخی UI وقتی تنظیم خالی است (۱۰۰ هزار تومان = ۱٬۰۰۰٬۰۰۰ ریال) */ +export const DEFAULT_WALLET_MIN_RIAL = 1_000_000 + +export function parseWalletMinRial( + raw: string | number | null | undefined, + fallback = DEFAULT_WALLET_MIN_RIAL, +): number { + if (raw == null || String(raw).trim() === '') { + return fallback + } + const n = Number(String(raw).replace(/,/g, '').trim()) + if (!Number.isFinite(n) || n < 0) { + return fallback + } + return Math.floor(n) +} + +export function formatWalletMinHint( + kind: 'withdraw' | 'deposit', + amountRial: number, + formatPrice: (value: number) => string = usePriceWithoutType, +): string { + const label = kind === 'withdraw' ? 'برداشتی' : 'واریزی' + return `حداقل مبلغ ${label} ${formatPrice(amountRial)} ریال می باشد.` +} diff --git a/src/views/base/wallet/composables/useWalletPage.ts b/src/views/base/wallet/composables/useWalletPage.ts index 84c8dc0..06fbd28 100644 --- a/src/views/base/wallet/composables/useWalletPage.ts +++ b/src/views/base/wallet/composables/useWalletPage.ts @@ -10,9 +10,11 @@ import { useInfiniteScroll } from '@vueuse/core' import { message } from 'ant-design-vue' import type { Card } from '@/models/wallet' import { useUserStore } from '@/store/userStore' +import { useSettingsStore } from '@/store/settingsStore' import { useDesktopBreakpoint } from '@/layouts/composables/useAppLayout' import type { TableEngineInput, TableOutput } from '@/models/table' import { getTransactionTable, getTransactionTable2 } from '@/api/transaction' +import { formatWalletMinHint, parseWalletMinRial } from '@/utils/walletMinAmount' export interface WalletPageContext { isDeposit: ReturnType> @@ -30,6 +32,8 @@ export interface WalletPageContext { withdrawItems: ReturnType> mobileDepositScrollEl: ReturnType> desktopDepositScrollEl: ReturnType> + minWithdrawHint: ReturnType> + minDepositHint: ReturnType> usePriceWithoutType: typeof usePriceWithoutType usePrice: typeof usePrice setIsDeposit: (val: boolean) => void @@ -48,6 +52,7 @@ export function useWalletPage() { const isDeposit = ref(true) const walletStore = useWalletStore() const userStore = useUserStore() + const settingsStore = useSettingsStore() const isDesktop = useDesktopBreakpoint() const showAddCard = ref(false) const chargeAccountModal = ref(false) @@ -87,6 +92,19 @@ export function useWalletPage() { const unitCalculator = computed(() => (walletStore?.walletInfo?.cash ?? 0) / 100) + const minWithdrawAmount = computed(() => + parseWalletMinRial(settingsStore.getSettingByKey('min_withdraw')), + ) + const minDepositAmount = computed(() => + parseWalletMinRial(settingsStore.getSettingByKey('min_deposit')), + ) + const minWithdrawHint = computed(() => + formatWalletMinHint('withdraw', minWithdrawAmount.value), + ) + const minDepositHint = computed(() => + formatWalletMinHint('deposit', minDepositAmount.value), + ) + const disableButton = computed(() => { if (loading.value) return true if (walletStore?.walletInfo?.cash && !isDeposit.value) { @@ -95,13 +113,16 @@ export function useWalletPage() { walletStore?.walletInfo?.cash <= 0 || walletStore?.walletInfo?.cash < parseInt(String(form.value?.value)) || isNaN(parseInt(String(form.value?.value))) || - parseInt(String(form.value?.value)) < 1000000 + parseInt(String(form.value?.value)) < minWithdrawAmount.value ) } return true } if (isDeposit.value) { - return isNaN(parseInt(String(form.value?.value))) || parseInt(String(form.value?.value)) < 1000000 + return ( + isNaN(parseInt(String(form.value?.value))) || + parseInt(String(form.value?.value)) < minDepositAmount.value + ) } return false }) @@ -267,6 +288,8 @@ export function useWalletPage() { withdrawItems, mobileDepositScrollEl, desktopDepositScrollEl, + minWithdrawHint, + minDepositHint, usePriceWithoutType, usePrice, setIsDeposit, diff --git a/src/views/base/wallet/desktop/DesktopWalletView.vue b/src/views/base/wallet/desktop/DesktopWalletView.vue index 2349603..f579b63 100644 --- a/src/views/base/wallet/desktop/DesktopWalletView.vue +++ b/src/views/base/wallet/desktop/DesktopWalletView.vue @@ -56,7 +56,7 @@

- حداقل مبلغ برداشتی 100 هزار تومان می باشد. + {{ minWithdrawHint }}

موجودی کیف پول: @@ -77,7 +77,7 @@

- حداقل مبلغ واریزی 100 هزار تومان می باشد. + {{ minDepositHint }}