import{r as y,h,w as S,a as j,c as i,e as s,i as n,m as g,F as b,f as k,j as o,S as d,v as C,k as c,t as x,l as _,q as F,u as V,g as v,p as M,o as u}from"./app-OFnD_EfZ.js";import{u as r}from"./swal-C1wxMWhd.js";import{_ as B}from"./CustomTable-wjyxWH_G.js";import{r as I,a as N}from"./DocumentCheckIcon-CCVtgCcr.js";import"./sweetalert2.esm.all-BQIkj5Wb.js";/* empty css                                                    */const q={class:"sm:p-4 md:p-6 font-semibold mt-4 sm:mt-0"},R={class:"flex flex-col border-2 border-slate-300 shadow-md rounded px-3 py-2"},T={class:"flex px-1 py-2"},z=["value"],E={class:"flex items-center px-1 py-2"},L={class:"flex items-center mr-2"},A={class:"flex items-center mr-2"},G={class:"flex items-center mr-2"},H={class:"flex items-center mr-2"},J={class:"flex items-center"},K={class:"flex px-1 py-2"},O=["value"],P={class:"flex px-1 py-2"},Q={class:"overflow-x-auto border border-gray-200 rounded shadow mt-4 p-3"},W={class:"flex text-xl mx-2 mb-2"},X={class:"flex flex-col sm:flex-row mb-6 font-semibold mt-2 sm:justify-center gap-4"},Y={class:"flex px-2 py-2 bg-red-500 text-white rounded sm:w-auto mb-2 justify-center"},oe={__name:"Create",setup(Z){const D=M(),p=y([]),l=h({bank_id:"",checker_id:"",cycle:"daily",startdate:""});S(()=>l.bank_id,async a=>{var m;if(!a){p.value=[];return}const e=f.value.find(t=>t.id===a);e&&(l.name=(m=e.equipment)==null?void 0:m.name);try{const t=await v.get(`/api/dispatchSet/getDispatch?dispatchId=${a}`);p.value=t.data.data}catch(t){console.error("載入檢核表單基本資料失敗",t)}});const w=y([]),f=y([]),U=async()=>{const a=await v.get("/api/dispatchSet/getForm");w.value=a.data.userData,f.value=a.data.bankData},$=async()=>{if(!l.bank_id){await r.error("請選擇「檢核表單」","資料未填寫完整");return}if(!l.cycle){await r.error("請確認已勾選「週期」","資料未填寫完整");return}if(!l.checker_id){await r.error("請確認已勾選「巡檢人員」","資料未填寫完整");return}if(!l.startdate){await r.error("請選擇「起始日期」","資料未填寫完整");return}if(p.value.length===0){await r.error("該檢核表單尚未建立檢查項目，新增失敗");return}try{await v.post("/api/dispatch",l),await r.success("派工單新增成功"),D.push("/dispatch/Index")}catch{await r.error("請稍後再試，或聯絡管理員","儲存失敗")}};return j(()=>U()),(a,e)=>{const m=F("router-link");return u(),i(b,null,[e[21]||(e[21]=s("h2",{class:"text-xl sm:text-3xl px-3 pb-2 font-semibold text-black dark:text-white border-b-4 border-zinc-200"},"派工設定 - 派工排程",-1)),s("div",q,[s("div",R,[s("div",T,[e[9]||(e[9]=s("span",{class:"text-left"},"檢核表單：",-1)),n(s("select",{class:"border rounded flex-shrink min-w-0","onUpdate:modelValue":e[0]||(e[0]=t=>l.bank_id=t)},[e[8]||(e[8]=s("option",{disabled:"",value:""},"請選擇檢核表單",-1)),(u(!0),i(b,null,k(f.value,t=>(u(),i("option",{key:t.id,value:t.id},x(t==null?void 0:t.name),9,z))),128))],512),[[g,l.bank_id]])]),s("div",E,[e[15]||(e[15]=s("span",{class:"mr-2"},"週期：",-1)),s("label",L,[n(s("input",{type:"radio",value:"daily","onUpdate:modelValue":e[1]||(e[1]=t=>l.cycle=t),name:"cycle"},null,512),[[d,l.cycle]]),e[10]||(e[10]=o("日 ",-1))]),s("label",A,[n(s("input",{type:"radio",value:"week","onUpdate:modelValue":e[2]||(e[2]=t=>l.cycle=t),name:"cycle"},null,512),[[d,l.cycle]]),e[11]||(e[11]=o("週 ",-1))]),s("label",G,[n(s("input",{type:"radio",value:"month","onUpdate:modelValue":e[3]||(e[3]=t=>l.cycle=t),name:"cycle"},null,512),[[d,l.cycle]]),e[12]||(e[12]=o("月 ",-1))]),s("label",H,[n(s("input",{type:"radio",value:"season","onUpdate:modelValue":e[4]||(e[4]=t=>l.cycle=t),name:"cycle"},null,512),[[d,l.cycle]]),e[13]||(e[13]=o("季 ",-1))]),s("label",J,[n(s("input",{type:"radio",value:"year","onUpdate:modelValue":e[5]||(e[5]=t=>l.cycle=t),name:"cycle"},null,512),[[d,l.cycle]]),e[14]||(e[14]=o("年 ",-1))])]),s("div",K,[e[17]||(e[17]=s("span",{class:"text-left"},"巡檢人員：",-1)),n(s("select",{class:"border rounded flex-shrink min-w-0","onUpdate:modelValue":e[6]||(e[6]=t=>l.checker_id=t)},[e[16]||(e[16]=s("option",{disabled:"",value:""},"請選擇巡檢人員",-1)),(u(!0),i(b,null,k(w.value,t=>(u(),i("option",{key:t.id,value:t.id},x(t.name),9,O))),128))],512),[[g,l.checker_id]])]),s("div",P,[e[18]||(e[18]=s("span",{class:"text-left"},"起始日期：",-1)),n(s("input",{type:"date","onUpdate:modelValue":e[7]||(e[7]=t=>l.startdate=t)},null,512),[[C,l.startdate]])])]),s("div",Q,[s("div",W,x(l.name||""),1),c(B,{items:p.value,columns:[{label:"檢核項目",field:"item"},{label:"管理值",field:"rangeDisplay"}],rows:7,selectable:!1},{"column-rangeDisplay":_(({data:t})=>[o(x(t.range&&t.range2?`${t.range} ~ ${t.range2}`:t.range?`> ${t.range}`:t.range2?`< ${t.range2}`:""),1)]),_:1},8,["items"])]),s("div",X,[s("button",Y,[c(m,{to:"/Dispatch/Index",class:"flex w-full justify-center"},{default:_(()=>[c(V(N),{class:"w-6 h-6"}),e[19]||(e[19]=o(" 取消 ",-1))]),_:1,__:[19]})]),s("button",{class:"flex px-2 py-2 bg-green-500 text-white rounded sm:w-auto mb-2 justify-center",onClick:$},[c(V(I),{class:"w-6 h-6"}),e[20]||(e[20]=o("儲存 ",-1))])])])],64)}}};export{oe as default};
