import{c as k,m as q,d as E}from"./jobOrder-CGbsc7bp.js";import{_ as M}from"./OnlyOffice.vue_vue_type_script_setup_true_lang-BH1_y9Dy.js";import{s as P}from"./event-CLiVQHeO.js";import{d as $,V as z,r as n,d9 as D,aE as F,l as s,c as v,o as y,W as A,w as o,D as x,j as b,B as H,p as I,A as h,H as L,ac as W,d8 as Z,cZ as G}from"./index-9PRMimni.js";const ee=$({__name:"OnlineDocs",props:{edit:{type:Boolean}},emits:["success","switchFile"],setup(J,{expose:N,emit:B}){const l=B,{t:c}=z(),g=G(),r=n(),a=n(),f=n(),m=n(!0),R=n(),w=n(!1);function T(){m.value=!1}async function S(){if(!a.value)return;const e=await k(a.value.fileId);await r.value?.handleInitOffice(e.fileCode,e.id)}function V(e,t,d){try{if(!e)return;a.value=e,f.value=d,W(async()=>{if(!a.value)return;if(!Z(a.value.fileId)){const p=t==="copy"?e.lastFormUrl:e.formUrl,_=t==="copy"?e.lastFileName:e.fileName,u=await P(p,_);a.value.fileCode=u.name;const O={shipId:f.value.shipId,templateId:a.value.templateId,fileCode:u.name},C=await q(O);a.value.fileId=C.id,await E({smsCode:a.value.formCode,jobOrderId:f.value.id,fileId:C.id.toString()}),await r.value?.handleInitOffice(a.value.fileCode,a.value.fileId);return}const i=await k(a.value.fileId);await r.value?.handleInitOffice(i.fileCode,i.id)})}catch{m.value=!1}}function j(){l("switchFile",!1),l("success")}async function U(){try{if(!a.value)return;g.success(c("common.optionsSuccessText")),w.value=!0,l("switchFile",!1),l("success")}catch(e){console.log(e),g.error(c("common.optionsErrorText"))}}return N({setFormUrl:V}),(e,t)=>{const d=H,i=L,p=A,_=D("debounce"),u=D("loading");return F((y(),v(p,{segmented:{content:!0},size:"small",class:"proCard","content-class":"p-0"},{header:o(()=>t[1]||(t[1]=[I(h(" "))])),"header-extra":o(()=>[b(i,null,{default:o(()=>[e.edit?F((y(),v(d,{key:0,loading:s(R),type:"primary"},{default:o(()=>[I(h(s(c)("common.saveText")),1)]),_:1},8,["loading"])),[[_,U,"1000"]]):x("",!0),b(d,{onClick:t[0]||(t[0]=O=>j())},{default:o(()=>[I(h(s(c)("common.backText")),1)]),_:1})]),_:1})]),default:o(()=>[s(w)?x("",!0):(y(),v(s(M),{key:0,ref_key:"onlyOfficeRef",ref:r,mode:e.edit?"edit":"view",onOnInfo:T,onOnRequestRefreshFile:S},null,8,["mode"]))]),_:1})),[[u,s(m)]])}}});export{ee as _};
