import{F as k,M as c,I as J,r as R,a6 as V,aG as w,W as G}from"./index.17037962789732.js";import"./index.170379627897337.js";import"./index.170379627897315.js";import"./index.170379627897318.js";import"./index.170379627897319.js";import"./index.170379627897314.js";import"./index.170379627897325.js";import{s as L,u as S,q as W}from"./category.1703796278973.js";import{d as j,k as l,m as $,u as r,o as z,c as E,a as v,b as o,y as H,B as K}from"./vue.1703796278973.js";const Q=j({name:"modifyModal"}),ue=j({...Q,props:{formData:{type:Object,default:()=>{}},title:{type:String,defult:""},isAdd:{type:Number,default:0},isChild:{type:Number,default:0}},emits:["refresh"],setup(A,{expose:T,emit:I}){const s=A,g=l(),N=k.useForm,b=l([]),h=l([]),p=l([]),u=l({}),f=l({}),i=l({}),a=l({name:"",sortIndex:1,description:""}),y=l({name:[{required:!0,message:"请输入名称",trigger:"blur"},{max:64,message:"最多可输入64个字符"}],sortIndex:[{required:!0,message:"请输入排序",trigger:"blur"}]}),n=l(!1),{resetFields:F,validate:X,validateInfos:Y}=N(a.value,y.value),M=async()=>{g.value.validate().then(async()=>{if(i.value={},s.isAdd===0)s.isChild===1?i.value={...a.value,parentId:f.value.id}:s.isChild===2?i.value={parentId:f.value.id,...a.value}:s.isChild===3&&(i.value={...a.value}),(await L(i.value)).status===200?(c.success("操作成功！"),n.value=!1,I("refresh")):c.error("操作失败！");else if(s.isAdd===2){const e=u.value.id,t={...a.value,id:u.value.id,key:u.value.key,parentId:u.value.parentId};(await S(e,t)).status===200?(c.success("操作成功！"),n.value=!1,I("refresh")):c.error("操作失败！")}})},q=async e=>{s.isAdd===0?s.isChild===1?(f.value=e,e.children&&e.children.length>0&&(h.value=e.children.sort(C("sortIndex")),a.value={name:"",sortIndex:h.value[h.value.length-1].sortIndex+1,description:""},n.value=!0)):s.isChild===3?(await D(),p.value=b.value.sort(C("sortIndex")),p.value.length>0&&(a.value={name:"",sortIndex:p.value[p.value.length-1].sortIndex+1,description:""}),n.value=!0):s.isChild===2&&(e.level===5?(c.warning("树形结构最多添加5层"),n.value=!1):(f.value=e,a.value={name:"",sortIndex:1,description:""},n.value=!0)):s.isAdd===2&&(u.value=e,a.value={name:e.name,sortIndex:e.sortIndex,description:e.description},n.value=!0)},C=e=>function(t,_){var d=t[e],x=_[e];return d-x},D=async()=>{const t=await W({paging:!1,sorts:[{name:"sortIndex",order:"asc"},{name:"createTime",order:"desc"}]});t.status===200&&(b.value=t.result)},O=()=>{n.value=!1,F()};return $([()=>s.isAdd],()=>{},{immediate:!1,deep:!0}),T({show:q}),(e,t)=>{const _=J,d=R,x=V,B=w,P=k,U=G;return r(n)?(z(),E(U,H({key:0,title:s.title,maskClosable:!1,"destroy-on-close":"",visible:"",onOk:M,onCancel:O,okText:"确定",cancelText:"取消"},e.layout),{default:v(()=>[o(P,{layout:"vertical",ref_key:"formRef",ref:g,rules:r(y),model:r(a)},{default:v(()=>[o(d,{label:"名称",name:"name"},{default:v(()=>[o(_,{value:r(a).name,"onUpdate:value":t[0]||(t[0]=m=>r(a).name=m),maxlength:64,placeholder:"请输入名称"},null,8,["value"])]),_:1}),o(d,{label:"排序",name:"sortIndex"},{default:v(()=>[o(x,{style:{width:"100%"},id:"inputNumber",value:r(a).sortIndex,"onUpdate:value":t[1]||(t[1]=m=>r(a).sortIndex=m),min:1,placeholder:"请输入排序"},null,8,["value"])]),_:1}),o(d,{label:"说明"},{default:v(()=>[o(B,{value:r(a).description,"onUpdate:value":t[2]||(t[2]=m=>r(a).description=m),"show-count":"",maxlength:200,placeholder:"请输入说明"},null,8,["value"])]),_:1})]),_:1},8,["rules","model"])]),_:1},16,["title"])):K("",!0)}}});export{ue as _};
