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