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))
|
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(
|
export function calcPayablePriceRial(
|
||||||
finalPriceRial: number,
|
finalPriceRial: number,
|
||||||
@@ -97,10 +108,11 @@ export function calcPayablePriceRial(
|
|||||||
isBuy: boolean,
|
isBuy: boolean,
|
||||||
targetRialCash?: number | null
|
targetRialCash?: number | null
|
||||||
) {
|
) {
|
||||||
|
if (targetRialCash != null && Number(targetRialCash) > 0) {
|
||||||
|
return Number(targetRialCash)
|
||||||
|
}
|
||||||
|
|
||||||
if (feeDeductFromGold.value) {
|
if (feeDeductFromGold.value) {
|
||||||
if (targetRialCash != null && Number(targetRialCash) > 0) {
|
|
||||||
return Number(targetRialCash)
|
|
||||||
}
|
|
||||||
if (isBuy) return finalPriceRial + feeInRial
|
if (isBuy) return finalPriceRial + feeInRial
|
||||||
return finalPriceRial
|
return finalPriceRial
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,21 @@ type TransactionPriceSource = {
|
|||||||
price?: number | null
|
price?: number | null
|
||||||
total_price?: number | null
|
total_price?: number | null
|
||||||
amount?: number | null
|
amount?: number | null
|
||||||
|
sts?: number | null
|
||||||
|
sts_str?: string | number | null
|
||||||
|
payment_sts?: number | null
|
||||||
} | 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 {
|
export function getTransactionTradePrice(item: TransactionPriceSource): number {
|
||||||
@@ -79,6 +93,34 @@ export function getTransactionTradePrice(item: TransactionPriceSource): number {
|
|||||||
return 0
|
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 {
|
export function getTransactionGoldAmount(item: TransactionPriceSource): number {
|
||||||
const gold = Number(item.gold) || 0
|
const gold = Number(item.gold) || 0
|
||||||
if (Math.abs(gold) > 0) {
|
if (Math.abs(gold) > 0) {
|
||||||
|
|||||||
@@ -338,6 +338,7 @@ import {
|
|||||||
calcRialFromLockedGram,
|
calcRialFromLockedGram,
|
||||||
calcSellGoldDebit,
|
calcSellGoldDebit,
|
||||||
calcSellTargetCash,
|
calcSellTargetCash,
|
||||||
|
calcTradeTargetCash,
|
||||||
feeDeductFromGold,
|
feeDeductFromGold,
|
||||||
loadServiceFeeFromSettings,
|
loadServiceFeeFromSettings,
|
||||||
serviceFeePercentage,
|
serviceFeePercentage,
|
||||||
@@ -803,7 +804,8 @@ async function ok() {
|
|||||||
direction: isBuy.value ? 1 : 2,
|
direction: isBuy.value ? 1 : 2,
|
||||||
price: Math.round(unitPrice.value),
|
price: Math.round(unitPrice.value),
|
||||||
amount: orderGoldAmount.value,
|
amount: orderGoldAmount.value,
|
||||||
target_cash: calcSellTargetCash(
|
target_cash: calcTradeTargetCash(form.value.goldCash, inputLock.value)
|
||||||
|
?? calcSellTargetCash(
|
||||||
form.value.goldCash,
|
form.value.goldCash,
|
||||||
form.value.goldValue,
|
form.value.goldValue,
|
||||||
unitPrice.value,
|
unitPrice.value,
|
||||||
|
|||||||
@@ -32,8 +32,8 @@
|
|||||||
{{ usePriceWithoutType(props.item.cash ?? 0) }} ریال
|
{{ usePriceWithoutType(props.item.cash ?? 0) }} ریال
|
||||||
</div>
|
</div>
|
||||||
<div class="dtxn-row__status">
|
<div class="dtxn-row__status">
|
||||||
<ATag color="blue" class="!py-1 !px-4 !ml-0 !text-xs">
|
<ATag v-if="statusLabel" color="blue" class="!py-1 !px-4 !ml-0 !text-xs">
|
||||||
{{ props.item.order?.sts_str ?? props.item.withdraw?.sts_str }}
|
{{ statusLabel }}
|
||||||
</ATag>
|
</ATag>
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
@@ -83,8 +83,8 @@
|
|||||||
<div class="flex w-full justify-between mt-2">
|
<div class="flex w-full justify-between mt-2">
|
||||||
<div class="text-gray-500">وضعیت :</div>
|
<div class="text-gray-500">وضعیت :</div>
|
||||||
<div class="text-gray-500 flex gap-1 text-xs items-center">
|
<div class="text-gray-500 flex gap-1 text-xs items-center">
|
||||||
<ATag class="!py-1 !px-6 !ml-0" color="blue">
|
<ATag v-if="statusLabel" class="!py-1 !px-6 !ml-0" color="blue">
|
||||||
{{ props.item.order?.sts_str ?? props.item.withdraw?.sts_str }}
|
{{ statusLabel }}
|
||||||
</ATag>
|
</ATag>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -118,6 +118,7 @@ import {
|
|||||||
formatGoldAmount,
|
formatGoldAmount,
|
||||||
getTransactionGoldAmount,
|
getTransactionGoldAmount,
|
||||||
getTransactionTradePrice,
|
getTransactionTradePrice,
|
||||||
|
resolveTransactionStatusLabel,
|
||||||
usePriceWithoutType,
|
usePriceWithoutType,
|
||||||
} from '@/utils/usePrice'
|
} from '@/utils/usePrice'
|
||||||
import BasicActionSheet from '@/components/BasicPacks/BasicActionSheet.vue'
|
import BasicActionSheet from '@/components/BasicPacks/BasicActionSheet.vue'
|
||||||
@@ -140,6 +141,7 @@ const props = withDefaults(
|
|||||||
|
|
||||||
const goldAmount = computed(() => getTransactionGoldAmount(props.item))
|
const goldAmount = computed(() => getTransactionGoldAmount(props.item))
|
||||||
const tradePrice = computed(() => getTransactionTradePrice(props.item))
|
const tradePrice = computed(() => getTransactionTradePrice(props.item))
|
||||||
|
const statusLabel = computed(() => resolveTransactionStatusLabel(props.item))
|
||||||
|
|
||||||
const isUp = computed(
|
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__row' : 'flex justify-between mb-3'">
|
||||||
<div :class="variant === 'desktop' ? 'dtxn-detail__label' : 'text-primary'">وضعیت:</div>
|
<div :class="variant === 'desktop' ? 'dtxn-detail__label' : 'text-primary'">وضعیت:</div>
|
||||||
<div class="flex text-xs items-center">
|
<div class="flex text-xs items-center">
|
||||||
<ATag color="blue" class="!py-1 !px-6 !ml-0">
|
<ATag v-if="statusLabel" color="blue" class="!py-1 !px-6 !ml-0">
|
||||||
{{ item.order?.sts_str ?? item.withdraw?.sts_str }}
|
{{ statusLabel }}
|
||||||
</ATag>
|
</ATag>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -115,7 +115,7 @@
|
|||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
import { formatGoldAmount, usePriceWithoutType } from '@/utils/usePrice'
|
import { formatGoldAmount, resolveTransactionStatusLabel, usePriceWithoutType } from '@/utils/usePrice'
|
||||||
import type { Transaction } from '@/models/transaction'
|
import type { Transaction } from '@/models/transaction'
|
||||||
import {
|
import {
|
||||||
getCashWalletLabel,
|
getCashWalletLabel,
|
||||||
@@ -139,6 +139,7 @@ const props = withDefaults(
|
|||||||
)
|
)
|
||||||
|
|
||||||
const tradeProduct = computed(() => resolveTransactionTradeProduct(props.item))
|
const tradeProduct = computed(() => resolveTransactionTradeProduct(props.item))
|
||||||
|
const statusLabel = computed(() => resolveTransactionStatusLabel(props.item))
|
||||||
const tradeProductLabel = computed(
|
const tradeProductLabel = computed(
|
||||||
() => (tradeProduct.value?.title ?? '').trim() || getMeltedGoldTradeLabel(),
|
() => (tradeProduct.value?.title ?? '').trim() || getMeltedGoldTradeLabel(),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user