import{aH as z,aI as oe,_ as le,d as ue,D as te,E as f,a7 as j,ai as ne,aT as se,H as re,x as m,aA as ie,O as de,o as V,N as x,K as s,y as n,b as R,u as ce,a as q,W as D,aS as M,G as pe}from"./index.1417328f.js";import me from"./company-modal.2d0ed9ba.js";import"./index.2abffb79.js";const{VITE_PROXY_DOMAIN_REAL:ke,VITE_PROXY_USER_REAL:fe}=oe(),P=fe+"/admin/",_e=h=>z.request("post",`${P}useradd`,{data:h}),ve=h=>z.request("post",`${P}usersave`,{data:h}),ye={class:"w-full flex justify-center"},Fe={class:"w-full flex justify-between items-center"},Ae=R("div",null,"\u64CD\u4F5C",-1),Ce=D("\u6DFB\u52A0"),be=D("\u5220\u9664"),he=D("\u4FDD\u5B58"),Ee=D("\u5173\u95ED"),ge=ue({__name:"addEdit",props:{itemId:{type:String,default:""},showModel:{type:Boolean,default:!1},isDetails:{type:String,default:"add"},sitem:{type:Object}},emits:["cancel","refresh"],setup(h,{emit:N}){const U=h,{logout:H}=te(),L=f("default"),B=f(),r=f([]);let _="";const y=f(!1),X=f(""),d=f("add"),I={id:"",nickname:"",mobile:"",companyArr:[]},Y=f(null),l=j({...I}),T=f(null),{isSuperUser:G}=ne();let g=[];const K=j({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:(a,o,u)=>{o===""?u(new Error("\u624B\u673A\u53F7\u4E0D\u80FD\u4E3A\u7A7A\uFF01")):se(o)?u():u(new Error("\u624B\u673A\u53F7\u683C\u5F0F\u4E0D\u6B63\u786E\uFF01"))},trigger:"blur"}],companyArr:[{required:!0,validator:(a,o,u)=>{o.length===0?u(new Error("\u8BF7\u9009\u62E9\u4E1A\u52A1\u516C\u53F8")):u()}}]}),W=async a=>{if(!!a){if(!_){M.warning("\u8BF7\u9009\u62E9\u9ED8\u8BA4\u516C\u53F8");return}await a.validate(async(o,u)=>{if(o){if(F.value===!0)return;const e=Object.assign({},l);d.value==="add"&&delete e.id;const i=e.companyArr.map(({companyCode:t})=>t),v=g.filter(({companyCode:t})=>!i.includes(t)).map(({companyCode:t,companyName:p,id:C})=>({id:C,companyCode:t,companyName:p,is_del:1,is_main:"0"})),A=g.filter(({companyCode:t})=>i.includes(t)).map(({companyCode:t,companyName:p,id:C})=>({id:C,companyCode:t,companyName:p,is_del:0,is_main:"0"})),w=e.companyArr.filter(({companyCode:t})=>!v.find(({companyCode:p})=>p===t)&&!A.find(({companyCode:p})=>p===t)).map(({companyCode:t,companyName:p,id:C})=>({id:C,companyCode:t,companyName:p,is_main:"0",is_del:0}));e.companyArr=[...v,...A,...w],e.companyArr.forEach(t=>{t.companyCode===_&&(t.is_main="1")}),F.value=!0;const{code:E,message:k}=d.value==="add"?await _e(e):await ve(e);F.value=!1,E===0?(M.success(b.value+"\u6210\u529F\uFF01"),y.value=!1,N("refresh")):E>100&&E<140?(y.value=!1,H()):M.error(k)}})}},$=async(a,o)=>{var u;a&&(a.clearValidate(),a.resetFields()),await pe(async()=>{for(let e in l)e==="companyArr"&&o.company_relaton?d.value!=="add"?o.company_relaton.forEach(i=>{l.companyArr.push({...i})}):l.companyArr=[]:l[e]=o[e]}),g=((u=o.company_relaton)==null?void 0:u.map(e=>({...e})))||[],d.value==="add"&&(l.companyArr=[],g=[])},S=()=>{y.value=!1,r.value=[],l.companyArr=[],_="",N("cancel")},F=f(!0),b=f("");async function O(a){switch(F.value=!0,d.value){case"add":b.value="\u65B0\u5EFA\u8D26\u53F7";break;case"edit":b.value="\u7F16\u8F91\u8D26\u53F7";break;case"view":b.value="\u8D26\u53F7\u8BE6\u60C5";break;default:b.value="\u65B0\u5EFA\u8D26\u53F7"}$(B.value,a),F.value=!1}function J(a){if(l.companyArr.splice(a,1),r.value[a]&&(_=""),r.value.splice(a,1),l.companyArr.length>=1){if(r.value[a]=!0,l.companyArr[a]){_=l.companyArr[a].companyCode,r.value[a]=!0;return}_=l.companyArr[a-1].companyCode,r.value[a-1]=!0}}function Q(a){const o=l.companyArr.map(({companyCode:e})=>e);a.forEach(e=>{if(!o.includes(e.code)){const{code:i,name:v}=e;l.companyArr.push({companyCode:i,companyName:v})}}),r.value=l.companyArr.map(()=>!1);const u=l.companyArr.findIndex(({companyCode:e})=>e===_);u>=0&&(r.value[u]=!0)}re(()=>U.showModel,()=>{const{showModel:a,itemId:o,isDetails:u,sitem:e}=U;if(y.value=a,y.value&&(X.value=o,d.value=u,O(u!=="add"?e:I)),d.value==="edit"||d.value==="view"){const i=e.company_relaton.findIndex(({is_main:v})=>String(v)==="1");i>=0&&(r.value=e.company_relaton.map(()=>!1),_=e.company_relaton[i].companyCode,r.value[i]=!0)}});function Z(a){r.value.forEach((o,u)=>{r.value[u]=!1}),_=l.companyArr[a].companyCode,r.value[a]=!0}return(a,o)=>{const u=m("el-input"),e=m("el-form-item"),i=m("el-col"),v=m("el-checkbox"),A=m("el-table-column"),w=m("ElButton"),E=m("el-table"),k=m("el-row"),t=m("el-button"),p=m("el-form"),C=m("el-dialog"),ee=ie("loading");return de((V(),x(C,{"close-on-press-escape":!1,modelValue:y.value,"onUpdate:modelValue":o[4]||(o[4]=c=>y.value=c),"append-to-body":"",width:"900px",center:"",title:b.value,onClose:S},{default:s(()=>[n(p,{class:"demo-ruleForm",ref_key:"ruleFormRef",ref:B,model:l,rules:K,"label-width":"90px",size:L.value,"status-icon":""},{default:s(()=>[n(k,null,{default:s(()=>[n(i,{span:24},{default:s(()=>[n(e,{label:"\u771F\u5B9E\u59D3\u540D",prop:"nickname"},{default:s(()=>[n(u,{modelValue:l.nickname,"onUpdate:modelValue":o[0]||(o[0]=c=>l.nickname=c),disabled:d.value==="view",placeholder:"\u771F\u5B9E\u59D3\u540D"},null,8,["modelValue","disabled"])]),_:1})]),_:1}),n(i,{span:24},{default:s(()=>[n(e,{label:"\u624B\u673A\u53F7",prop:"mobile"},{default:s(()=>[n(u,{modelValue:l.mobile,"onUpdate:modelValue":o[1]||(o[1]=c=>l.mobile=c),disabled:d.value==="view",maxlength:11,placeholder:"\u624B\u673A\u53F7"},null,8,["modelValue","disabled"])]),_:1})]),_:1}),n(i,{span:24},{default:s(()=>[n(e,{label:"\u4E1A\u52A1\u516C\u53F8",prop:"companyArr"},{default:s(()=>[n(E,{data:l.companyArr,border:"",size:"small","row-key":"companyCode","reserve-selection":"",ref_key:"tableRef",ref:Y},{default:s(()=>[n(A,{label:"\u9ED8\u8BA4\u516C\u53F8",width:"80px"},{default:s(({$index:c})=>[R("div",ye,[n(v,{disabled:d.value==="view",modelValue:r.value[c],"onUpdate:modelValue":ae=>r.value[c]=ae,onChange:()=>Z(c)},null,8,["disabled","modelValue","onUpdate:modelValue","onChange"])])]),_:1}),n(A,{label:"\u516C\u53F8\u7F16\u53F7",prop:"companyCode"}),n(A,{label:"\u516C\u53F8\u540D\u79F0",prop:"companyName"}),d.value!=="view"&&ce(G)?(V(),x(A,{key:0,width:"100px",label:"\u64CD\u4F5C"},{header:s(()=>[R("div",Fe,[Ae,n(w,{text:"",type:"primary",onClick:o[2]||(o[2]=()=>T.value.onDisplay())},{default:s(()=>[Ce]),_:1})])]),default:s(({$index:c})=>[n(w,{text:"",type:"danger",onClick:()=>J(c)},{default:s(()=>[be]),_:2},1032,["onClick"])]),_:1})):q("v-if",!0)]),_:1},8,["data"])]),_:1})]),_:1})]),_:1}),n(i,{span:24,class:"clear"},{default:s(()=>[d.value==="add"||d.value==="edit"?(V(),x(t,{key:0,type:"primary",class:"fr",style:{margin:"0 0 0 16px"},onClick:o[3]||(o[3]=c=>W(B.value)),loading:F.value},{default:s(()=>[he]),_:1},8,["loading"])):q("v-if",!0),n(t,{class:"fr",style:{margin:"0 0 0 16px"},onClick:S},{default:s(()=>[Ee]),_:1})]),_:1})]),_:1},8,["model","rules","size"]),n(me,{ref_key:"companyModalRef",ref:T,onChoose:Q},null,512)]),_:1},8,["modelValue","title"])),[[ee,F.value]])}}});var Ve=le(ge,[["__file","/Users/apple/Desktop/Company Projects/accout-vue3-ui/src/views/interest/companyAccount/addEdit.vue"]]);export{Ve as default};