import{r as p,b as J}from"./index-D7dBOFlH.js";import{_ as K}from"./Picker-D56_1Pug.js";import{r as Q}from"./role-4s7QY04X.js";import{J as P,G as W,i as X,H as Y,N as Z,S as $,T as ee,Q as ae,a as le}from"./element-plus-DckSU5ni.js";import{x as oe,s as te,r as g,k as se,c as E,E as _,F as r,u as l,j as re,G as ne,O as s,I as x,C as D,y as de,a4 as ue,M as ie,K as h,z as m}from"./vue-vendor-vBC20LeU.js";const Ve=(n={})=>p.get({url:"/auth.admin/lists",params:n}),me=n=>p.get({url:"/auth.admin/detail",params:n}),pe=n=>p.post({url:"/auth.admin/add",params:n}),we=n=>p.post({url:"/auth.admin/delete",params:n}),ce=n=>p.post({url:"/auth.admin/edit",params:n}),Ee=n=>p.post({url:"/auth.admin/disable",params:n}),xe=oe({__name:"edit",emits:["success"],setup(n,{expose:F,emit:R}){const U=R,v=te(),c=g("add"),u=g(!1),f=g(!1),b={id:"",account:"",name:"",role_id:[],avatar:"",password:"",password_confirm:"",disable:0,is_admin:0},a=se({...b}),V=g([]),y=(d,e,t)=>{a.is_admin==1||a.role_id.length?t():t(new Error("请选择角色"))},L=(d,e,t)=>{(a.password||e)&&(e||t(new Error("请再次输入密码")),e!==a.password&&t(new Error("两次输入密码不一致!"))),t()},q=E(()=>({account:[{required:!0,message:"请输入账号",trigger:["blur","change"]}],name:[{required:!0,message:"请输入名称",trigger:["blur","change"]}],role_id:[{required:!0,validator:y}],password:[c.value=="add"?{required:!0,message:"请输入密码",trigger:["blur","change"]}:{}],password_confirm:[c.value=="add"?{required:!0,message:"请输入确认密码",trigger:["blur","change"]}:{},{validator:L,trigger:"blur"}]})),C=E(()=>c.value=="edit"?"编辑管理员":"新增管理员"),j=(d="add")=>{O(),c.value=d,f.value=!0},k=async d=>{if(u.value=!0,N(),d){const e=await me({id:d});Object.keys(a).forEach(t=>{e[t]!=null&&(a[t]=e[t])})}u.value=!1},N=()=>{Object.assign(a,b),v.value?.resetFields()},O=async()=>{Q().then(d=>{V.value=d||[]})},B=()=>{v.value?.validate(async d=>{d&&(u.value=!0,(c.value==="edit"?ce:pe)(a).then(()=>{u.value=!1,f.value=!1,le.success("操作成功"),U("success")}).catch(()=>{u.value=!1}))})};return F({open:j,setFormData:k}),(d,e)=>{const t=X,i=Y,I=K,G=ae,S=Z,w=$,T=ee,M=W,z=J,A=P;return m(),_(z,{modelValue:l(f),"onUpdate:modelValue":e[7]||(e[7]=o=>re(f)?f.value=o:null),title:l(C),width:"520px","close-on-click-modal":!1,confirmLoading:l(u),onConfirm:B},{default:r(()=>[ne((m(),_(M,{ref_key:"formRef",ref:v,model:l(a),"label-width":"90px",rules:l(q)},{default:r(()=>[s(i,{label:"账号",prop:"account"},{default:r(()=>[s(t,{modelValue:l(a).account,"onUpdate:modelValue":e[0]||(e[0]=o=>l(a).account=o),placeholder:"请输入账号",clearable:""},null,8,["modelValue"])]),_:1}),s(i,{label:"头像",prop:"avatar"},{default:r(()=>[D("div",null,[s(I,{modelValue:l(a).avatar,"onUpdate:modelValue":e[1]||(e[1]=o=>l(a).avatar=o),limit:1},null,8,["modelValue"]),e[8]||(e[8]=D("div",{class:"text-base text-info leading-normal mt-1.5"},"建议尺寸：1:1，支持jpg，jpeg，png格式",-1))])]),_:1}),s(i,{label:"名称",prop:"name"},{default:r(()=>[s(t,{modelValue:l(a).name,"onUpdate:modelValue":e[2]||(e[2]=o=>l(a).name=o),placeholder:"请输入名称",clearable:""},null,8,["modelValue"])]),_:1}),l(a).is_admin!=1?(m(),_(i,{key:0,label:"角色",prop:"role_id"},{default:r(()=>[s(S,{class:"flex-1",modelValue:l(a).role_id,"onUpdate:modelValue":e[3]||(e[3]=o=>l(a).role_id=o),multiple:"",placeholder:"请选择角色",clearable:""},{default:r(()=>[(m(!0),de(ie,null,ue(l(V),(o,H)=>(m(),_(G,{key:H,label:o.name,value:o.id},null,8,["label","value"]))),128))]),_:1},8,["modelValue"])]),_:1})):x("",!0),s(i,{label:"密码",prop:"password"},{default:r(()=>[s(t,{modelValue:l(a).password,"onUpdate:modelValue":e[4]||(e[4]=o=>l(a).password=o),"show-password":"",clearable:"",placeholder:"请输入密码"},null,8,["modelValue"])]),_:1}),s(i,{label:"确认密码",prop:"password_confirm"},{default:r(()=>[s(t,{modelValue:l(a).password_confirm,"onUpdate:modelValue":e[5]||(e[5]=o=>l(a).password_confirm=o),"show-password":"",clearable:"",placeholder:"请输入确认密码"},null,8,["modelValue"])]),_:1}),l(a).is_admin!=1?(m(),_(i,{key:1,label:"管理员状态",prop:"disable"},{default:r(()=>[s(T,{modelValue:l(a).disable,"onUpdate:modelValue":e[6]||(e[6]=o=>l(a).disable=o)},{default:r(()=>[s(w,{value:0},{default:r(()=>[...e[9]||(e[9]=[h("启用",-1)])]),_:1}),s(w,{value:1},{default:r(()=>[...e[10]||(e[10]=[h("禁用",-1)])]),_:1})]),_:1},8,["modelValue"])]),_:1})):x("",!0)]),_:1},8,["model","rules"])),[[A,l(u)]])]),_:1},8,["modelValue","title","confirmLoading"])}}});export{xe as _,Ve as a,we as b,Ee as c};
