This commit is contained in:
2026-08-02 12:26:28 +03:30
parent 2dd2d3a624
commit 68ba464f10
2 changed files with 43 additions and 29 deletions
+1
View File
@@ -24,6 +24,7 @@ export interface Price {
buy: number
price: number
price_last: number
last_historical?: number
goldir?: number
up?: PriceUp
closed?: boolean
@@ -803,8 +803,6 @@ import type { Price } from '@/models/home'
import { persianToEnglishDigits } from '@/utils/persianDigits'
import {
applyLastPricePayload,
getTradeBuyPrice,
getTradeSellPrice,
lastPrice,
percentPriceChanged,
} from '@/utils/price'
@@ -817,7 +815,6 @@ import {
} from '@/utils/usePrice'
import {
CHART_METAL_MARKUP_RATIO,
resolveMetalDayRangePrices,
type ChartMetalType,
} from '@/views/base/home/composables/usePriceChart'
import { useAboutUsPageContext } from '../composables/useAboutUsPage'
@@ -849,10 +846,6 @@ const patternMaskStyle = computed(() => ({
const LIVE_SECTION_METAL: ChartMetalType = 'maftol'
const activeMetal = computed<ChartMetalType>(() =>
activeProduct.value === 'wire' ? 'maftol' : 'katod',
)
const orderCardSubtitle = computed(() =>
activeProduct.value === 'wire' ? 'مقدار مفتول مس قابل خرید' : 'مقدار کاتد مس قابل خرید',
)
@@ -863,11 +856,19 @@ function applyMetalMarkup(basePrice: number, metal: ChartMetalType) {
return Math.round(basePrice + basePrice * ratio)
}
const baseBuyPrice = computed(() => getTradeBuyPrice(lastPrice.value))
/** پایهٔ همهٔ قیمت‌های لندینگ — فقط فیلد buy از /api/price/last */
const baseBuyPrice = computed(() => {
const buy = Number(lastPrice.value?.buy ?? 0)
return Number.isFinite(buy) && buy > 0 ? buy : 0
})
const liveUnitPrice = computed(() =>
applyMetalMarkup(baseBuyPrice.value, activeMetal.value),
)
/** کاتد: buy خام — مفتول: buy + ۶٪ */
const liveUnitPrice = computed(() => {
if (activeProduct.value === 'cathode') {
return baseBuyPrice.value
}
return applyMetalMarkup(baseBuyPrice.value, 'maftol')
})
/** قیمت مفتول مس — همیشه برای سکشن قیمت لحظه‌ای لندینگ */
const wireLiveUnitPrice = computed(() =>
@@ -943,17 +944,17 @@ function writeCachedChartValues(values: number[]) {
}
}
/** سری پایه از آخرین مظنه موجود — برای نمایش نوسان تا آخرین لحظه */
/** سری پایه از فیلد buy — برای نمایش نوسان تا آخرین مظنه خرید */
function buildFallbackChartValuesFromPrice(price = lastPrice.value): number[] {
if (!price) return []
const buy = getTradeBuyPrice(price)
const sell = getTradeSellPrice(price)
const last = Number(price.price_last ?? buy ?? 0)
const highBase = Number(price.up?.buy ?? buy ?? last)
const lowBase = Number(price.up?.sell ?? sell ?? last)
const end = last || buy
if (!(end > 0)) return []
const buy = Number(price.buy ?? 0)
if (!(Number.isFinite(buy) && buy > 0)) return []
const sell = Number(price.sell ?? 0)
const highBase = Number(price.up?.buy ?? buy)
const lowBase = Number(price.up?.sell ?? (sell > 0 ? sell : buy))
const end = buy
let lo = lowBase > 0 ? lowBase : end
let hi = highBase > 0 ? highBase : end
@@ -999,11 +1000,16 @@ const effectiveRawChartValues = computed(() => {
return buildFallbackChartValuesFromPrice()
})
const chartValues = computed(() =>
effectiveRawChartValues.value
.map((value) => applyMetalMarkup(value, activeMetal.value))
.filter((value) => Number.isFinite(value) && value > 0),
)
const chartValues = computed(() => {
const raw = effectiveRawChartValues.value
// کاتد: بدون مارک‌آپ — مفتول: +۶٪ مثل قیمت لحظه‌ای
if (activeProduct.value === 'cathode') {
return raw.filter((value) => Number.isFinite(value) && value > 0)
}
return raw
.map((value) => applyMetalMarkup(value, 'maftol'))
.filter((value) => Number.isFinite(value) && value > 0)
})
const wireChartValues = computed(() =>
effectiveRawChartValues.value
@@ -1052,11 +1058,18 @@ const wireDayChangeAmountLabel = computed(() => {
})
const dayRangePrices = computed(() => {
const fromApi = resolveMetalDayRangePrices({
price: lastPrice.value,
metal: LIVE_SECTION_METAL,
metalRatio: CHART_METAL_MARKUP_RATIO[LIVE_SECTION_METAL],
})
// پایه از buy/sell API — سپس مارک‌آپ مفتول برای سکشن live
const buy = Number(lastPrice.value?.buy ?? 0)
const sell = Number(lastPrice.value?.sell ?? 0)
const fromApi = {
high: buy > 0 ? applyMetalMarkup(buy, LIVE_SECTION_METAL) : 0,
low:
sell > 0
? applyMetalMarkup(sell, LIVE_SECTION_METAL)
: buy > 0
? applyMetalMarkup(buy, LIVE_SECTION_METAL)
: 0,
}
const values = wireChartValues.value
if (values.length > 0) {
const chartHigh = Math.max(...values)