import{u as H}from"./useInstance.233fbdde.js";import{d as $,r as c,b as I,p as L,c as h,e as P,k as j,i as a,h as n,u,g as f,aC as q,H as G,t as F,a2 as J,m as _,cB as O,cC as Q,cD as R,E,cE as W}from"./index.0308b213.js";import{c as b,g as x,a as N}from"./el-tree.54e888c4.js";const X={style:{display:"flex","align-items":"flex-start"}},Y={class:"flex",style:{"margin-top":"3px"}},Z=_(" \u5168\u9009 "),ee=_(" \u5168\u4E0D\u9009 "),le=_("\u63D0\u4EA4"),se=_("\u53D6\u6D88"),ae=$({props:{modelValue:{type:Boolean},id:null},emits:["update:modelValue","onClose"],setup(B,{emit:D}){const r=B,T=c(!0),s=c();let k=c([]);c([]),c([]);const o=I({id:0,name:"",desc:"",permissions:[]}),A=e=>e==="M"||e==="C"?"\u83DC\u5355":e==="F"?"\u6743\u9650":"",g=c(!1);let C=c(!1);L(()=>r.modelValue,e=>{g.value=e,r.id&&Number(r.id)>0?(C.value=!0,o.id=r.id,O({id:r.id}).then(l=>{var t;o.name=l.role.name,o.desc=l.role.desc,k.value=l.menu_list,(t=s.value)==null||t.setCheckedKeys(l.auth_keys)})):(C.value=!1,Q().then(l=>{k.value=l}))});const S=e=>{var t;let l=(t=s==null?void 0:s.value)==null?void 0:t.getNode(e);console.log(l,l.isLeaf,"checkNode")},y=(e,l)=>{e.forEach(t=>{var d;console.log(t,t.name,"asss"),t.children&&t.children.length>0&&y(t.children,l),(d=s==null?void 0:s.value)==null||d.setChecked(t.id,l,!1)})},w=e=>{var t;const l=(t=s==null?void 0:s.value)==null?void 0:t.getNode(e).checked;console.log(e,l,"isChecked",e.children.length),l?e.children&&e.children.length>0&&y(e.children,!0):e.children&&e.children.length>0&&y(e.children,!1)},V=()=>{var e;o.permissions=x(s.value),o.permissions.push(...N(s.value)),console.log((e=s.value)==null?void 0:e.getCheckedNodes(),N(s.value),x(s.value),o.permissions,"formData.permissions")},z=()=>{b(!0,s.value)},K=()=>{b(!1,s.value)},M=()=>{o.id>0?(V(),R(o).then(e=>{E({message:e.msg,type:"success"}),m()})):(V(),W(o).then(e=>{E({message:e.msg,type:"success"}),m()}))},m=()=>{D("update:modelValue",!1),D("onClose"),o.id=0,o.rolename="",o.permissions=[]};return c(),H(),(e,l)=>{const t=h("el-input"),d=h("el-form-item"),p=h("el-button"),U=h("el-dialog");return P(),j(U,{modelValue:g.value,"onUpdate:modelValue":l[4]||(l[4]=i=>g.value=i),title:u(C)?"\u7F16\u8F91\u89D2\u8272":"\u6DFB\u52A0\u89D2\u8272",width:"50%","destroy-on-close":"",onClose:m},{default:a(()=>[n(u(J),{model:u(o),"label-width":"120px"},{default:a(()=>[n(d,{label:"\u89D2\u8272\u540D"},{default:a(()=>[n(t,{modelValue:u(o).name,"onUpdate:modelValue":l[0]||(l[0]=i=>u(o).name=i),placeholder:"\u8BF7\u8F93\u5165\u89D2\u8272\u540D"},null,8,["modelValue"])]),_:1}),n(d,{label:"\u63CF\u8FF0"},{default:a(()=>[n(t,{modelValue:u(o).desc,"onUpdate:modelValue":l[1]||(l[1]=i=>u(o).desc=i),placeholder:"\u8BF7\u8F93\u5165\u89D2\u8272\u540D"},null,8,["modelValue"])]),_:1}),n(d,{label:"\u6743\u9650",prop:"auth_keys"},{default:a(()=>[f("div",X,[f("div",Y,[n(p,{type:"primary",size:"small",onClick:l[2]||(l[2]=i=>z())},{default:a(()=>[Z]),_:1}),n(p,{type:"primary",size:"small",onClick:l[3]||(l[3]=i=>K())},{default:a(()=>[ee]),_:1})]),f("div",null,[n(u(q),{ref_key:"treeRef",ref:s,data:u(k),onCheck:w,onCheckChange:S,"node-key":"id",props:{children:"children",label:"name"},"check-strictly":T.value,"show-checkbox":"","check-on-click-node":"","default-checked-keys":u(o).permissions},{default:a(({node:i,data:v})=>[f("text",{class:G(["permission-tree-text",[{permission:v.type==="F"}]])},F(v.name)+"["+F(A(v.type))+"] ",3)]),_:1},8,["data","check-strictly","default-checked-keys"])])])]),_:1}),n(d,null,{default:a(()=>[n(p,{type:"primary",onClick:M},{default:a(()=>[le]),_:1}),n(p,{onClick:m},{default:a(()=>[se]),_:1})]),_:1})]),_:1},8,["model"])]),_:1},8,["modelValue","title"])}}});export{ae as _};
