24 lines
843 B
TypeScript
24 lines
843 B
TypeScript
import type { Product } from '@/models/products'
|
|||
|
|
import { lastPrice } from '@/utils/price'
|
||
|
|
|
||
|
|
/** قیمت خرید نمایشی محصول (همان مقداری که در لیست و اکشنشیت نشان داده میشود) */
|
||
|
|
export function getProductBuyPrice(product: Product): number {
|
||
|
|
if (product.group_type === 'آبشده') {
|
||
|
|
return lastPrice.value?.buy ?? 0
|
||
|
|
}
|
||
|
|
|
||
|
|
if (['مس', 'نقره'].includes(product.group_type)) {
|
||
|
|
const base = (product.price_profit ?? 0) + (product.price ?? 0)
|
||
|
|
return base + (product.cash_fee_buy ?? 0)
|
||
|
|
}
|
||
|
|
|
||
|
|
const basePrice = (product.price ?? 0) + (product.cash_fee_buy ?? 0)
|
||
|
|
return product.direct_price === 0
|
||
|
|
? basePrice * (product.amount ?? 0)
|
||
|
|
: basePrice
|
||
|
|
}
|
||
|
|
|
||
|
|
export function isProductPriceInactive(product: Product): boolean {
|
||
|
|
return getProductBuyPrice(product) <= 0
|
||
|
|
}
|