import{V as b,d as N,r as A,ay as T,aw as j,c as L,o as q,w as p,j as v,l as w,aH as C,p as I,A as U,X as k,cZ as E}from"./index-9PRMimni.js";import{B as M}from"./BasicForm-dL_oCSPM.js";import{d as z}from"./unPlannedJob-BvCurP2n.js";import{u as G}from"./jobOrder-CGbsc7bp.js";import{i as y}from"./isEmpty-BUg1OsQj.js";import{u as H}from"./useForm-CKmgcynv.js";import{h as J}from"./has-CjqcrIOV.js";const{t:F}=b();function W(){return{formSchemas:[{field:"attachment",label:F("unPlannedJob.basicDetailTab.attachment"),giProps:{span:1},slot:"attachmentSlot",showLabel:!1,rules:[{validator(d,r){return y(r)?Promise.reject(new Error(F("common.RequireTips"))):Promise.resolve(!0)}}]}]}}const ee=N({__name:"index",props:{sourceData:{},isView:{type:Boolean}},emits:["updateForms"],setup(f,{expose:d,emit:r}){const h=f,R=r,{t:_}=b(),S=E(),{formSchemas:V}=W(),[B,c]=H({gridProps:{cols:1},layout:"horizontal",schemas:V,showActionButtonGroup:!1}),{setFieldsValue:l}=c,t=A([]);T(()=>h.sourceData?.attachment,e=>{y(e)||g()},{immediate:!1});async function D({index:e,model:s,field:a}){if(J(t.value[e],"id")){const o=t.value[e].id;await z(o),R("updateForms")}else t.value.splice(e,1),l({attachment:t.value})}async function P({file:e,onFinish:s,onError:a}){try{const o=new FormData;o.append("file",e.file);const n=await G(o),i={fileId:t.value.length+1,fileCode:n.name,fileName:n.originalFileName,url:n.url,name:n.originalFileName,status:"finished"};t.value.push(i),S.success(_("common.uploadSuccessText")),l({attachment:t.value}),s({file:e})}catch{a()}}function x(){return new Promise((e,s)=>{c.validate().then(()=>{e(!0)}).catch(()=>{s("4")})})}function g(){t.value=[];const e=h.sourceData?.attachment,s=e||[];t.value=s.map(a=>({...a,fileId:a.id,url:a.fileUrl,name:a.fileName,status:"finished"})),l({attachment:t.value})}return j(()=>{g()}),d({validate:x,getFieldsValue:c.getFieldsValue}),(e,s)=>{const a=C,o=M,n=k;return q(),L(n,null,{default:p(()=>[v(o,{onRegister:w(B)},{attachmentSlot:p(({model:i,field:m})=>[v(a,{"list-type":"image-card","file-list":i[m],"onUpdate:fileList":u=>i[m]=u,accept:".jpg,.png,.jpeg",disabled:e.isView,max:5,"show-preview-button":!0,"custom-request":P,onRemove:({index:u})=>D({index:u,field:m,model:i}),"show-remove-button":!0},{default:p(()=>[I(U(w(_)("common.uploadText")),1)]),_:2},1032,["file-list","onUpdate:fileList","disabled","onRemove"])]),_:1},8,["onRegister"])]),_:1})}}});export{ee as _};
