Update static/script.js
Browse files- static/script.js +30 -28
static/script.js
CHANGED
|
@@ -539,13 +539,14 @@ async function hienThiHoaChat() {
|
|
| 539 |
const columns = data.columns;
|
| 540 |
const rows = data.rows;
|
| 541 |
|
| 542 |
-
const
|
|
|
|
| 543 |
const idxTinhTrang = columns.findIndex(c => c.toUpperCase().includes("TÌNH TRẠNG"));
|
| 544 |
|
| 545 |
const table = document.getElementById("bangHoaChat");
|
| 546 |
table.innerHTML = "";
|
| 547 |
|
| 548 |
-
//
|
| 549 |
const thead = table.createTHead();
|
| 550 |
const headerRow = thead.insertRow();
|
| 551 |
columns.forEach(col => {
|
|
@@ -557,7 +558,7 @@ async function hienThiHoaChat() {
|
|
| 557 |
headerRow.appendChild(th);
|
| 558 |
});
|
| 559 |
|
| 560 |
-
//
|
| 561 |
const tbody = table.createTBody();
|
| 562 |
rows.forEach((row, rowIndex) => {
|
| 563 |
const tr = tbody.insertRow();
|
|
@@ -569,44 +570,45 @@ async function hienThiHoaChat() {
|
|
| 569 |
input.classList.add("input-cell");
|
| 570 |
input.style.width = "100%";
|
| 571 |
|
| 572 |
-
//
|
| 573 |
if (colIndex === idxTinhTrang) {
|
| 574 |
input.readOnly = true;
|
| 575 |
input.style.fontWeight = "bold";
|
| 576 |
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
if (
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
} else {
|
| 596 |
-
|
| 597 |
-
input.style.backgroundColor = "#eaffea";
|
| 598 |
}
|
| 599 |
-
}
|
| 600 |
|
| 601 |
-
|
| 602 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 603 |
}
|
| 604 |
|
| 605 |
td.appendChild(input);
|
| 606 |
});
|
| 607 |
});
|
| 608 |
|
| 609 |
-
// Hiện nút lưu
|
| 610 |
const nutLuu = document.getElementById("nutLuuHoaChat");
|
| 611 |
if (nutLuu) nutLuu.style.display = "block";
|
| 612 |
|
|
|
|
| 539 |
const columns = data.columns;
|
| 540 |
const rows = data.rows;
|
| 541 |
|
| 542 |
+
const idxNgayNhap = columns.findIndex(c => c.toUpperCase().includes("NGÀY NHẬP"));
|
| 543 |
+
const idxNgayHetHan = columns.findIndex(c => c.toUpperCase().includes("HẠN"));
|
| 544 |
const idxTinhTrang = columns.findIndex(c => c.toUpperCase().includes("TÌNH TRẠNG"));
|
| 545 |
|
| 546 |
const table = document.getElementById("bangHoaChat");
|
| 547 |
table.innerHTML = "";
|
| 548 |
|
| 549 |
+
// Tạo header
|
| 550 |
const thead = table.createTHead();
|
| 551 |
const headerRow = thead.insertRow();
|
| 552 |
columns.forEach(col => {
|
|
|
|
| 558 |
headerRow.appendChild(th);
|
| 559 |
});
|
| 560 |
|
| 561 |
+
// Tạo body
|
| 562 |
const tbody = table.createTBody();
|
| 563 |
rows.forEach((row, rowIndex) => {
|
| 564 |
const tr = tbody.insertRow();
|
|
|
|
| 570 |
input.classList.add("input-cell");
|
| 571 |
input.style.width = "100%";
|
| 572 |
|
| 573 |
+
// Nếu là ô TÌNH TRẠNG
|
| 574 |
if (colIndex === idxTinhTrang) {
|
| 575 |
input.readOnly = true;
|
| 576 |
input.style.fontWeight = "bold";
|
| 577 |
|
| 578 |
+
try {
|
| 579 |
+
const ngayNhapStr = row[idxNgayNhap]?.toString().slice(0, 10);
|
| 580 |
+
const hetHanStr = row[idxNgayHetHan]?.toString().slice(0, 10);
|
| 581 |
+
const ngayHet = new Date(hetHanStr);
|
| 582 |
+
const today = new Date();
|
| 583 |
+
|
| 584 |
+
const daysLeft = Math.ceil((ngayHet - today) / (1000 * 3600 * 24));
|
| 585 |
+
let text = "";
|
| 586 |
+
let color = "";
|
| 587 |
+
|
| 588 |
+
if (isNaN(daysLeft)) {
|
| 589 |
+
text = "Không xác định";
|
| 590 |
+
} else if (daysLeft <= 0) {
|
| 591 |
+
text = "HẾT HẠN";
|
| 592 |
+
color = "red";
|
| 593 |
+
} else if (daysLeft <= 30) {
|
| 594 |
+
text = `CÒN: ${daysLeft} NGÀY`;
|
| 595 |
+
color = "orange";
|
| 596 |
} else {
|
| 597 |
+
text = `CÒN: ${daysLeft} NGÀY`;
|
|
|
|
| 598 |
}
|
|
|
|
| 599 |
|
| 600 |
+
input.value = text;
|
| 601 |
+
input.style.color = color;
|
| 602 |
+
|
| 603 |
+
} catch (e) {
|
| 604 |
+
input.value = "Không xác định";
|
| 605 |
+
}
|
| 606 |
}
|
| 607 |
|
| 608 |
td.appendChild(input);
|
| 609 |
});
|
| 610 |
});
|
| 611 |
|
|
|
|
| 612 |
const nutLuu = document.getElementById("nutLuuHoaChat");
|
| 613 |
if (nutLuu) nutLuu.style.display = "block";
|
| 614 |
|