83 lines
3.3 KiB
TypeScript
83 lines
3.3 KiB
TypeScript
|
|
async function goi_sp_tu_api(): Promise<ProductInfo[]> {
|
|
return new Promise((resolve, reject) => {
|
|
return resolve(listproduct_mau);
|
|
})
|
|
}
|
|
|
|
|
|
async function hienthi_sp() {
|
|
const lay_sp_tu_api: ProductInfo[] = await goi_sp_tu_api();
|
|
|
|
// code hien thi danh sach dang dien ra
|
|
// Usage example:
|
|
showListProductHome(lay_sp_tu_api, 'started', 'js-holder-list-started');
|
|
showListProductHome(lay_sp_tu_api, 'coming', 'js-holder-list-coming');
|
|
showListProductHome(lay_sp_tu_api, 'ended', 'js-holder-list-ended');
|
|
}
|
|
|
|
function showListProductHome(lay_sp_tu_api: ProductInfo[], status: string, holderId: string) {
|
|
const html: string[] = [];
|
|
const holder = document.getElementById(holderId);
|
|
|
|
lay_sp_tu_api
|
|
.filter((product: ProductInfo) => product.status == status)
|
|
.forEach(function (product, keyIndex) {
|
|
html.push(
|
|
xayhtml(product)
|
|
);
|
|
if (status != 'ended' || product.to_time > product.from_time) {
|
|
const countdownTime = (status == 'started') ? product.to_time : product.from_time;
|
|
countDown(`js-deal-time-${product.productId}`, countdownTime);
|
|
}
|
|
});
|
|
|
|
if (holder) {
|
|
holder.innerHTML = html.join('');
|
|
}
|
|
}
|
|
|
|
function xayhtml(product: ProductInfo) {
|
|
var Htmlcheckstatus: string = ''
|
|
if (product.status == 'started') {
|
|
Htmlcheckstatus = `<div class="deal-time-holder d-flex align-items space-center">
|
|
<div class="txt">Còn lại:</div>
|
|
<div class="product-time-holder js-deal-time-${product.productId}" data-time="${product.to_time}">
|
|
</div>
|
|
</div>
|
|
<a href="/auction_program/product-detail.html?id=${product.productId}" class="btn-auction">Đấu giá ngay</a>`;
|
|
} else if (product.status == 'coming') {
|
|
Htmlcheckstatus = `<div class="deal-time-holder d-flex align-items space-center">
|
|
<div class="txt">Bắt đầu sau:</div>
|
|
<div class="product-time-holder js-deal-time-${product.productId}" data-time="${product.from_time}">
|
|
</div>
|
|
</div>
|
|
<a href="/auction_program/product-detail.html?id=${product.productId}" class="btn-auction">Xem chi tiết</a>`;
|
|
} else if (product.to_time < Date.now()) {
|
|
Htmlcheckstatus = `<div class="starting-price">Thắng cuộc ${formatPrice(product.starting_price)}<u>đ</u></div>
|
|
<div class="deal-time-holder d-flex align-items space-center end">
|
|
<div class="txt">Đã kết thúc</div>
|
|
</div>
|
|
<a href="/auction_program/product-detail.html?id=${product.productId}" class="btn-auction">Xem chi tiết</a>`;
|
|
}
|
|
return `<div class="product-item">
|
|
<a href="/product-detail.html?id=${product.productId}" class="product-image">
|
|
<img src="${product.image}" alt="${product.product_name}">
|
|
</a>
|
|
<div class="info-product">
|
|
<a href="" class="product-name line-clamp-2">${product.product_name}</a>
|
|
<div class="product-cost">
|
|
Giá gốc: ${formatPrice(product.price)}đ
|
|
</div>
|
|
${Htmlcheckstatus}
|
|
</div>
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
|
|
hienthi_sp();
|
|
|
|
|
|
|