-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
60 lines (55 loc) · 1.89 KB
/
Copy pathapp.js
File metadata and controls
60 lines (55 loc) · 1.89 KB
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
const STORAGE_KEY = "kamlin_bookings_v2";
function getBookings(){
try { return JSON.parse(localStorage.getItem(STORAGE_KEY) || "[]"); }
catch { return []; }
}
function saveBookings(items){ localStorage.setItem(STORAGE_KEY, JSON.stringify(items)); }
function createBooking(data){
const items = getBookings();
const ref = "KML-" + Date.now().toString().slice(-8);
const item = {
id: ref,
createdAt: new Date().toISOString(),
name: data.name || "",
phone: data.phone || "",
service: data.service || "",
area: data.area || "",
notes: data.notes || "",
status: "جديد",
assignedTo: "",
followUp: "",
quote: "",
warranty: "",
source: "الموقع"
};
items.unshift(item);
saveBookings(items);
return item;
}
function validPhone(phone){ return String(phone).replace(/\D/g,"").length >= 10; }
function bindForm(id,statusId){
const form=document.getElementById(id), status=document.getElementById(statusId);
if(!form) return;
form.addEventListener("submit", e=>{
e.preventDefault();
const data=Object.fromEntries(new FormData(form).entries());
if(!validPhone(data.phone)){
status.className="form-status error";
status.textContent="يرجى إدخال رقم هاتف صحيح.";
return;
}
const item=createBooking(data);
status.className="form-status success";
status.textContent=`تم استلام الطلب بنجاح. رقم الطلب: ${item.id}`;
form.reset();
});
}
bindForm("quickBooking","quickStatus");
bindForm("bookingForm","bookingStatus");
function bookService(service){
const select=document.getElementById("serviceSelect");
if(select) select.value=service;
document.getElementById("booking")?.scrollIntoView({behavior:"smooth"});
}
function toggleMenu(){ document.getElementById("mainNav")?.classList.toggle("open"); }
document.getElementById("year").textContent=new Date().getFullYear();