Spaces:
Sleeping

doluong6 commited on
Commit
8a3817f
·
verified ·
1 Parent(s): 2904a28

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +29 -55
static/script.js CHANGED
@@ -18,77 +18,51 @@ function login() {
18
  }
19
 
20
  function chonMuc(muc) {
 
21
  if (muc === "cho_xu_ly") {
22
  hienThiChoXuLy();
 
 
 
 
23
  }
24
  }
25
 
26
- async function hienThiChoXuLy() {
27
- const bang = document.getElementById("bangChiTiet");
28
- const tieuDe = document.getElementById("tieuDeBang");
29
- const noiDung = document.getElementById("noiDungBang");
30
-
31
- // Reset nội dung
32
- tieuDe.innerText = "Phiếu chờ xử lý";
33
- noiDung.innerHTML = "";
34
 
35
- // 1. Gọi API đếm phiếu
36
- try {
37
- const res = await fetch("/dem_pyc_tat_ca");
38
- const data = await res.json();
39
- const card = document.createElement("div");
40
- card.className = "card";
41
- card.innerHTML = `
42
- <h3>Số phiếu chờ xử lý</h3>
43
- <p>${data.tong_so_pyc || 0}</p>
44
- `;
45
- noiDung.appendChild(card);
46
- } catch (err) {
47
- console.error("Lỗi lấy số phiếu:", err);
48
- noiDung.innerHTML += "<p>Lỗi khi tải tổng số phiếu.</p>";
49
- }
50
 
51
- // 2. Gọi API danh sách chi tiết
52
  try {
53
  const res = await fetch("/ds_pyc_cho_xu_ly");
54
  const ds = await res.json();
55
 
56
- if (!Array.isArray(ds) || ds.length === 0) {
57
- noiDung.innerHTML += "<p>Không có phiếu nào đang chờ xử lý.</p>";
58
- return;
59
- }
60
-
61
- let html = `
62
- <table class='display' id='tableChoXuLy'>
63
- <thead>
64
- <tr>
65
- <th>Khách hàng</th>
66
- <th>File phiếu yêu cầu</th>
67
- </tr>
68
- </thead>
69
- <tbody>
70
- ${ds.map(row => `
71
- <tr>
72
- <td>${row["Khách hàng"]}</td>
73
- <td>${row["File PYC"]}</td>
74
- </tr>
75
- `).join("")}
76
- </tbody>
77
- </table>
78
- `;
79
- noiDung.innerHTML += html;
80
 
81
- // Kích hoạt DataTables
82
- $(document).ready(() => {
83
- $('#tableChoXuLy').DataTable();
 
 
 
 
84
  });
85
 
 
 
 
86
  } catch (err) {
87
- console.error("Lỗi lấy danh sách:", err);
88
- noiDung.innerHTML += "<p>Lỗi khi tải danh sách phiếu.</p>";
 
 
89
  }
90
-
91
- bang.style.display = "block";
92
  }
93
 
94
  function toggleSubmenu(id) {
 
18
  }
19
 
20
  function chonMuc(muc) {
21
+ anTatCa();
22
  if (muc === "cho_xu_ly") {
23
  hienThiChoXuLy();
24
+ } else if (muc === "completedRequests") {
25
+ document.getElementById("daHoanThanh").style.display = "flex";
26
+ } else if (muc === "requestRevenue") {
27
+ document.getElementById("doanhThuPYC").style.display = "flex";
28
  }
29
  }
30
 
31
+ function anTatCa() {
32
+ document.getElementById("bangChiTiet").style.display = "none";
33
+ document.getElementById("daHoanThanh").style.display = "none";
34
+ document.getElementById("doanhThuPYC").style.display = "none";
35
+ document.getElementById("bangPYCChoXuLy").style.display = "none";
36
+ }
 
 
37
 
38
+ async function hienThiChoXuLy() {
39
+ anTatCa();
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
 
41
  try {
42
  const res = await fetch("/ds_pyc_cho_xu_ly");
43
  const ds = await res.json();
44
 
45
+ const tbody = document.querySelector("#tablePYCChoXuLy tbody");
46
+ tbody.innerHTML = "";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
+ ds.forEach(item => {
49
+ const tr = document.createElement("tr");
50
+ tr.innerHTML = `
51
+ <td>${item["Khách hàng"]}</td>
52
+ <td>${item["File PYC"]}</td>
53
+ `;
54
+ tbody.appendChild(tr);
55
  });
56
 
57
+ document.getElementById("bangPYCChoXuLy").style.display = "block";
58
+ $("#tablePYCChoXuLy").DataTable();
59
+
60
  } catch (err) {
61
+ console.error("Lỗi khi tải danh sách chờ xử lý:", err);
62
+ const tbody = document.querySelector("#tablePYCChoXuLy tbody");
63
+ tbody.innerHTML = "<tr><td colspan='2'>Lỗi khi tải dữ liệu</td></tr>";
64
+ document.getElementById("bangPYCChoXuLy").style.display = "block";
65
  }
 
 
66
  }
67
 
68
  function toggleSubmenu(id) {