import{h as j,a as H,b as J}from"./index.44444325.js";import{q as K,A as P,B as m,a4 as x,aS as $,E as G,r as d,as as Q,L as W,o as v,K as g,H as a,t as u,n as X,J as Y,I as Z,P as ee,S as B,aM as b,O as le,D as ae}from"./index.d8ce26ef.js";const ue=B("\u4FDD\u5B58"),te=B("\u5173\u95ED"),re=K({__name:"addEdit",props:{itemId:{type:String,default:""},showModel:{type:Boolean,default:!1},isDetails:{type:String,default:"add"},sitem:{type:Object}},emits:["cancel","refresh"],setup(C,{emit:w}){const D=C,{logout:y}=P(),M=m("default"),_=m(),c=m(!1),S=m(""),i=m("add"),E=m([]),V={id:"",nickname:"",mobile:"",email:"",role:""},o=x({...V}),U=x({nickname:[{required:!0,message:"\u8BF7\u8F93\u5165\u771F\u5B9E\u59D3\u540D",trigger:"blur"},{min:2,max:12,message:"\u957F\u5EA6\u5728 2 \u5230 12 \u4E2A\u5B57\u7B26",trigger:"blur"}],mobile:[{required:!0,validator:(s,e,l)=>{e===""?l(new Error("\u624B\u673A\u53F7\u4E0D\u80FD\u4E3A\u7A7A\uFF01")):$(e)?l():l(new Error("\u624B\u673A\u53F7\u683C\u5F0F\u4E0D\u6B63\u786E\uFF01"))},trigger:"blur"}],role:[{required:!0,message:"\u8BF7\u9009\u62E9\u89D2\u8272",trigger:"change"}],email:[{required:!1,message:"\u8BF7\u8F93\u5165\u90AE\u7BB1",trigger:"change"}]}),q=async s=>{!s||await s.validate(async(e,l)=>{if(e){if(p.value===!0)return;p.value=!0;const r=Object.assign({},o),{code:n,message:F}=i.value==="add"?await j(r):await H(r);p.value=!1,n===0?(b.success(f.value+"\u6210\u529F\uFF01"),c.value=!1,w("refresh")):n>100&&n<140?(c.value=!1,y()):b.error(F)}})},T=async(s,e)=>{!s||(s.clearValidate(),s.resetFields(),await ae(async()=>{for(let l in o)l==="role"?o[l]=e.roleid||"":o[l]=e[l]}))},A=()=>{c.value=!1,w("cancel")},p=m(!0),f=m("");async function k(s){switch(p.value=!0,i.value){case"add":f.value="\u65B0\u5EFA\u8D26\u53F7";break;case"edit":f.value="\u7F16\u8F91\u8D26\u53F7";break;case"view":f.value="\u8D26\u53F7\u8BE6\u60C5";break;default:f.value="\u65B0\u5EFA\u8D26\u53F7"}const{code:e,data:l,message:r}=await J({});e===0?E.value=l!=null?l:[]:e>100&&e<140?y():b.error(r),await T(_.value,s),p.value=!1}return G(()=>D.showModel,()=>{const{showModel:s,itemId:e,isDetails:l,sitem:r}=D;c.value=s,c.value&&(S.value=e,i.value=l,k(l!=="add"?r:V))}),(s,e)=>{const l=d("el-input"),r=d("el-form-item"),n=d("el-col"),F=d("el-radio"),N=d("el-radio-group"),z=d("el-row"),h=d("el-button"),I=d("el-form"),L=d("el-dialog"),O=Q("loading");return W((v(),g(L,{"close-on-press-escape":!1,modelValue:c.value,"onUpdate:modelValue":e[5]||(e[5]=t=>c.value=t),"append-to-body":"",width:"900px",center:"",title:f.value,onClose:A},{default:a(()=>[u(I,{ref_key:"ruleFormRef",ref:_,model:o,rules:U,"label-width":"90px",class:"demo-ruleForm",size:M.value,"status-icon":""},{default:a(()=>[u(z,null,{default:a(()=>[u(n,{span:8},{default:a(()=>[u(r,{label:"\u771F\u5B9E\u59D3\u540D",prop:"nickname"},{default:a(()=>[u(l,{modelValue:o.nickname,"onUpdate:modelValue":e[0]||(e[0]=t=>o.nickname=t),disabled:i.value==="view",placeholder:"\u771F\u5B9E\u59D3\u540D"},null,8,["modelValue","disabled"])]),_:1})]),_:1}),u(n,{span:8},{default:a(()=>[u(r,{label:"\u624B\u673A\u53F7",prop:"mobile"},{default:a(()=>[u(l,{modelValue:o.mobile,"onUpdate:modelValue":e[1]||(e[1]=t=>o.mobile=t),disabled:i.value==="view",maxlength:11,placeholder:"\u624B\u673A\u53F7"},null,8,["modelValue","disabled"])]),_:1})]),_:1}),u(n,{span:8},{default:a(()=>[u(r,{label:"\u90AE\u7BB1",prop:"email"},{default:a(()=>[u(l,{modelValue:o.email,"onUpdate:modelValue":e[2]||(e[2]=t=>o.email=t),disabled:i.value==="view",placeholder:"\u90AE\u7BB1"},null,8,["modelValue","disabled"])]),_:1})]),_:1}),u(n,{span:24},{default:a(()=>[u(r,{label:"\u89D2\u8272",prop:"role"},{default:a(()=>[u(N,{modelValue:o.role,"onUpdate:modelValue":e[3]||(e[3]=t=>o.role=t),disabled:i.value==="view"},{default:a(()=>[(v(!0),X(Z,null,Y(E.value,(t,R)=>(v(),g(F,{key:t.id+R,label:t.id,disabled:t.status!=="1"},{default:a(()=>[B(le(t.role_name),1)]),_:2},1032,["label","disabled"]))),128))]),_:1},8,["modelValue","disabled"])]),_:1})]),_:1})]),_:1}),u(n,{span:24,class:"clear"},{default:a(()=>[i.value==="add"||i.value==="edit"?(v(),g(h,{key:0,type:"primary",class:"fr",style:{margin:"0 0 0 16px"},onClick:e[4]||(e[4]=t=>q(_.value))},{default:a(()=>[ue]),_:1})):ee("",!0),u(h,{class:"fr",style:{margin:"0 0 0 16px"},onClick:A},{default:a(()=>[te]),_:1})]),_:1})]),_:1},8,["model","rules","size"])]),_:1},8,["modelValue","title"])),[[O,p.value]])}}});export{re as default};
