diff --git a/src/utils/serviceFee.ts b/src/utils/serviceFee.ts index 2d3345a..b3bd3cf 100644 --- a/src/utils/serviceFee.ts +++ b/src/utils/serviceFee.ts @@ -90,6 +90,17 @@ export function calcGramFromLockedRial(rialAmount: number, unitPriceRial: number return parseFloat((rial / (unit * (1 - fee))).toFixed(6)) } +/** مبلغ ریالی قفل‌شده توسط کاربر — برای ارسال به سرور */ +export function calcTradeTargetCash( + goldCash?: number | null, + inputLock?: TradeInputLock, +): number | undefined { + if (inputLock !== 'rial') return undefined + const cash = Number(goldCash ?? 0) + if (cash <= 0) return undefined + return Math.round(cash) +} + /** مبلغ نهایی قابل پرداخت (خرید) یا دریافت (فروش) به ریال */ export function calcPayablePriceRial( finalPriceRial: number, @@ -97,10 +108,11 @@ export function calcPayablePriceRial( isBuy: boolean, targetRialCash?: number | null ) { + if (targetRialCash != null && Number(targetRialCash) > 0) { + return Number(targetRialCash) + } + if (feeDeductFromGold.value) { - if (targetRialCash != null && Number(targetRialCash) > 0) { - return Number(targetRialCash) - } if (isBuy) return finalPriceRial + feeInRial return finalPriceRial } diff --git a/src/utils/usePrice.ts b/src/utils/usePrice.ts index 8860960..1920e62 100644 --- a/src/utils/usePrice.ts +++ b/src/utils/usePrice.ts @@ -54,7 +54,21 @@ type TransactionPriceSource = { price?: number | null total_price?: number | null amount?: number | null + sts?: number | null + sts_str?: string | number | null + payment_sts?: number | null } | null + withdraw?: { + sts?: number | null + sts_str?: string | number | null + } | null + order_id?: number | null +} + +const ORDER_STATUS_LABELS: Record = { + 1: 'باز', + 2: 'موفق', + 3: 'ناموفق', } export function getTransactionTradePrice(item: TransactionPriceSource): number { @@ -79,6 +93,34 @@ export function getTransactionTradePrice(item: TransactionPriceSource): number { return 0 } +export function resolveTransactionStatusLabel(item?: TransactionPriceSource | null): string { + if (!item) return '' + + const raw = item.order?.sts_str ?? item.withdraw?.sts_str + if (typeof raw === 'string') { + const trimmed = raw.trim() + if (trimmed && trimmed !== 'بدون مقدار') { + return trimmed + } + } + + if (typeof raw === 'number' || (typeof raw === 'string' && /^\d+$/.test(String(raw).trim()))) { + const mapped = ORDER_STATUS_LABELS[Number(raw)] + if (mapped) return mapped + } + + const sts = item.order?.sts ?? item.withdraw?.sts + if (sts != null && ORDER_STATUS_LABELS[Number(sts)]) { + return ORDER_STATUS_LABELS[Number(sts)] + } + + if (item.order_id && Number(item.order?.payment_sts) === 4) { + return 'موفق' + } + + return '' +} + export function getTransactionGoldAmount(item: TransactionPriceSource): number { const gold = Number(item.gold) || 0 if (Math.abs(gold) > 0) { diff --git a/src/views/base/gold/index.vue b/src/views/base/gold/index.vue index 0587d00..5206b3f 100644 --- a/src/views/base/gold/index.vue +++ b/src/views/base/gold/index.vue @@ -338,6 +338,7 @@ import { calcRialFromLockedGram, calcSellGoldDebit, calcSellTargetCash, + calcTradeTargetCash, feeDeductFromGold, loadServiceFeeFromSettings, serviceFeePercentage, @@ -803,7 +804,8 @@ async function ok() { direction: isBuy.value ? 1 : 2, price: Math.round(unitPrice.value), amount: orderGoldAmount.value, - target_cash: calcSellTargetCash( + target_cash: calcTradeTargetCash(form.value.goldCash, inputLock.value) + ?? calcSellTargetCash( form.value.goldCash, form.value.goldValue, unitPrice.value, diff --git a/src/views/base/transactions/components/Item.vue b/src/views/base/transactions/components/Item.vue index c4aba0f..3a1cb99 100644 --- a/src/views/base/transactions/components/Item.vue +++ b/src/views/base/transactions/components/Item.vue @@ -32,8 +32,8 @@ {{ usePriceWithoutType(props.item.cash ?? 0) }} ریال
- - {{ props.item.order?.sts_str ?? props.item.withdraw?.sts_str }} + + {{ statusLabel }}
@@ -83,8 +83,8 @@
وضعیت :
- - {{ props.item.order?.sts_str ?? props.item.withdraw?.sts_str }} + + {{ statusLabel }}
@@ -118,6 +118,7 @@ import { formatGoldAmount, getTransactionGoldAmount, getTransactionTradePrice, + resolveTransactionStatusLabel, usePriceWithoutType, } from '@/utils/usePrice' import BasicActionSheet from '@/components/BasicPacks/BasicActionSheet.vue' @@ -140,6 +141,7 @@ const props = withDefaults( const goldAmount = computed(() => getTransactionGoldAmount(props.item)) const tradePrice = computed(() => getTransactionTradePrice(props.item)) +const statusLabel = computed(() => resolveTransactionStatusLabel(props.item)) const isUp = computed( () => diff --git a/src/views/base/transactions/components/TransactionDetailPanel.vue b/src/views/base/transactions/components/TransactionDetailPanel.vue index 47a24fc..4edcc7e 100644 --- a/src/views/base/transactions/components/TransactionDetailPanel.vue +++ b/src/views/base/transactions/components/TransactionDetailPanel.vue @@ -93,8 +93,8 @@
وضعیت:
- - {{ item.order?.sts_str ?? item.withdraw?.sts_str }} + + {{ statusLabel }}
@@ -115,7 +115,7 @@