/* Add Job — sectioned mobile-first form */
function ItemRow({ item, onChange, onRemove, index }){
const isAir = item.p==='air';
return (
รายการที่ {index+1}
{onRemove && }
onChange({...item,p:v})} getIcon={o=>o.icon} />
onChange({...item,model:e.target.value})} />
{isAir ? (
) :
— ไม่ระบุ BTU —
}
จำนวน
{item.qty||1}
);
}
function FormCard({ step, icon, title, children }){
return (
{step}
{title}
{children}
);
}
function AddJobScreen(){
const { device, addJob, navigate, jobs, role } = useCK();
const isMobile = device==='mobile';
const [f,setF] = React.useState({
customer:'', phone:'', addr:'', district:'', routeNote:'',
jobType:'install', items:[{p:'air',brand:'',model:'',btu:'',qty:1}],
date:CK.TODAY, slot:'คิวแรก (09.00)', urgency:'normal', note:'',
branch:'b1',
});
const set = (k,v)=>setF(s=>({...s,[k]:v}));
const ds = computeDayStatus(jobs, f.date);
const blocked = ds.status==='full' || ds.status==='closed';
const valid = f.customer && f.phone && f.district && f.items.length>0;
function save(){
const job = {
id: CK.nid(), code: CK.code(Math.floor(Math.random()*9000)+100),
date:f.date, branch:f.branch, district:f.district, customer:f.customer, phone:f.phone,
addr:f.addr||`ต.${f.district} อ.${f.district} จ.ศรีสะเกษ`, routeNote:f.routeNote,
jobType:f.jobType, items:f.items, slot:f.slot, urgency:f.urgency, note:f.note,
status:'pending', team:null, createdBy: role==='sales'?'มานี ใจดี':'สุดา (HQ)',
createdAt: new Date().toLocaleString('th-TH'), prepared:false,
log:[{by:'ผู้บันทึก', from:'—', to:'pending', note:'สร้างงานจากสาขา', at: new Date().toLocaleString('th-TH',{day:'2-digit',month:'short',hour:'2-digit',minute:'2-digit'})}],
};
addJob(job);
navigate('queue',{date:f.date});
}
return (
{isMobile ?
เพิ่มงานใหม่
:
}
{isMobile &&
กรอกข้อมูลให้ครบเพื่อให้สำนักงานใหญ่จัดคิวได้ทันที
}
set('customer',e.target.value)} />
set('phone',e.target.value)} />
set('routeNote',e.target.value)} />
set('jobType',v)} getIcon={o=>o.icon} />
{f.items.map((it,i)=>(
set('items', f.items.map((x,j)=>j===i?ni:x))}
onRemove={f.items.length>1?()=>set('items', f.items.filter((_,j)=>j!==i)):null} />
))}
set('date',d)} compact />
{blocked && (
{ds.status==='closed' ? 'วันนี้งดรับงาน' : `วันนี้คิวเต็ม (${ds.used}/${ds.max} unit)`} — ไม่ควรรับเพิ่ม ต้องให้สำนักงานใหญ่/ผู้บริหารอนุมัติก่อน
)}
({id:t,th:t}))} value={f.slot} onChange={v=>set('slot',v)} />
set('urgency',v)} />
{/* sticky save bar */}
{valid ? พร้อมบันทึก
: กรอกชื่อ เบอร์ และอำเภอ}
ร่าง
บันทึกงาน
);
}
Object.assign(window, { AddJobScreen });