From 4c707849efb9e20dda21b78d5d51ceb95230bff1 Mon Sep 17 00:00:00 2001 From: adonis Date: Sat, 6 Jun 2026 15:48:27 +0330 Subject: [PATCH] fix some bug --- src/utils/price.ts | 18 +++++------------- src/utils/productPrice.ts | 12 ++++++++++-- src/views/base/gold/index.vue | 11 ++++++++--- .../base/home/components/CurrentPrice.vue | 8 ++++---- .../base/products/components/ProductItem.vue | 7 ++----- 5 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/utils/price.ts b/src/utils/price.ts index a8e3bbe..88df9b3 100644 --- a/src/utils/price.ts +++ b/src/utils/price.ts @@ -9,26 +9,18 @@ export const price = ref() export const lastPrice = ref() export const olderPrice = ref(0) -/** buy/sell معامله: اول up (مثل endpoint قدیمی /price/up) سپس fallback */ +/** buy/sell نمایش و معامله — همان buy/sell/price_last از /api/price/last */ export function getTradeBuyPrice(p?: Price | null) { - return p?.up?.buy ?? p?.buy ?? 0 + return p?.buy ?? p?.price_last ?? p?.up?.buy ?? 0 } export function getTradeSellPrice(p?: Price | null) { - return p?.up?.sell ?? p?.sell ?? 0 + return p?.sell ?? p?.up?.sell ?? 0 } -/** یکسان‌سازی پاسخ last با رفتار قدیمی price/up */ +/** up جدا نگه داشته می‌شود؛ buy/sell/price_last از lastPrice سرور دست‌نخورده می‌ماند */ export function normalizePriceResponse(data: Price): Price { - if (!data?.up) { - return data - } - - return { - ...data, - buy: data.up.buy, - sell: data.up.sell, - } + return data } export async function setIntervalGetAllPrice() { diff --git a/src/utils/productPrice.ts b/src/utils/productPrice.ts index b8b24ab..4843c67 100644 --- a/src/utils/productPrice.ts +++ b/src/utils/productPrice.ts @@ -1,10 +1,10 @@ import type { Product } from '@/models/products' -import { getTradeBuyPrice, lastPrice } from '@/utils/price' +import { getTradeBuyPrice, getTradeSellPrice, lastPrice } from '@/utils/price' /** قیمت خرید نمایشی محصول (همان مقداری که در لیست و اکشن‌شیت نشان داده می‌شود) */ export function getProductBuyPrice(product: Product): number { if (product.group_type === 'آبشده') { - return getTradeBuyPrice(lastPrice.value) + return getTradeBuyPrice(lastPrice.value) + (product.cash_fee_buy ?? 0) } if (['مس', 'نقره'].includes(product.group_type)) { @@ -18,6 +18,14 @@ export function getProductBuyPrice(product: Product): number { : basePrice } +/** قیمت فروش نمایشی آبشده — فقط cash_fee_sell محصول اختلاف ایجاد می‌کند */ +export function getProductSellPrice(product: Product): number { + if (product.group_type === 'آبشده') { + return getTradeSellPrice(lastPrice.value) - (product.cash_fee_sell ?? 0) + } + return getTradeSellPrice(lastPrice.value) +} + export function isProductPriceInactive(product: Product): boolean { return getProductBuyPrice(product) <= 0 } diff --git a/src/views/base/gold/index.vue b/src/views/base/gold/index.vue index dc5a684..d1ec275 100644 --- a/src/views/base/gold/index.vue +++ b/src/views/base/gold/index.vue @@ -227,6 +227,7 @@ import type { Transaction } from '@/models/transaction' import type { TableEngineInput, TableOutput } from '@/models/table' import { useInfiniteScroll } from '@vueuse/core' import { getTransactionTable } from '@/api/transaction' +import { getProductBuyPrice, getProductSellPrice } from '@/utils/productPrice' import { getLastPrices, getTradeBuyPrice, getTradeSellPrice, lastPrice, setIntervalGetAllPrice, stopPriceInterval } from '@/utils/price' import type { Product } from '@/models/products' import { useFundUserStore } from '@/store/fundStore' @@ -277,9 +278,13 @@ const sellPagination = ref({ }], limit: 6, page: 0 }) -const unitPrice = computed(() => - isBuy.value ? getTradeBuyPrice(lastPrice.value) : getTradeSellPrice(lastPrice.value) -) +const unitPrice = computed(() => { + const product = props.ProductItem + if (product?.group_type === 'آبشده') { + return isBuy.value ? getProductBuyPrice(product) : getProductSellPrice(product) + } + return isBuy.value ? getTradeBuyPrice(lastPrice.value) : getTradeSellPrice(lastPrice.value) +}) const feeInGrams = computed(() => calcFeeInGrams(form.value?.goldValue)) const finalPrice = computed(() => (form.value?.goldValue ?? 0) * unitPrice.value) const feeInRial = computed(() => unitPrice.value * feeInGrams.value) diff --git a/src/views/base/home/components/CurrentPrice.vue b/src/views/base/home/components/CurrentPrice.vue index 5e2075a..65e303f 100644 --- a/src/views/base/home/components/CurrentPrice.vue +++ b/src/views/base/home/components/CurrentPrice.vue @@ -31,7 +31,7 @@