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