"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
function get_sp_tu_api() {
return __awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
return resolve(listproduct_mau);
});
});
}
function show_info_product() {
return __awaiter(this, void 0, void 0, function* () {
const lay_thongtin_sp = yield get_sp_tu_api();
// code hien thi danh sach dang dien ra
show_product_detail(lay_thongtin_sp);
});
}
function GetURLParameter(sParam, url) {
var url_decode = decodeURIComponent(url);
var sPageURL = url_decode;
var sURLVariables = sPageURL.split('?');
for (var i = 0; i < sURLVariables.length; i++) {
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam) {
return sParameterName[1];
}
}
}
function XayhtmlProductDeail(product) {
// lay gia cao nhat
const highestBid = getHighestBid(product.list_user);
// xay html hien thi anh san pham
const htmlImage = `
`;
// xay html hien thi thong tin san pham
var HtmlButtonBid = '';
if (product.from_time > Date.now()) {
HtmlButtonBid = `
Số người đang xem: ${product.user_online} người
`;
}
else if (product.to_time > Date.now()) {
HtmlButtonBid = `
Giá cao nhất hiện tại:
${formatPrice(highestBid.highestBid)}đ
Số người đang tham gia: ${product.user_online} người
Đấu giá ngay
`;
}
else {
HtmlButtonBid = `
Giá thắng cuộc:
${formatPrice(highestBid.highestBid)}đ

Người chiến thắng:
${highestBid.highestBidName}
Phiên đấu giá đã kết thúc
`;
}
const htmlInfo = `
${product.product_name}
Khởi điểm:
${formatPrice(product.price)}đ
Bước giá:
${formatPrice(product.price_step)}đ
${HtmlButtonBid}
`;
let html_dien_bien_dau_gia = '';
if (product.from_time < Date.now()) {
const boxParticipant = document.getElementById('box-participant-list');
if (boxParticipant) {
boxParticipant.classList.remove('d-none');
}
product.list_user.forEach((user) => {
html_dien_bien_dau_gia += `
${highestBid.highestBid == user.price ? `
${user.userName}
` : `${user.userName}`}
|
${formatPrice(user.price)}đ
|
${formatTime(user.time)}
|
`;
});
}
const htmlSpec = `
${product.specifications}
`;
return { htmlImage, htmlInfo, html_dien_bien_dau_gia, htmlSpec };
}
function show_product_detail(lay_thongtin_sp) {
const IdProduct = Number(GetURLParameter('id', window.location.href));
const holderImage = document.getElementById('js-holder-image');
const holderInfo = document.getElementById('js-holder-info');
const holderAuctionDetails = document.getElementById('js-holder-auction-details');
const holderSpec = document.getElementById('js-holder-specifications');
lay_thongtin_sp
.filter((product) => product.productId == IdProduct)
.forEach(function (product, keyIndex) {
const { htmlImage, htmlInfo, html_dien_bien_dau_gia, htmlSpec } = XayhtmlProductDeail(product);
holderImage.innerHTML = htmlImage;
holderInfo.innerHTML = htmlInfo;
holderAuctionDetails.innerHTML = html_dien_bien_dau_gia;
holderSpec.innerHTML = htmlSpec;
if (product.from_time > Date.now()) {
countDown(`js-deal-time-${product.productId}`, product.from_time);
}
else if (product.to_time > Date.now()) {
countDown(`js-deal-time-${product.productId}`, product.to_time);
}
});
}
function getHighestBid(list_user) {
let highestBid = 0;
let highestBidName = '';
list_user.forEach(user => {
if (user.price > highestBid) {
highestBid = user.price;
highestBidName = user.userName;
}
});
return { highestBid, highestBidName };
}
function getList() {
}
show_info_product();