import{r as d,h as v,a as C,c as a,d as m,e as t,j as I,u as L,i as w,v as V,m as D,F as E,f as M,t as g,g as y,o as l}from"./app-OFnD_EfZ.js";import{u as N}from"./swal-C1wxMWhd.js";import{_ as q}from"./_plugin-vue_export-helper-DlAUqK2U.js";import"./sweetalert2.esm.all-BQIkj5Wb.js";const T={key:0,class:"fixed inset-0 z-50 bg-black/40 backdrop-blur-sm flex items-center justify-center"},U={class:"bg-white rounded-xl shadow-xl w-full max-w-xl animate-fade-in"},z={class:"space-y-4 p-6"},A={class:"flex flex-col font-bold text-xl"},O={class:""},R=["href"],$={class:"flex flex-row whitespace-nowrap items-center gap-2 mx-12"},G={class:"flex flex-row whitespace-nowrap items-center gap-2 mx-12"},H=["value"],J={class:"px-4 py-2 mx-6"},K={class:"flex items-center space-x-4"},P={key:0,class:"font-bold text-lg"},Q={key:1,class:"font-bold text-lg border border-black rounded py-1 pl-2 pr-8"},W={class:"flex justify-center gap-4 mt-6 font-semibold"},X={__name:"ImportBank",props:{show:Boolean,bank:Object},emits:["update:show","saved"],setup(k,{emit:_}){const h="/sets/sm/si",n=_,f=d([]),u=v({id:"",name:""}),c=v({id:"",name:""}),F=async()=>{const o=await y.get("/api/equipments");f.value=o.data.data},x=d(null),p=d(null),r=d("");function B(){x.value.click()}function S(o){const e=o.target.files[0];e&&(p.value=e,r.value=e.name)}async function j(){var e,s;if(!p.value)return;const o=new FormData;o.append("BankFile",p.value),o.append("equipment_id",u.id),o.append("bank_name",c.name);try{const i=await y.post("/api/bankList/import",o);await N.success("匯入成功"),n("update:show",!1),n("saved")}catch(i){let b="匯入失敗";console.log(i),(s=(e=i.response)==null?void 0:e.data)!=null&&s.errors&&(b=`匯入失敗：
`+i.response.data.errors.join(`
`)),alert(b)}}return C(()=>{F()}),(o,e)=>k.show?(l(),a("div",T,[t("div",U,[e[9]||(e[9]=t("div",{class:"bg-slate-600 rounded-t-xl text-white"},[t("div",{class:"text-2xl font-semibold py-3 text-center"}," 匯入 ")],-1)),t("div",z,[t("div",A,[t("div",O,[e[3]||(e[3]=I("範例檔：",-1)),t("a",{class:"text-blue-600",href:`${L(h)}/files/banksExample.xlsx`,download:""},"匯入表單範例.xlsx",8,R)]),e[4]||(e[4]=t("div",{class:"py-2 border-b-2 border-blue-900"}," 說明：輸入表單名稱、選擇設備及表單後，只有且當每一行資料無誤時，才會進行建立作業 ",-1))]),t("div",$,[e[5]||(e[5]=t("label",{class:"block text-base font-bold text-gray-700 mb-1"},"表單名稱",-1)),w(t("input",{"onUpdate:modelValue":e[0]||(e[0]=s=>c.name=s),class:"text-sm w-full border border-gray-300 rounded-md px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-400"},null,512),[[V,c.name]])]),t("div",G,[e[7]||(e[7]=t("label",{class:"block text-base font-bold text-gray-700 mb-1"},"選擇設備",-1)),w(t("select",{"onUpdate:modelValue":e[1]||(e[1]=s=>u.id=s),class:"text-sm w-full border border-gray-300 rounded-md px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-400"},[e[6]||(e[6]=t("option",{disabled:"",value:""},"請選擇",-1)),(l(!0),a(E,null,M(f.value,s=>(l(),a("option",{key:s.id,value:s.id},g(s.name),9,H))),128))],512),[[D,u.id]])]),t("div",J,[t("input",{type:"file",ref_key:"fileInput",ref:x,onChange:S,accept:".xls,.csv,.xlsx",class:"hidden"},null,544),t("div",K,[r.value?m("",!0):(l(),a("span",P,"未選擇任何檔案")),r.value?(l(),a("span",Q,g(r.value),1)):m("",!0),t("button",{onClick:B,class:"border rounded font-serif text-sm bg-blue-900 py-1 px-4 text-white"}," 選擇檔案 ")])]),e[8]||(e[8]=t("hr",{class:"shadow border"},null,-1)),t("div",W,[t("button",{onClick:e[2]||(e[2]=()=>{n("update:show",!1),n("saved")}),class:"w-15 h-10 px-4 py-2 text-base bg-red-600 hover:bg-red-500 text-white rounded"}," 取消 "),t("button",{label:"上傳",onClick:j,class:"w-15 h-10 px-4 py-2 text-base bg-emerald-500 hover:bg-emerald-400 text-white rounded"}," 上傳 ")])])])])):m("",!0)}},oe=q(X,[["__scopeId","data-v-b35c0ba7"]]);export{oe as default};
