import{_ as O}from"./basicModal.vue_vue_type_script_setup_true_lang-CsJydKhW.js";import"./basicModal.vue_vue_type_style_index_0_lang-8QZP7ApW.js";import{B as G}from"./BasicForm-dL_oCSPM.js";import{V as R,d as H,r as p,c as L,o as f,l as o,w as i,j as S,h as K,aH as U,B as Z,p as J,A as F,ac as Q,cZ as W}from"./index-9PRMimni.js";import{K as X,L as Y}from"./vesselEquipmentDetails-CJeqdW1Z.js";import{u as j}from"./account-C850CBTF.js";import{u as ee}from"./useModal-CO65vga3.js";import{u as te}from"./useForm-CKmgcynv.js";const{t:m}=R();function oe(){return{formSchemas:[{field:"fileCode",slot:"fileCode",label:m("equipmentLibrary.equipmentMainLibrary.serviceLetters.uploadFile"),rules:[{key:"fileCode",required:!0,message:`${m("equipmentLibrary.equipmentMainLibrary.serviceLetters.uploadFile")} ${m("common.required")}`,trigger:["change"]}]},{field:"remark",component:"NInput",label:m("equipmentLibrary.equipmentMainLibrary.serviceLetters.remark"),componentProps:()=>({type:"textarea"})}]}}const se=["href"],de=H({__name:"FormModal",props:{selectedTreeItem:{}},emits:["success"],setup(_,{expose:q,emit:x}){const l=_,M=x,{t:u}=R(),h=W(),n=p(""),a=p(),r=p(),[T,{openModal:B,closeModal:C,setSubLoading:d,setProps:I}]=ee({title:"",width:800}),{formSchemas:N}=oe(),[A,{submit:P,validate:g,setFieldsValue:V}]=te({gridProps:{cols:1},layout:"horizontal",labelPlacement:"left",schemas:N,showActionButtonGroup:!1});async function D(t,e,s){n.value=s,a.value=e,I({title:t}),B(),await Q(),s!=="add"&&V(a.value||{})}async function $(t,e,s){const c=new FormData;c.append("file",t.file?.file);try{r.value=await j(c),e[s]=r.value?.name,t.onFinish(),g([s])}catch{t.onError(),v(e,s)}}function v(t,e){r.value={},t[e]="",g([e])}async function z(){const t=await P();if(!t){d(!1);return}try{if(n.value==="add"){const e={...t,letterName:o(r)?.originalFileName,fileSize:o(r)?.size,productCode:l.selectedTreeItem?.code,model:l.selectedTreeItem?.model,shipId:l.selectedTreeItem?.shipId};await X(e),h.success(u("common.optionsAddSuccessText"))}else{const e={...a.value||{},remark:t.remark};await Y(e),h.success(u("common.optionsEditSuccessText"))}C(),d(!1),M("success")}catch{d(!1)}}return q({handleOpenModal:D}),(t,e)=>{const s=Z,c=U,y=G,E=O;return f(),L(E,{ref:"modalRef",showAction:o(n)!=="view",onRegister:o(T),onOnOk:z},{default:i(()=>[S(y,{ref:"formRef",onRegister:o(A)},{fileCode:i(({model:k,field:b})=>[o(n)==="add"?(f(),L(c,{key:0,max:1,"custom-request":w=>$(w,k,b),onRemove:w=>v(k,b)},{default:i(()=>[S(s,null,{default:i(()=>[J(F(o(u)("common.uploadText")),1)]),_:1})]),_:2},1032,["custom-request","onRemove"])):(f(),K("a",{key:1,href:o(a)?.fileUrl,target:"_blank"},F(o(a)?.letterName),9,se))]),_:1},8,["onRegister"])]),_:1},8,["showAction","onRegister"])}}});export{de as _};
