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