Spaces:
Sleeping

doluong6 commited on
Commit
54f7f34
·
verified ·
1 Parent(s): fbfa06f

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +50 -25
static/script.js CHANGED
@@ -670,23 +670,38 @@ async function hienThiHSKH() {
670
  }
671
 
672
  const fullIndex = data.columns.indexOf("Full");
 
 
 
673
 
674
- const danhSachNguoiTiepNhan = [
675
- "Lê Danh Huy",
676
- "Trần Văn Dương",
677
- "Nguyễn Mạnh Cường",
678
- "Nguyễn Ngọc Vinh"
679
- ];
680
-
681
- const danhSachPhongYeuCau = ["ĐL1", "ĐL2", "ĐL3", "ĐL4", "ĐL5", "QA"];
682
-
683
- // Xóa DataTable cũ nếu có
684
  if ($.fn.DataTable.isDataTable("#bangHSKH")) {
685
  $('#bangHSKH').DataTable().clear().destroy();
686
  }
687
 
688
  let tbodyHtml = "";
689
- data.rows.forEach(row => {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
690
  const isFullChecked = (row[fullIndex] || "").toLowerCase() === "x";
691
  const rowClass = isFullChecked ? "full-row" : "not-full-row";
692
 
@@ -694,7 +709,11 @@ async function hienThiHSKH() {
694
 
695
  for (let j = 0; j < data.columns.length; j++) {
696
  const col = data.columns[j];
697
- const cell = row[j] || "";
 
 
 
 
698
 
699
  if (["Full", "PYC", "BB", "GCN"].includes(col)) {
700
  const checked = cell.toLowerCase() === "x" ? "checked" : "";
@@ -703,26 +722,32 @@ async function hienThiHSKH() {
703
  } else if (col === "Tên Khách hàng" || col === "Tên Cơ sở sử dụng") {
704
  tbodyHtml += `<td><textarea class="input-area">${cell}</textarea></td>`;
705
  } else if (col === "Người tiếp nhận") {
706
- tbodyHtml += `<td><select class="input-cell">`;
707
- danhSachNguoiTiepNhan.forEach(name => {
708
- const selected = name === cell ? "selected" : "";
709
- tbodyHtml += `<option value="${name}" ${selected}>${name}</option>`;
710
- });
711
- tbodyHtml += `</select></td>`;
 
 
712
  } else if (col === "Phòng yêu cầu") {
713
- tbodyHtml += `<td><select class="input-cell">`;
714
- danhSachPhongYeuCau.forEach(phong => {
715
- const selected = phong === cell ? "selected" : "";
716
- tbodyHtml += `<option value="${phong}" ${selected}>${phong}</option>`;
717
- });
718
- tbodyHtml += `</select></td>`;
 
 
 
 
719
  } else {
720
  tbodyHtml += `<td><input class="input-cell" type="text" value="${cell}" /></td>`;
721
  }
722
  }
723
 
724
  tbodyHtml += `</tr>`;
725
- });
726
 
727
  $("#bangHSKH tbody").html(tbodyHtml);
728
 
 
670
  }
671
 
672
  const fullIndex = data.columns.indexOf("Full");
673
+ const pycIndex = data.columns.indexOf("SỐ PYC");
674
+ const tenKHIndex = data.columns.indexOf("Tên Khách hàng");
675
+ const coSoIndex = data.columns.indexOf("Tên Cơ sở sử dụng");
676
 
 
 
 
 
 
 
 
 
 
 
677
  if ($.fn.DataTable.isDataTable("#bangHSKH")) {
678
  $('#bangHSKH').DataTable().clear().destroy();
679
  }
680
 
681
  let tbodyHtml = "";
682
+
683
+ for (let i = 0; i < data.rows.length; i++) {
684
+ const row = data.rows[i];
685
+ const soPYC = row[pycIndex] || "";
686
+
687
+ // Lấy thông tin từ API
688
+ let tenKH = row[tenKHIndex] || "";
689
+ let coSo = row[coSoIndex] || "";
690
+
691
+ if (soPYC) {
692
+ try {
693
+ const pycRes = await fetch(`${BACKEND_URL}/lay_thong_tin_pyc?so_pyc=${encodeURIComponent(soPYC)}`);
694
+ if (pycRes.ok) {
695
+ const pycData = await pycRes.json();
696
+ tenKH = pycData.ten_khach_hang || tenKH;
697
+ coSo = pycData.co_so_su_dung || coSo;
698
+ }
699
+ } catch (e) {
700
+ console.warn(`Không lấy được dữ liệu cho ${soPYC}`);
701
+ }
702
+ }
703
+
704
+ // Cập nhật lại hàng với thông tin mới
705
  const isFullChecked = (row[fullIndex] || "").toLowerCase() === "x";
706
  const rowClass = isFullChecked ? "full-row" : "not-full-row";
707
 
 
709
 
710
  for (let j = 0; j < data.columns.length; j++) {
711
  const col = data.columns[j];
712
+ let cell = row[j] || "";
713
+
714
+ // Ghi đè nếu là KH hoặc Cơ sở
715
+ if (j === tenKHIndex) cell = tenKH;
716
+ if (j === coSoIndex) cell = coSo;
717
 
718
  if (["Full", "PYC", "BB", "GCN"].includes(col)) {
719
  const checked = cell.toLowerCase() === "x" ? "checked" : "";
 
722
  } else if (col === "Tên Khách hàng" || col === "Tên Cơ sở sử dụng") {
723
  tbodyHtml += `<td><textarea class="input-area">${cell}</textarea></td>`;
724
  } else if (col === "Người tiếp nhận") {
725
+ tbodyHtml += `<td>
726
+ <select class="input-cell">
727
+ <option ${cell === "Lê Danh Huy" ? "selected" : ""}>Lê Danh Huy</option>
728
+ <option ${cell === "Trần Văn Dương" ? "selected" : ""}>Trần Văn Dương</option>
729
+ <option ${cell === "Nguyễn Mạnh Cường" ? "selected" : ""}>Nguyễn Mạnh Cường</option>
730
+ <option ${cell === "Nguyễn ngọc vinh" ? "selected" : ""}>Nguyễn ngọc vinh</option>
731
+ </select>
732
+ </td>`;
733
  } else if (col === "Phòng yêu cầu") {
734
+ tbodyHtml += `<td>
735
+ <select class="input-cell">
736
+ <option ${cell === "ĐL1" ? "selected" : ""}>ĐL1</option>
737
+ <option ${cell === "ĐL2" ? "selected" : ""}>ĐL2</option>
738
+ <option ${cell === "ĐL3" ? "selected" : ""}>ĐL3</option>
739
+ <option ${cell === "ĐL4" ? "selected" : ""}>ĐL4</option>
740
+ <option ${cell === "ĐL5" ? "selected" : ""}>ĐL5</option>
741
+ <option ${cell === "QA" ? "selected" : ""}>QA</option>
742
+ </select>
743
+ </td>`;
744
  } else {
745
  tbodyHtml += `<td><input class="input-cell" type="text" value="${cell}" /></td>`;
746
  }
747
  }
748
 
749
  tbodyHtml += `</tr>`;
750
+ }
751
 
752
  $("#bangHSKH tbody").html(tbodyHtml);
753