fixed amount 2
This commit is contained in:
@@ -232,6 +232,7 @@ import type { Product } from '@/models/products'
|
||||
import { useFundUserStore } from '@/store/fundStore'
|
||||
import {useConfigStore} from "@/store/configStore";
|
||||
import { calcFeeInGrams, calcPayablePriceRial, calcSellGoldDebit, feeDeductFromGold, loadServiceFeeFromSettings } from '@/utils/serviceFee'
|
||||
import { resolveProductCashFeeBuyRial, resolveProductCashFeeSellRial } from '@/utils/productCashFee'
|
||||
import { formatCashWalletBalanceText, formatGoldWalletBalanceText } from '@/utils/productDealMethod'
|
||||
import { getCashWalletBalance } from '@/utils/productAssets'
|
||||
import { isStoreClosed, getStoreClosedMessage } from '@/utils/storeHours'
|
||||
@@ -283,13 +284,12 @@ const basePriceValue = computed(() => {
|
||||
const product = props?.ProductItem
|
||||
if (!product) return undefined
|
||||
|
||||
const { price_profit = 0, price = 0, cash_fee_buy = 0, cash_fee_sell = 0 } = product
|
||||
const { price_profit = 0, price = 0 } = product
|
||||
const base = price_profit + price
|
||||
const buyFee = resolveProductCashFeeBuyRial(product, base)
|
||||
const sellFee = resolveProductCashFeeSellRial(product, base)
|
||||
|
||||
const rawPrice = isBuy.value
|
||||
? base + cash_fee_buy
|
||||
: base - cash_fee_sell
|
||||
return rawPrice
|
||||
return isBuy.value ? base + buyFee : base - sellFee
|
||||
})
|
||||
|
||||
const finalPrice = computed(() => {
|
||||
@@ -299,15 +299,17 @@ const finalPrice = computed(() => {
|
||||
const product = props?.ProductItem
|
||||
if (!product) return 0
|
||||
|
||||
const { price_profit = 0, price = 0, cash_fee_buy = 0, cash_fee_sell = 0 } = product
|
||||
const { price_profit = 0, price = 0 } = product
|
||||
|
||||
const base = price_profit + price
|
||||
const buyFee = resolveProductCashFeeBuyRial(product, base)
|
||||
const sellFee = resolveProductCashFeeSellRial(product, base)
|
||||
|
||||
if (isBuy.value) {
|
||||
return gold * (base + cash_fee_buy)
|
||||
} else {
|
||||
return gold * (base - cash_fee_sell)
|
||||
return gold * (base + buyFee)
|
||||
}
|
||||
|
||||
return gold * (base - sellFee)
|
||||
})
|
||||
|
||||
const payablePrice = computed(() =>
|
||||
@@ -533,20 +535,30 @@ watch(
|
||||
}
|
||||
)
|
||||
|
||||
function productFeeBase(product?: Product) {
|
||||
return (product?.price_profit ?? 0) + (product?.price ?? 0)
|
||||
}
|
||||
|
||||
function calculateCash(val: number) {
|
||||
priceErrorVisible.value = false
|
||||
if (!lastPrice.value) return
|
||||
|
||||
const product = props?.ProductItem
|
||||
if (!product) return
|
||||
|
||||
const base = productFeeBase(product)
|
||||
const buyFee = resolveProductCashFeeBuyRial(product, base)
|
||||
const sellFee = resolveProductCashFeeSellRial(product, base)
|
||||
const tradeBuy = getTradeBuyPrice(lastPrice.value)
|
||||
form.value.goldVazn = parseFloat((val * ((props?.ProductItem?.price) + (props?.ProductItem?.cash_fee_buy))) / tradeBuy).toFixed(1)
|
||||
form.value.goldVazn = parseFloat(String((val * (base + buyFee)) / tradeBuy)).toFixed(1)
|
||||
if (isBuy.value) {
|
||||
form.value.goldCash = val
|
||||
? parseFloat(String(val * ((props?.ProductItem?.price) + (props?.ProductItem?.cash_fee_buy))))
|
||||
? parseFloat(String(val * (base + buyFee)))
|
||||
: 0
|
||||
if (!val) form.value.goldVazn = 0
|
||||
} else {
|
||||
form.value.goldCash = val
|
||||
? parseFloat(String((val * props?.ProductItem?.price) - (props?.ProductItem?.cash_fee_sell)))
|
||||
? parseFloat(String(val * base - sellFee))
|
||||
: 0
|
||||
if (!val) form.value.goldVazn = 0
|
||||
}
|
||||
@@ -554,9 +566,16 @@ function calculateCash(val: number) {
|
||||
|
||||
function calculateGold(val: number) {
|
||||
if (price.value) {
|
||||
const product = props?.ProductItem
|
||||
if (!product) return
|
||||
|
||||
const base = productFeeBase(product)
|
||||
const buyFee = resolveProductCashFeeBuyRial(product, base)
|
||||
const sellFee = resolveProductCashFeeSellRial(product, base)
|
||||
|
||||
if (isBuy.value) {
|
||||
if (val) {
|
||||
form.value.goldValue = toFixedDownThreeChar(parseFloat(val / (((props?.ProductItem?.price_profit) + (props?.ProductItem?.price)) + (props?.ProductItem?.cash_fee_buy))))
|
||||
form.value.goldValue = toFixedDownThreeChar(parseFloat(String(val / (base + buyFee))))
|
||||
if (parseInt(finalPrice.value) > 0) priceErrorVisible.value = true
|
||||
if (parseInt(finalPrice.value) === 0) priceErrorVisible.value = false
|
||||
}
|
||||
@@ -571,7 +590,7 @@ function calculateGold(val: number) {
|
||||
}
|
||||
else {
|
||||
if (val) {
|
||||
form.value.goldValue = toFixedDownThreeChar(parseFloat(val / (((props?.ProductItem?.price_profit) + (props?.ProductItem?.price)) + (props?.ProductItem?.cash_fee_sell))))
|
||||
form.value.goldValue = toFixedDownThreeChar(parseFloat(String(val / (base - sellFee))))
|
||||
if (parseInt(finalPrice.value) > 0) priceErrorVisible.value = true
|
||||
if (parseInt(finalPrice.value) === 0) priceErrorVisible.value = false
|
||||
} else if (val.toString() === '') {
|
||||
|
||||
@@ -281,6 +281,7 @@ import type { TableEngineInput, TableOutput } from '@/models/table'
|
||||
import { getTransactionTable } from '@/api/transaction'
|
||||
import { getLastPrices, getTradeBuyPrice, getTradeSellPrice, lastPrice, setIntervalGetAllPrice, stopPriceInterval } from '@/utils/price'
|
||||
import { getProductBuyPrice, getProductSellPrice, isProductPriceInactive } from '@/utils/productPrice'
|
||||
import { resolveProductCashFeeBuyRial, resolveProductCashFeeSellRial } from '@/utils/productCashFee'
|
||||
import { Product } from '@/models/products'
|
||||
import BasicSelect from '@/components/BasicPacks/BasicSelect.vue'
|
||||
import Bg_main from '@/components/bg_main.vue'
|
||||
@@ -402,22 +403,9 @@ interface Prop {
|
||||
const props = withDefaults(defineProps<Prop>(), {})
|
||||
const emit = defineEmits<{ ordered: [] }>()
|
||||
const isBuy = ref<boolean>(true)
|
||||
const buyTotalPrice = computed(() => {
|
||||
const item = props?.ProductItem
|
||||
if (!item) return 0
|
||||
const basePrice = (item.price ?? 0) + (item.cash_fee_buy ?? 0)
|
||||
const buyTotalPrice = computed(() => resolveProductTradeBuyUnitPrice(props?.ProductItem))
|
||||
|
||||
return basePrice * productPriceAmountFactor(item)
|
||||
})
|
||||
|
||||
const sellTotalPrice = computed(() => {
|
||||
const item = props?.ProductItem
|
||||
if (!item) return 0
|
||||
|
||||
const basePrice = (item.price ?? 0) - (item.cash_fee_sell ?? 0)
|
||||
|
||||
return basePrice * productPriceAmountFactor(item)
|
||||
})
|
||||
const sellTotalPrice = computed(() => resolveProductTradeSellUnitPrice(props?.ProductItem))
|
||||
const buyFee = computed(() => ((props?.ProductItem?.amount * (props?.ProductItem?.percent_fee_buy ?? 0) * (props?.ProductItem?.price ?? 0)).toFixed(0)))
|
||||
const sellFee = computed(() => ((props?.ProductItem?.amount * (props?.ProductItem?.percent_fee_sell ?? 0) * (props?.ProductItem?.sellPrice ?? 0)).toFixed(0)))
|
||||
|
||||
@@ -738,7 +726,8 @@ function calculateCash(val: number) {
|
||||
// form.value.goldVazn = parseFloat((val * (( props?.ProductItem?.price) + (props?.ProductItem?.cash_fee_buy)))/lastPrice.value?.buy).toFixed(2)
|
||||
if (isBuy.value) {
|
||||
if (val){
|
||||
const unitPrice = (props?.ProductItem?.price ?? 0) + (props?.ProductItem?.cash_fee_buy ?? 0)
|
||||
const base = props?.ProductItem?.price ?? 0
|
||||
const unitPrice = base + resolveProductCashFeeBuyRial(props?.ProductItem, base)
|
||||
form.value.goldCash = parseFloat(String(val * unitPrice * productPriceAmountFactor(props?.ProductItem))).toFixed(0)
|
||||
}
|
||||
else {
|
||||
@@ -748,7 +737,8 @@ function calculateCash(val: number) {
|
||||
}
|
||||
else {
|
||||
if (val){
|
||||
const unitPrice = (props?.ProductItem?.price ?? 0) - (props?.ProductItem?.cash_fee_sell ?? 0)
|
||||
const base = props?.ProductItem?.price ?? 0
|
||||
const unitPrice = base - resolveProductCashFeeSellRial(props?.ProductItem, base)
|
||||
form.value.goldCash = parseFloat(String(val * unitPrice * productPriceAmountFactor(props?.ProductItem))).toFixed(0)
|
||||
}
|
||||
else{
|
||||
@@ -839,8 +829,11 @@ async function initPrice() {
|
||||
await getLastPrices()
|
||||
// await setIntervalGetPrice()
|
||||
loading.value = true
|
||||
props.ProductItem.price = lastPrice?.value?.price? (lastPrice?.value?.price + props.ProductItem?.cash_fee_buy) * props.ProductItem?.amount: 0
|
||||
props.ProductItem.sellPrice = lastPrice?.value?.price? (lastPrice?.value?.price - props.ProductItem?.percent_fee_sell) * props.ProductItem?.amount:0
|
||||
const livePrice = lastPrice?.value?.price ?? 0
|
||||
const buyFee = resolveProductCashFeeBuyRial(props.ProductItem, livePrice)
|
||||
const sellFee = resolveProductCashFeeSellRial(props.ProductItem, livePrice)
|
||||
props.ProductItem.price = livePrice ? (livePrice + buyFee) * props.ProductItem.amount : 0
|
||||
props.ProductItem.sellPrice = livePrice ? (livePrice - sellFee) * props.ProductItem.amount : 0
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user