import{_ as L}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 U}from"./BasicForm-dL_oCSPM.js";import{V as _,bk as V,d as O,c as D,o as K,l as d,w as i,j as f,aH as z,B as G,p as H,A as W,cZ as Z}from"./index-9PRMimni.js";import{u as J}from"./account-C850CBTF.js";import{i as Q}from"./smsFormsTemplate-Dsea_L5v.js";import{r as X,w as Y}from"./xlsx-GLiMJrM3.js";import{u as j}from"./useModal-CO65vga3.js";import{u as ee}from"./useForm-CKmgcynv.js";const{t:e}=_(),y=V();function se(){const p=[{field:"code",component:"NInput",label:e("mdm.smsFormsTemplate.smsFileCode")},{field:"name",component:"NInput",label:e("mdm.smsFormsTemplate.smsFileName")},{field:"type",component:"BasicSelect",label:e("mdm.smsFormsTemplate.fileType"),componentProps:()=>({cacheKey:"sms_template_type",block:!0,cache:!1,labelField:y.getLocale==="en"?"labelEn":"label"})}];return{modalSchemas:[{field:"code",component:"NInput",label:e("mdm.smsFormsTemplate.smsFileCode"),componentProps:{},rules:[{required:!0,message:`${e("common.inputText")} ${e("mdm.smsFormsTemplate.smsFileCode")}`,trigger:["blur"]}]},{field:"nameCn",component:"NInput",label:`${e("mdm.smsFormsTemplate.smsFileName")}(Chinese)`,componentProps:{},rules:[{required:!0,message:`${e("common.inputText")} ${e("mdm.smsFormsTemplate.smsFileName")}(Chinese)`,trigger:["blur"]}]},{field:"nameEn",component:"NInput",label:`${e("mdm.smsFormsTemplate.smsFileName")}(English)`,componentProps:{},rules:[{required:!0,message:`${e("common.inputText")} ${e("mdm.smsFormsTemplate.smsFileName")}(English)`,trigger:["blur"]}]},{field:"type",component:"BasicSelect",label:e("mdm.smsFormsTemplate.fileType"),componentProps:()=>({cacheKey:"sms_template_type",block:!0,cache:!1,labelField:y.getLocale==="en"?"labelEn":"label"}),rules:[{required:!0,message:`${e("common.chooseText")} ${e("mdm.smsFormsTemplate.fileType")}`,trigger:["change"]}]},{field:"version",component:"NInput",label:e("mdm.smsFormsTemplate.smsFileVersion"),componentProps:{}},{field:"fileCode",label:e("mdm.smsFormsTemplate.fileUrl"),slot:"fileSlot",giProps:{span:3},rules:[{key:"fileCode",required:!0,message:`${e("common.chooseText")} ${e("mdm.smsFormsTemplate.fileUrl")}`,trigger:["change"]}]}],searchSchemas:p}}const pe=O({__name:"AddTemplateModal",props:{selectedTreeItem:{}},emits:["success"],setup(p,{expose:h,emit:b}){const w=p,S=b,{t:g}=_(),x=Z(),[N,{openModal:R,closeModal:$,setSubLoading:u,setProps:B}]=j({title:"",width:800}),{modalSchemas:C}=se(),[k,{submit:E,validate:F}]=ee({gridProps:{cols:3},layout:"horizontal",schemas:C,showActionButtonGroup:!1});async function P(s){B({title:s}),R()}function I({file:s}){const o=s.name?.split(".")?.pop()?.toLowerCase();return o!=="xls"&&o!=="xlsx"?(x.error("The type of uploaded file is restricted to .xls,.xlsx"),!1):!0}function q(s){return new Promise((o,m)=>{if(!s){m(new Error("No File"));return}const t=new FileReader;t.onload=async r=>{try{const a=new Uint8Array(r?.target?.result),n=X(a,{type:"array"}),l=Y(n,{bookType:"xlsx",type:"array"}),c=s.name?.replace(/\.xls$/i,".xlsx")||"file.xlsx",A=new File([l],c,{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});o(A)}catch(a){m(a)}},t.onerror=r=>m(r),t.readAsArrayBuffer(s)})}async function M(s,o,m){let t=s.file?.file;t.name?.split(".")?.pop()?.toLowerCase()==="xls"&&(t=await q(t));const a=new FormData;a.append("file",t);try{const n=await J(a);o[m]=n.name,F([m]),s.onFinish()}catch{s.onError(),T(o,m)}}function T(s,o){s[o]="",F([o])}async function v(){const s=await E();if(!s){u(!1);return}try{const o={...s,category:w.selectedTreeItem.key};await Q(o),u(!1),$(),x.success(g("common.optionsSuccessText")),S("success")}catch{u(!1)}}return h({handleOpenModal:P}),(s,o)=>{const m=G,t=z,r=U,a=L;return K(),D(a,{ref:"modalRef",onRegister:d(N),onOnOk:v},{default:i(()=>[f(r,{ref:"formRef",onRegister:d(k)},{fileSlot:i(({model:n,field:l})=>[f(t,{multiple:"",accept:".xlsx,.xls",max:1,customRequest:c=>M(c,n,l),onBeforeUpload:I,onRemove:c=>T(n,l)},{default:i(()=>[f(m,null,{default:i(()=>[H(W(d(g)("common.uploadText")),1)]),_:1})]),_:2},1032,["customRequest","onRemove"])]),_:1},8,["onRegister"])]),_:1},8,["onRegister"])}}});export{pe as _,se as c};
