price calulator changed 5
This commit is contained in:
+15
-3
@@ -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
|
||||
}
|
||||
|
||||
@@ -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<number, string> = {
|
||||
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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -32,8 +32,8 @@
|
||||
{{ usePriceWithoutType(props.item.cash ?? 0) }} ریال
|
||||
</div>
|
||||
<div class="dtxn-row__status">
|
||||
<ATag color="blue" class="!py-1 !px-4 !ml-0 !text-xs">
|
||||
{{ props.item.order?.sts_str ?? props.item.withdraw?.sts_str }}
|
||||
<ATag v-if="statusLabel" color="blue" class="!py-1 !px-4 !ml-0 !text-xs">
|
||||
{{ statusLabel }}
|
||||
</ATag>
|
||||
</div>
|
||||
</button>
|
||||
@@ -83,8 +83,8 @@
|
||||
<div class="flex w-full justify-between mt-2">
|
||||
<div class="text-gray-500">وضعیت :</div>
|
||||
<div class="text-gray-500 flex gap-1 text-xs items-center">
|
||||
<ATag class="!py-1 !px-6 !ml-0" color="blue">
|
||||
{{ props.item.order?.sts_str ?? props.item.withdraw?.sts_str }}
|
||||
<ATag v-if="statusLabel" class="!py-1 !px-6 !ml-0" color="blue">
|
||||
{{ statusLabel }}
|
||||
</ATag>
|
||||
</div>
|
||||
</div>
|
||||
@@ -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(
|
||||
() =>
|
||||
|
||||
@@ -93,8 +93,8 @@
|
||||
<div :class="variant === 'desktop' ? 'dtxn-detail__row' : 'flex justify-between mb-3'">
|
||||
<div :class="variant === 'desktop' ? 'dtxn-detail__label' : 'text-primary'">وضعیت:</div>
|
||||
<div class="flex text-xs items-center">
|
||||
<ATag color="blue" class="!py-1 !px-6 !ml-0">
|
||||
{{ item.order?.sts_str ?? item.withdraw?.sts_str }}
|
||||
<ATag v-if="statusLabel" color="blue" class="!py-1 !px-6 !ml-0">
|
||||
{{ statusLabel }}
|
||||
</ATag>
|
||||
</div>
|
||||
</div>
|
||||
@@ -115,7 +115,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed } from 'vue'
|
||||
import { formatGoldAmount, usePriceWithoutType } from '@/utils/usePrice'
|
||||
import { formatGoldAmount, resolveTransactionStatusLabel, usePriceWithoutType } from '@/utils/usePrice'
|
||||
import type { Transaction } from '@/models/transaction'
|
||||
import {
|
||||
getCashWalletLabel,
|
||||
@@ -139,6 +139,7 @@ const props = withDefaults(
|
||||
)
|
||||
|
||||
const tradeProduct = computed(() => resolveTransactionTradeProduct(props.item))
|
||||
const statusLabel = computed(() => resolveTransactionStatusLabel(props.item))
|
||||
const tradeProductLabel = computed(
|
||||
() => (tradeProduct.value?.title ?? '').trim() || getMeltedGoldTradeLabel(),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user