import{R as _,d as w,e as h,f as S}from"./api.CqRi3mJO.js";import{R as D}from"./RoleMenuTreeStores.Dj-SlS5F.js";import{R as T}from"./RoleMenuBtnStores.Ds74f0Jk.js";import{R as A,a as B}from"./RoleMenuFieldStores.1tuZt4kb.js";import{X as F,E as x}from"./index.Df8UJ10K.js";import{a as P,r as m,q as b,aj as E,J as H,o as X}from"./vue.D1BjjNmv.js";const G=P({__name:"RoleMenuTree",setup(j){const i=_(),k=D(),p=T(),y=A(),v=B(),s=m(),d=m([]),R=m([]),g={children:"children",label:"name",value:"id"};let c=!1;const M=e=>{const l=[],a=[...e];for(;a.length;){const n=a.pop();if(n&&(n.id!==void 0&&n.id!==null&&l.push(n.id),Array.isArray(n.children)&&n.children.length))for(const u of n.children)a.push(u)}return l},C=async(e,l)=>{var n,u;if(c)return;await h({roleId:i.roleId,menuId:e.id,isCheck:l}).then(o=>{x({message:o.msg,type:"success"})});const a=(u=(n=s==null?void 0:s.value)==null?void 0:n.getNode)==null?void 0:u.call(n,e);if(a&&a.level===1&&Array.isArray(e.children)&&e.children.length){const o=M(e.children);if(o.length){c=!0;try{for(const t of o)t!=null&&s.value.setChecked(t,l,!1);await Promise.all(o.filter(t=>t!=null).map(t=>h({roleId:i.roleId,menuId:t,isCheck:l})))}finally{c=!1}}}if(l&&a){const o=[];let t=a.parent;for(;t&&t.data;)o.push(t.data),t=t.parent;const f=o.filter(r=>r&&r.id!==void 0&&r.id!==null);if(f.length){c=!0;try{for(const r of f)s.value.setChecked(r.id,!0,!1);await Promise.all(f.map(r=>h({roleId:i.roleId,menuId:r.id,isCheck:!0})))}finally{c=!1}}}},I=async e=>{if(e.is_catalog)p.setState([]),y.setState([]);else{k.setRoleMenuTree(e);const{data:l}=await S({roleId:i.roleId,menuId:e.id});p.setState(l.menu_btn),y.setState(l.menu_field)}v.$reset()};return b(async()=>{d.value=await w({roleId:i.roleId}),d.value=d.value.filter(e=>!e.name.includes("商户列表")&&!e.name.includes("商户账号")),R.value=F.toTreeArray(d.value).filter(e=>e.isCheck).map(e=>e.id)}),(e,l)=>{const a=E("el-tree");return X(),H(a,{ref_key:"treeRef",ref:s,data:d.value,props:g,"default-checked-keys":R.value,onCheckChange:C,onNodeClick:I,"node-key":"id","check-strictly":"","highlight-current":"","show-checkbox":"","default-expand-all":""},null,8,["data","default-checked-keys"])}}});export{G as default};
