import{az as f,d as B,Q as D,r as n,x as W,o as C,A as T,B as o,f as i,a as t,E as V,k as j,D as Z,a2 as G,cM as H,V as J,bP as X,cC as $,W as aa,K as ea,Z as la,__tla as ta}from"./index-92ad187a.js";import{_ as sa,__tla as da}from"./Dialog-44c9fa34.js";import{E as ra,__tla as ua}from"./el-tree-select-42c0ad8b.js";import{g as oa,__tla as ia}from"./index-f055b6ab.js";import{d as w,h as na}from"./tree-0af4953a.js";import{b as ca,__tla as ma}from"./index-343decc0.js";import{u as pa,__tla as _a}from"./useMessage-d9788660.js";let c,L,O,k,fa=Promise.all([(()=>{try{return ta}catch{}})(),(()=>{try{return da}catch{}})(),(()=>{try{return ua}catch{}})(),(()=>{try{return ia}catch{}})(),(()=>{try{return ma}catch{}})(),(()=>{try{return _a}catch{}})()]).then(async()=>{c=(d=>(d[d.CUSTOMER_QUANTITY_LIMIT=1]="CUSTOMER_QUANTITY_LIMIT",d[d.CUSTOMER_LOCK_LIMIT=2]="CUSTOMER_LOCK_LIMIT",d))(c||{}),k=async d=>await f.get({url:"/crm/customer-limit-config/page",params:d}),O=async d=>await f.delete({url:"/crm/customer-limit-config/delete?id="+d}),L=B({__name:"CustomerLimitConfigForm",emits:["success"],setup(d,{expose:x,emit:S}){const{t:h}=D(),g=pa(),m=n(!1),b=n(""),p=n(!1),U=n(""),s=n({id:void 0,type:c.CUSTOMER_LOCK_LIMIT,userIds:void 0,deptIds:void 0,maxCount:void 0,dealCountEnabled:!1}),R=W({type:[{required:!0,message:"\u89C4\u5219\u7C7B\u578B\u4E0D\u80FD\u4E3A\u7A7A",trigger:"change"}],maxCount:[{required:!0,message:"\u6570\u91CF\u4E0A\u9650\u4E0D\u80FD\u4E3A\u7A7A",trigger:"blur"}]}),y=n(),I=n(),v=n();x({open:async(e,a,l)=>{if(m.value=!0,b.value=h("action."+e),U.value=e,Q(),l){p.value=!0;try{s.value=await(async u=>await f.get({url:"/crm/customer-limit-config/get?id="+u}))(l)}finally{p.value=!1}}else s.value.type=a;await N(),await Y()}});const A=S,K=async()=>{if(y&&await y.value.validate()){p.value=!0;try{const e=s.value;U.value==="create"?(await(async a=>await f.post({url:"/crm/customer-limit-config/create",data:a}))(e),g.success(h("common.createSuccess"))):(await(async a=>await f.put({url:"/crm/customer-limit-config/update",data:a}))(e),g.success(h("common.updateSuccess"))),m.value=!1,A("success")}finally{p.value=!1}}},Q=()=>{var e;s.value={id:void 0,type:c.CUSTOMER_LOCK_LIMIT,userIds:void 0,deptIds:void 0,maxCount:void 0,dealCountEnabled:!1},(e=y.value)==null||e.resetFields()},N=async()=>{const e=await oa();I.value=[],I.value.push(...na(e))},Y=async()=>{const e=await ca();v.value=[],v.value=H(t(I));const a={};e.forEach(l=>{l.dept&&(a[l.deptId]||(a[l.deptId]=[]),a[l.deptId].push(l))}),M(v.value,a)},M=(e,a)=>{for(let l=0;l<e.length;l++){if(e[l].isUser)continue;const u=a[e[l].id];u&&(e[l].children||(e[l].children=[]),e[l].children.push(...u.map(_=>({id:_.id,name:_.username+"-"+_.nickname,isUser:!0,disabled:_.status===1})))),e[l].children&&e[l].children.length!==0&&M(e[l].children,a),e[l].disabled=!0,e[l].id="null"}};return(e,a)=>{const l=ra,u=J,_=X,q=$,F=aa,E=ea,P=sa,z=la;return C(),T(P,{title:t(b),modelValue:t(m),"onUpdate:modelValue":a[5]||(a[5]=r=>G(m)?m.value=r:null)},{footer:o(()=>[i(E,{onClick:K,type:"primary",disabled:t(p)},{default:o(()=>[V("\u786E \u5B9A")]),_:1},8,["disabled"]),i(E,{onClick:a[4]||(a[4]=r=>m.value=!1)},{default:o(()=>[V("\u53D6 \u6D88")]),_:1})]),default:o(()=>[j((C(),T(F,{ref_key:"formRef",ref:y,model:t(s),rules:t(R),"label-width":"200px"},{default:o(()=>[i(u,{label:"\u89C4\u5219\u9002\u7528\u4EBA\u7FA4",prop:"userIds"},{default:o(()=>[i(l,{modelValue:t(s).userIds,"onUpdate:modelValue":a[0]||(a[0]=r=>t(s).userIds=r),data:t(v),props:t(w),multiple:"",filterable:"","check-on-click-node":"","node-key":"id",placeholder:"\u8BF7\u9009\u62E9\u89C4\u5219\u9002\u7528\u4EBA\u7FA4"},null,8,["modelValue","data","props"])]),_:1}),i(u,{label:"\u89C4\u5219\u9002\u7528\u90E8\u95E8",prop:"deptIds"},{default:o(()=>[i(l,{modelValue:t(s).deptIds,"onUpdate:modelValue":a[1]||(a[1]=r=>t(s).deptIds=r),data:t(I),props:t(w),multiple:"",filterable:"","check-strictly":"","node-key":"id",placeholder:"\u8BF7\u9009\u62E9\u89C4\u5219\u9002\u7528\u90E8\u95E8"},null,8,["modelValue","data","props"])]),_:1}),i(u,{label:t(s).type===t(c).CUSTOMER_QUANTITY_LIMIT?"\u62E5\u6709\u5BA2\u6237\u6570\u4E0A\u9650":"\u9501\u5B9A\u5BA2\u6237\u6570\u4E0A\u9650",prop:"maxCount"},{default:o(()=>[i(_,{modelValue:t(s).maxCount,"onUpdate:modelValue":a[2]||(a[2]=r=>t(s).maxCount=r),placeholder:"\u8BF7\u8F93\u5165\u6570\u91CF\u4E0A\u9650"},null,8,["modelValue"])]),_:1},8,["label"]),t(s).type===t(c).CUSTOMER_QUANTITY_LIMIT?(C(),T(u,{key:0,label:"\u6210\u4EA4\u5BA2\u6237\u662F\u5426\u5360\u7528\u62E5\u6709\u5BA2\u6237\u6570",prop:"dealCountEnabled"},{default:o(()=>[i(q,{modelValue:t(s).dealCountEnabled,"onUpdate:modelValue":a[3]||(a[3]=r=>t(s).dealCountEnabled=r)},null,8,["modelValue"])]),_:1})):Z("",!0)]),_:1},8,["model","rules"])),[[z,t(p)]])]),_:1},8,["title","modelValue"])}}})});export{c as L,L as _,fa as __tla,O as d,k as g};
