20 lines
533 B
TypeScript
20 lines
533 B
TypeScript
|
|
// Add tất cả sp trong data product vào 1 mảng
|
||
|
|
import { productList } from '@/data/products';
|
||
|
|
|
||
|
|
export function getAllProducts() {
|
||
|
|
return productList.flatMap((group:any) => group.list);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Format giá
|
||
|
|
export function formatPrice(amount: number) {
|
||
|
|
return amount.toLocaleString('vi-VN');
|
||
|
|
}
|
||
|
|
|
||
|
|
// Tính % giảm giá
|
||
|
|
export function calculateDiscount(
|
||
|
|
price: number,
|
||
|
|
marketPrice: number
|
||
|
|
) {
|
||
|
|
if (price <= 0 || marketPrice <= price) return 0;
|
||
|
|
return Math.ceil(((marketPrice - price) / marketPrice) * 100);
|
||
|
|
}
|