import{b as q}from"./index-D7dBOFlH.js";import{c as J}from"./menu-DfOxXMkF.js";import{c as X,d as P}from"./role-4s7QY04X.js";import{J as Q,G as W,H as Y,i as Z,h as $,I as ee,X as le,j as te,a as ae}from"./element-plus-DckSU5ni.js";import{x as oe,s as g,r as m,k,c as se,l as ne,E as V,F as r,u as t,j as y,n as E,O as o,G as ce,C as re,z as w}from"./vue-vendor-vBC20LeU.js";const de={class:"w-full flex flex-wrap items-center"},he=oe({__name:"edit",emits:["success"],setup(ue,{expose:C,emit:R}){const D=R,_=g(),d=g(),h=m("add"),n=m(!1),i=m(!1),b={id:"",name:"",desc:"",sort:0,menu_id:[]},a=k({...b}),F=k({name:[{required:!0,message:"请输入角色名称",trigger:["blur","change"]}]}),K=se(()=>h.value=="edit"?"编辑角色":"新增角色"),p=m(!0),f=m([]),L=(e="add")=>{h.value=e,i.value=!0},O=async e=>{U(),await x(),e&&(Object.keys(a).forEach(l=>{e[l]!=null&&(a[l]=e[l])}),j())},U=()=>{Object.assign(a,b),_.value?.resetFields()},x=async()=>{n.value=!0;const e=await J();f.value=e||[],n.value=!1},j=()=>{E(()=>{a.menu_id.forEach(e=>{E(()=>{d.value.setChecked(e,!0,!1)})})})},B=()=>{const e=d.value?.getCheckedKeys()||[],l=d.value?.getHalfCheckedKeys()||[];return e?.unshift.apply(e,l),e},I=e=>{const l=f.value;for(let u=0;u<l.length;u++){const c=d.value?.store?.nodesMap?.[l[u].id];c&&(c.expanded=!!e)}},N=e=>{d.value?.setCheckedNodes(e?f.value:[])},S=()=>{_.value?.validate(async e=>{e&&(n.value=!0,a.menu_id=B(),(h.value==="edit"?X:P)(a).then(()=>{n.value=!1,i.value=!1,ae.success("操作成功"),D("success")}).catch(()=>{n.value=!1}))})};return ne(()=>{x()}),C({open:L,setFormData:O}),(e,l)=>{const u=Z,c=Y,T=$,v=ee,A=le,M=W,z=te,G=q,H=Q;return w(),V(G,{modelValue:t(i),"onUpdate:modelValue":l[4]||(l[4]=s=>y(i)?i.value=s:null),title:t(K),width:"500px","close-on-click-modal":!1,confirmLoading:t(n),onConfirm:S},{default:r(()=>[o(z,{"max-height":"500px",class:"px-3 mx-[-12px]"},{default:r(()=>[ce((w(),V(M,{ref_key:"formRef",ref:_,model:t(a),rules:t(F),"label-width":"80px"},{default:r(()=>[o(c,{label:"角色名称",prop:"name"},{default:r(()=>[o(u,{modelValue:t(a).name,"onUpdate:modelValue":l[0]||(l[0]=s=>t(a).name=s),placeholder:"请输入角色名称",clearable:""},null,8,["modelValue"])]),_:1}),o(c,{label:"备注",prop:"desc"},{default:r(()=>[o(u,{modelValue:t(a).desc,"onUpdate:modelValue":l[1]||(l[1]=s=>t(a).desc=s),type:"textarea",autosize:{minRows:2,maxRows:4},placeholder:"请输入备注",maxlength:"200","show-word-limit":""},null,8,["modelValue"])]),_:1}),o(c,{label:"排序",prop:"sort"},{default:r(()=>[o(T,{modelValue:t(a).sort,"onUpdate:modelValue":l[2]||(l[2]=s=>t(a).sort=s),min:0},null,8,["modelValue"])]),_:1}),o(c,{label:"权限",prop:"menu_id"},{default:r(()=>[re("div",de,[o(v,{label:"展开/折叠",onChange:I}),o(v,{label:"全选/不全选",onChange:N}),o(v,{modelValue:t(p),"onUpdate:modelValue":l[3]||(l[3]=s=>y(p)?p.value=s:null),label:"父子联动"},null,8,["modelValue"])]),o(A,{class:"w-full mt-1",ref_key:"treeRef",ref:d,data:t(f),"node-key":"id",props:{label:"name",children:"children"},"show-checkbox":"","check-strictly":!t(p)},null,8,["data","check-strictly"])]),_:1})]),_:1},8,["model","rules"])),[[H,t(n)]])]),_:1})]),_:1},8,["modelValue","title","confirmLoading"])}}});export{he as _};
