function getJackpotBox(selector, api) {
$().ready(function () {
$(`${selector}`).html(`
`)
$('head').append(`
`)
$.ajax({
url: `${api}`,
method: "GET",
headers: {
'Content-Type': 'application/json'
},
success: function (result) {
result = JSON.parse(result)
if (result?.Data?.data?.kqxs) {
const data = result?.Data?.data?.kqxs,
date = new Date(data.Date),
special = data.DB,
g1 = data?.G1,
g2 = data?.G2,
g3 = data?.G3,
g4 = data?.G4,
g5 = data?.G5,
g6 = data?.G6,
g7 = data?.G7,
g8 = data?.G8,
numbers = special.concat(g1, g2, g3, g4, g5, g6, g7),
area = data?.Area
const day = date.getDate(),
month = date.getMonth() + 1,
year = date.getFullYear()
$(`${selector} .box-title`).text(`kết quả xổ số ngày ${day}/${month}/${year}`)
var html = ''
if (area == 1) {
for (let x in data) {
switch (x) {
case 'DB':
html += templateJackpot(special, '', 1, 'Đặc biệt')
break
case 'G1':
html += templateJackpot(g1, '', 1, 'Giải nhất')
break
case 'G2':
html += templateJackpot(g2, '', 2, 'Giải nhì')
break
case 'G3':
html += templateJackpot(g3, 2, 3, 'Giải ba')
break
case 'G4':
html += templateJackpot(g4, '', 4, 'Giải tư')
break
case 'G5':
if (screen.width < 768) {
html += templateJackpot(g5, 2, 3, 'Giải năm')
break
}
html += templateJackpot(g5, '', 6, 'Giải năm')
break
case 'G6':
html += templateJackpot(g6, '', 3, 'Giải sáu')
break
case 'G7':
html += templateJackpot(g7, '', 4, 'Giải bảy')
break
}
}
} else if (area == 2 || area == 3) {
for (let x in data) {
switch (x) {
case 'DB':
html += templateJackpot(special, 1, 1, 'Đặc biệt')
break
case 'G1':
html += templateJackpot(g1, 1, 1, 'Giải nhất')
break
case 'G2':
html += templateJackpot(g2, 1, 1, 'Giải nhì')
break
case 'G3':
html += templateJackpot(g3, 1, 2, 'Giải ba')
break
case 'G4':
html += templateJackpot(g4, 2, 4, 'Giải tư')
break
case 'G5':
html += templateJackpot(g5, 1, 1, 'Giải năm')
break
case 'G6':
html += templateJackpot(g6, 1, 3, 'Giải sáu')
break
case 'G7':
html += templateJackpot(g7, 1, 1, 'Giải bảy')
break
case 'G8':
html += templateJackpot(g8, 1, 1, 'Giải tám')
break
}
}
}
$(`${selector} .jp-box__table`).html(html)
// Hiển thị số chữ số
;
(function () {
const radioSelections = document.querySelectorAll(`${selector} .checkcontainer input`);
[...radioSelections].forEach(item => {
item.onclick = (e) => {
const className = e.target.classList.value
switch (className) {
case 'full-number':
getNumbers(0)
break
case 'two-number':
getNumbers(-2)
break;
case 'three-number':
getNumbers(-3)
break;
}
}
})
})()
function getNumbers(sub) {
const numberElements = [...document.querySelectorAll(`${selector} [class*="col-"]`)]
numbers.forEach((item, index) => {
numberElements[index].innerHTML = item.substr(sub)
})
}
}
}
});
});
}
function templateJackpot(jackpot, rows, col, jpName) {
const colNumber = jackpot.map((item, index) => {
if (jpName == 'Đặc biệt') {
return `${item}
`
}
if (rows == 2) {
if (index <= col - 1) {
return `${item}
`
}
}
return `${item}
`
}).join('')
const html = `
`
return html
}