File size: 5,341 Bytes
7de75fb 3735c3c 7de75fb 53759c5 7de75fb 53759c5 7de75fb 53759c5 7de75fb 53759c5 62063aa 5b8ef5b 62063aa 5b8ef5b 62063aa 5b8ef5b 62063aa d773b94 3735c3c 5b8ef5b 3735c3c 18e78bc 53759c5 7de75fb 62063aa 3735c3c 62063aa 53759c5 7de75fb 53759c5 7de75fb 53759c5 7de75fb 53759c5 7de75fb 53759c5 5b8ef5b 7de75fb 53759c5 62063aa 5b8ef5b 62063aa 5b8ef5b 62063aa 53759c5 7de75fb 5b8ef5b 53759c5 7de75fb 18e78bc 3735c3c 62063aa 18e78bc 3735c3c 53759c5 d773b94 53759c5 5b8ef5b 53759c5 7de75fb 18e78bc 3735c3c 7de75fb 53759c5 e17cd01 c4e74a8 e17cd01 62063aa c4e74a8 7de75fb c4e74a8 7de75fb 3735c3c 18e78bc 3735c3c 7de75fb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | const input = document.getElementById("searchInput");
const clearBtn = document.getElementById("clearBtn");
const results = document.getElementById("results");
const counter = document.getElementById("counter");
const resultsHeader = document.querySelector(".resultsHeader");
const COLUMNS = [
{ key: "إسم المنشأة", label: "إسم المنشأة" },
{ key: "السجل التجاري", label: "السجل التجاري" },
{ key: "حالة العينة", label: "حالة العينة" },
{ key: "اسم المسح", label: "اسم المسح" },
];
function normalize(value){
return String(value ?? "")
.toLowerCase()
.trim()
.replace(/[إأآا]/g,"ا")
.replace(/ى/g,"ي")
.replace(/ة/g,"ه")
.replace(/[^\u0600-\u06FFa-zA-Z0-9 ]/g,"")
.replace(/\s+/g," ");
}
function esc(value){
return String(value ?? "")
.replace(/&/g,"&")
.replace(/</g,"<")
.replace(/>/g,">")
.replace(/"/g,""")
.replace(/'/g,"'");
}
function getStatusClass(status){
const s = normalize(status);
if(s.includes("اعطت كامل البيانات")){
return "status success";
}
if(s.includes("اعطت بعض البيانات") || s.includes("استيفاء ذاتي")){
return "status warning";
}
if(
s.includes("رفض") ||
s.includes("مغلق") ||
s.includes("لم يعثر") ||
s.includes("انتقلت") ||
s.includes("تحولت") ||
s.includes("خارج نطاق") ||
s.includes("لم تمارس") ||
s.includes("غير متاح") ||
s.includes("يطالب") ||
s.includes("اخري")
){
return "status danger";
}
return "status";
}
function getScore(row, q){
const name = normalize(row["إسم المنشأة"]);
const cr = normalize(row["السجل التجاري"]);
if(name === q || cr === q) return 1;
if(name.startsWith(q) || cr.startsWith(q)) return 2;
if(name.includes(q) || cr.includes(q)) return 3;
return 99;
}
function showResultsArea(){
results.classList.add("active");
if(resultsHeader) resultsHeader.classList.add("active");
}
function hideResultsArea(){
results.classList.remove("active");
if(resultsHeader) resultsHeader.classList.remove("active");
}
function render(rows){
showResultsArea();
counter.textContent = rows.length ? `عدد النتائج: ${rows.length}` : "";
if(!rows.length){
results.innerHTML = `
<div class="empty">
لم يتم العثور على نتيجة مطابقة.
</div>
`;
return;
}
const head = `
<thead>
<tr>
${COLUMNS.map(col => `<th>${col.label}</th>`).join("")}
</tr>
</thead>
`;
const body = `
<tbody>
${rows.map(row => `
<tr>
<td>${esc(row["إسم المنشأة"] || "—")}</td>
<td>${esc(row["السجل التجاري"] || "—")}</td>
<td>
<span class="${getStatusClass(row["حالة العينة"])}">
${esc(row["حالة العينة"] || "—")}
</span>
</td>
<td>${esc(row["اسم المسح"] || "—")}</td>
</tr>
`).join("")}
</tbody>
`;
const cards = `
<div class="cards">
${rows.map(row => `
<article class="resultCard">
<div class="cardTop">
<h3>${esc(row["إسم المنشأة"] || "—")}</h3>
<span class="${getStatusClass(row["حالة العينة"])}">
${esc(row["حالة العينة"] || "—")}
</span>
</div>
<div class="cardInfo">
<div>
<span>السجل التجاري</span>
<strong>${esc(row["السجل التجاري"] || "—")}</strong>
</div>
<div>
<span>اسم المسح</span>
<strong>${esc(row["اسم المسح"] || "—")}</strong>
</div>
</div>
</article>
`).join("")}
</div>
`;
results.innerHTML = `
<div class="tableWrap">
<table>${head}${body}</table>
</div>
${cards}
`;
}
function search(){
const q = normalize(input.value);
if(!q){
counter.textContent = "";
hideResultsArea();
return;
}
if(q.length < 2){
counter.textContent = "";
showResultsArea();
results.innerHTML = `<div class="empty">اكتب حرفين على الأقل.</div>`;
return;
}
const filtered = DATA
.filter(row => {
const name = normalize(row["إسم المنشأة"]);
const cr = normalize(row["السجل التجاري"]);
const status = normalize(row["حالة العينة"]);
if(status.includes("جديد")) return false;
return name.includes(q) || cr.includes(q);
})
.sort((a,b) => getScore(a,q) - getScore(b,q));
render(filtered);
}
function clearSearch(){
input.value = "";
counter.textContent = "";
results.innerHTML = "";
hideResultsArea();
input.focus();
}
let debounceTimer;
input.addEventListener("input", () => {
clearTimeout(debounceTimer);
debounceTimer = setTimeout(search, 250);
});
clearBtn.addEventListener("click", clearSearch);
if(!Array.isArray(DATA)){
showResultsArea();
counter.textContent = "";
results.innerHTML = `<div class="empty">ملف البيانات غير صحيح.</div>`;
} |