Update static/script.js
Browse files- static/script.js +65 -0
static/script.js
CHANGED
|
@@ -165,6 +165,11 @@ function chonMuc(muc) {
|
|
| 165 |
if (section) section.style.display = "block";
|
| 166 |
hienThiBangGia4();
|
| 167 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
}
|
| 169 |
|
| 170 |
|
|
@@ -1241,3 +1246,63 @@ async function hienThiBangGia4() {
|
|
| 1241 |
alert("Không thể tải bảng giá Nhiệt & Y tế.");
|
| 1242 |
}
|
| 1243 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
if (section) section.style.display = "block";
|
| 166 |
hienThiBangGia4();
|
| 167 |
}
|
| 168 |
+
if (muc === "banggia3") {
|
| 169 |
+
const section = document.getElementById("banggia3");
|
| 170 |
+
if (section) section.style.display = "block";
|
| 171 |
+
hienThiBangGia4();
|
| 172 |
+
}
|
| 173 |
}
|
| 174 |
|
| 175 |
|
|
|
|
| 1246 |
alert("Không thể tải bảng giá Nhiệt & Y tế.");
|
| 1247 |
}
|
| 1248 |
}
|
| 1249 |
+
async function hienThiBangGia3() {
|
| 1250 |
+
try {
|
| 1251 |
+
const response = await fetch(`${BACKEND_URL}/bang_gia_co_doday_apsuat`);
|
| 1252 |
+
const data = await response.json();
|
| 1253 |
+
|
| 1254 |
+
if (!data || !data.rows || data.rows.length === 0) {
|
| 1255 |
+
$("#tableBangGia3 tbody").html("<tr><td colspan='100%'>Không có dữ liệu</td></tr>");
|
| 1256 |
+
return;
|
| 1257 |
+
}
|
| 1258 |
+
|
| 1259 |
+
let theadHtml = "<tr>";
|
| 1260 |
+
data.columns.forEach(col => {
|
| 1261 |
+
theadHtml += `<th>${col}</th>`;
|
| 1262 |
+
});
|
| 1263 |
+
theadHtml += "</tr>";
|
| 1264 |
+
$("#tableBangGia3 thead").html(theadHtml);
|
| 1265 |
+
|
| 1266 |
+
let tbodyHtml = "";
|
| 1267 |
+
data.rows.forEach(row => {
|
| 1268 |
+
tbodyHtml += "<tr>";
|
| 1269 |
+
row.forEach((cell, i) => {
|
| 1270 |
+
const columnName = data.columns[i];
|
| 1271 |
+
if (columnName.toLowerCase().includes("giá") && !isNaN(cell)) {
|
| 1272 |
+
tbodyHtml += `<td style="text-align:right">${Number(cell).toLocaleString("vi-VN")}</td>`;
|
| 1273 |
+
} else if (columnName.toLowerCase().includes("tên") || columnName.toLowerCase().includes("thiết bị")) {
|
| 1274 |
+
tbodyHtml += `<td style="text-align:left">${cell}</td>`;
|
| 1275 |
+
} else {
|
| 1276 |
+
tbodyHtml += `<td>${cell}</td>`;
|
| 1277 |
+
}
|
| 1278 |
+
});
|
| 1279 |
+
tbodyHtml += "</tr>";
|
| 1280 |
+
});
|
| 1281 |
+
$("#tableBangGia3 tbody").html(tbodyHtml);
|
| 1282 |
+
|
| 1283 |
+
const table = $("#tableBangGia3").DataTable({
|
| 1284 |
+
destroy: true,
|
| 1285 |
+
scrollX: true,
|
| 1286 |
+
autoWidth: false,
|
| 1287 |
+
pageLength: 25,
|
| 1288 |
+
language: {
|
| 1289 |
+
search: "🔍 Tìm kiếm:",
|
| 1290 |
+
lengthMenu: "Hiển thị _MENU_ dòng",
|
| 1291 |
+
info: "Đang hiển thị _START_ đến _END_ của _TOTAL_ dòng",
|
| 1292 |
+
paginate: { previous: "←", next: "→" },
|
| 1293 |
+
emptyTable: "Không có dữ liệu"
|
| 1294 |
+
}
|
| 1295 |
+
});
|
| 1296 |
+
|
| 1297 |
+
setTimeout(() => {
|
| 1298 |
+
table.columns.adjust().draw(false);
|
| 1299 |
+
}, 100);
|
| 1300 |
+
|
| 1301 |
+
$(".fade-in").hide();
|
| 1302 |
+
$("#banggia3").show();
|
| 1303 |
+
|
| 1304 |
+
} catch (err) {
|
| 1305 |
+
console.error("Lỗi khi tải bảng giá:", err);
|
| 1306 |
+
alert("Không thể tải bảng giá Cơ – Độ dài – Áp suất.");
|
| 1307 |
+
}
|
| 1308 |
+
}
|