Update static/script.js
Browse files- static/script.js +28 -0
static/script.js
CHANGED
|
@@ -640,6 +640,34 @@ async function hienThiHoaChat() {
|
|
| 640 |
});
|
| 641 |
|
| 642 |
document.getElementById("nutLuuHoaChat").style.display = "block";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 643 |
} catch (err) {
|
| 644 |
console.error("Lỗi khi tải danh mục hóa chất:", err);
|
| 645 |
alert("❌ Không thể tải dữ liệu hóa chất.");
|
|
|
|
| 640 |
});
|
| 641 |
|
| 642 |
document.getElementById("nutLuuHoaChat").style.display = "block";
|
| 643 |
+
// 🔸 Hiển thị nút trích xuất
|
| 644 |
+
const btnExport = document.getElementById("nutTrichXuat160");
|
| 645 |
+
btnExport.style.display = "inline-block";
|
| 646 |
+
|
| 647 |
+
// 🔸 Gắn sự kiện click để trích xuất danh sách <=160 ngày
|
| 648 |
+
btnExport.onclick = function () {
|
| 649 |
+
let csvContent = "data:text/csv;charset=utf-8," + columns.join(",") + "\n";
|
| 650 |
+
|
| 651 |
+
rows.forEach(row => {
|
| 652 |
+
const hanSD = parseNgayVN(row[idxHanSD]);
|
| 653 |
+
if (hanSD instanceof Date && !isNaN(hanSD)) {
|
| 654 |
+
const today = new Date();
|
| 655 |
+
const diffDays = Math.ceil((hanSD - today) / (1000 * 3600 * 24));
|
| 656 |
+
if (diffDays <= 160) {
|
| 657 |
+
const rowData = row.map(v => `"${v}"`).join(",");
|
| 658 |
+
csvContent += rowData + "\n";
|
| 659 |
+
}
|
| 660 |
+
}
|
| 661 |
+
});
|
| 662 |
+
|
| 663 |
+
const encodedUri = encodeURI(csvContent);
|
| 664 |
+
const link = document.createElement("a");
|
| 665 |
+
link.setAttribute("href", encodedUri);
|
| 666 |
+
link.setAttribute("download", "hoa_chat_can_canh_bao.csv");
|
| 667 |
+
document.body.appendChild(link);
|
| 668 |
+
link.click();
|
| 669 |
+
document.body.removeChild(link);
|
| 670 |
+
};
|
| 671 |
} catch (err) {
|
| 672 |
console.error("Lỗi khi tải danh mục hóa chất:", err);
|
| 673 |
alert("❌ Không thể tải dữ liệu hóa chất.");
|