diff --git a/src/components/common/product/DealProductItem.tsx b/src/components/common/product/DealProductItem.tsx new file mode 100644 index 0000000..771ed13 --- /dev/null +++ b/src/components/common/product/DealProductItem.tsx @@ -0,0 +1,163 @@ +import React from 'react'; +import Image from 'next/image'; +import Link from 'next/link'; +import { TypeListProductDeal } from '@types/TypeListProductDeal'; + +const formatCurrency = (price: number | string) => { + return Number(price).toLocaleString('vi-VN'); +}; + +const DealProductItem = ({ item }: { item: TypeListProductDeal }) => { + const product = item.product_info; + const quantityLeft = item.quantity - item.sale_quantity; + + return ( +
+ + {product.productName} + + + {product.productType?.isHot === 1 && } + {product.productType?.isNew === 1 && } + + + +
+ +

{product.productName}

+ + +
+ {product.marketPrice > 0 ? ( + <> +

{product.marketPrice.toLocaleString()} ₫

+
-{parseInt(product.price_off || '0')}%
+ + ) : product.sale_rules?.type === 'deal' ? ( + <> +

+ {product.sale_rules.normal_price.toLocaleString()} ₫ +

+
0%
+ + ) : null} +
+ +
+ {Number(item.price) > 0 ? `${formatCurrency(item.price)}đ` : 'Liên hệ'} +
+ +
+ +
+

+ + Còn {quantityLeft}/ {item.quantity} sản phẩm + +
+ + {product.specialOffer?.all?.length > 0 ? ( +
+ ) : ( +
+ )} +
+ + {/* TOOLTIP */} +
+
{product.productName}
+
+
+ {product.marketPrice > 0 ? ( +

Giá niêm yết

+ ) : ( + product.sale_rules?.type === 'deal' &&

Giá gốc

+ )} +

Giá bán

+ {product.warranty !== '' &&

Bảo hành

} +

Tình trạng

+
+ +
+ {product.marketPrice > 0 ? ( +
+

+ {product.marketPrice.toLocaleString()}₫ + +

+ + -{product.price_off}% + +
+ ) : product.sale_rules?.type === 'deal' ? ( +
+

+ {product.sale_rules.normal_price.toLocaleString()} ₫ + +

+ + - + {Math.floor( + 100 - + (Number(product.sale_rules.price) / product.sale_rules.normal_price) * 100, + )} + % + +
+ ) : null} + +

{Number(product.price) > 0 ? `${formatCurrency(product.price)}đ` : 'Liên hệ'}

+

{product.warranty}

+

{quantityLeft > 0 ? 'Còn DEAL' : 'Hết DEAL'}

+
+
+ + {product.productSummary && ( + <> +
+ + Thông số sản phẩm +
+
+ +
+ + )} + + {product.specialOffer?.all?.length > 0 && ( +
+
+

+ Khuyến mãi +

+
+
+
    +
+
+ )} +
+
+ ); +}; + +export default DealProductItem; diff --git a/src/components/layout/home/BoxDeal/ProductItem.tsx b/src/components/layout/home/BoxDeal/ProductItem.tsx deleted file mode 100644 index b55a450..0000000 --- a/src/components/layout/home/BoxDeal/ProductItem.tsx +++ /dev/null @@ -1 +0,0 @@ -const ProductItem = ({ item }: { item: Product }) => {}; diff --git a/src/components/layout/home/BoxDeal/index.tsx b/src/components/layout/home/BoxDeal/index.tsx index 520687f..91ba7c8 100644 --- a/src/components/layout/home/BoxDeal/index.tsx +++ b/src/components/layout/home/BoxDeal/index.tsx @@ -3,7 +3,10 @@ import React from 'react'; import { Swiper, SwiperSlide } from 'swiper/react'; import { Autoplay, Navigation, Pagination } from 'swiper/modules'; import { FaCaretRight } from 'react-icons/fa'; + import CounDown from './CounDown'; +import { productDealData } from './productDealData'; +import DealProductItem from '@Common/product/DealProductItem'; const BoxProductDeal: React.FC = () => { return ( @@ -28,7 +31,13 @@ const BoxProductDeal: React.FC = () => { slidesPerView={6} loop={true} navigation={true} - > + > + {productDealData.map((item, index) => ( + + + + ))} +
); diff --git a/tsconfig.json b/tsconfig.json index 7da22be..e8e3e3e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -22,7 +22,8 @@ "@/*": ["./src/*"], "@components/*": ["./src/components/*"], "@types/*": ["./src/types/*"], - "@styles/*": ["./src/styles/*"] + "@styles/*": ["./src/styles/*"], + "@Common/*": ["./src/components/Common/*"] } }, "include": [