async function goi_sp_tu_api(): Promise { 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 = `
Còn lại:
Đấu giá ngay`; } else if (product.status == 'coming') { Htmlcheckstatus = `
Bắt đầu sau:
Xem chi tiết`; } else if (product.to_time < Date.now()) { Htmlcheckstatus = `
Thắng cuộc ${formatPrice(product.starting_price)}đ
Đã kết thúc
Xem chi tiết`; } return `
${product.product_name}
${product.product_name}
Giá gốc: ${formatPrice(product.price)}đ
${Htmlcheckstatus}
`; } hienthi_sp();