import{p as z,r as l,A as J,f as K,t as Q,F as h,j as e,B as U,h as N,y as W,I as C,ae as q,g,a as X,b as Y,k as Z,M as ee}from"./index-CKIL6d0V.js";import{O as ae}from"./index-DS0KBckH.js";import{R as S}from"./PlusCircleOutlined-C3dgw0Zs.js";import{F as te}from"./Table-BaVi_066.js";import{T as se}from"./index-DhKd6wcu.js";import{R as ne}from"./DeleteOutlined-BHDTCKcb.js";import"./index-C-LPyJas.js";import"./iconUtil-Co5gbObL.js";const oe=z.div`
  height: 100%;
  display: flex;
  flex-direction: column;
  .search {
    height: 60px;
    padding: 0 25px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    .btns {
      flex: 1;
      text-align: right;
    }
  }
  .content {
    flex: 1;
    height: 100%;
    display: flex;
    overflow: hidden;
    .organ {
      width: 220px;
      height: 100%;
      margin-right: 16px;
    }
    .tableBox {
      flex: 1;
      height: 100%;
      padding: 16px;
      box-sizing: border-box;
      overflow: hidden;
    }
  }
`,re=z.div`
  width: 80%;
  margin: 0 auto;
  /* .modalForm {
    padding-left: 50px;
  } */
  .modalFormTree {
    width: 100%;
  }
`,le=l.memo(()=>{const{message:s}=J.useApp(),{organ:p,changeOrgan:b}=K(a=>a),{token:{colorBgContainer:x,borderRadius:u,colorPrimaryText:F,colorWarning:D}}=Q.useToken(),[c]=h.useForm(),[n,d]=l.useState([]),[v,i]=l.useState(!1),[f,w]=l.useState("添 加"),[P,I]=l.useState(!1),[T,y]=l.useState(!1),[B,k]=l.useState(0);l.useEffect(()=>{(async()=>{try{const t=await g("/api/Orgunits/Get");d(t),b(t)}catch(t){s.error(t),console.log(t)}})()},[s,b]);const R=[{title:"序 号",dataIndex:"Id",width:80,align:"center",key:"Id",render:(a,t,o)=>e.jsx(e.Fragment,{children:o+1})},{title:"ID",dataIndex:"Id",align:"center",key:"Id",render:a=>e.jsx(e.Fragment,{children:a})},{title:"名 称",dataIndex:"Name",align:"center",key:"Id",render:a=>e.jsx(e.Fragment,{children:a})},{title:"上级组织",dataIndex:"PId",align:"center",key:"Id",render:a=>e.jsx(e.Fragment,{children:E(a)})},{title:"操 作",dataIndex:"Id",align:"center",key:"Id",render:(a,t)=>e.jsxs(X,{size:"large",style:{color:F},children:[e.jsxs("span",{style:{cursor:"pointer"},onClick:()=>O("编 辑",t),children:[e.jsx(Y,{}),"  编 辑"]}),e.jsxs("span",{style:{cursor:"pointer",display:a!==3?"inline-block":"none"},onClick:()=>V(a),children:[e.jsx(ne,{}),"  删 除"]})]})}],E=a=>{let t="根节点";return p.forEach(o=>{a===o.Id&&(t=o.Name)}),t},O=(a,t)=>{a==="添 加"?(w("添 加"),c.setFieldsValue({name:"",organization:n[0].Id})):(w("编 辑"),c.setFieldsValue({id:t.Id,name:t.Name,organization:t.PId!==0?t.PId:n[0].Id})),I(!0)},M=()=>{c.submit()},_=()=>{I(!1),c.setFieldsValue({name:"",organization:n[0].Id})},A=async a=>{const t={...a};if(f==="添 加"){const o=n.find(r=>r.Id===t.organization);if(t.name){i(!0);try{const{code:r,msg:m}=await g("/api/Orgunits/Create",{Name:t.name,PId:t.organization,Depth:o.Depth});if(r===200){s.success(m);const j=await g("/api/Orgunits/Get");d(j),i(!1)}else s.info(m)}catch(r){s.error(r),console.log(r)}}else{s.error("组织名称不能为空",3);return}}else{const o=n.find(r=>r.Id===t.id);try{i(!0);const{code:r,msg:m}=await Z("/api/Orgunits/Update",{},{Id:t.id,Name:t.name,PId:t.organization,Depth:o.Depth});if(r===200){s.success(m);const j=await g("/api/Orgunits/Get");d(j),i(!1)}else s.info(m)}catch(r){s.error(r)}}I(!1),console.log(a)},V=a=>{k(a),y(!0)},G=async()=>{i(!0);try{const{code:a,msg:t}=await ee("/api/Orgunits/Del",{Id:B});if(a===200){s.success(t),y(!1);const o=await g("/api/Orgunits/Get");d(o),i(!1)}else i(!1),s.warning(t)}catch(a){s.error(a)}},$=()=>{k(0),y(!1)},L=a=>{H(a)},H=a=>{if(!a||a===p[0].Id)d(p);else{const t=p.filter(o=>o.Id===a);d(t)}};return e.jsxs(oe,{children:[e.jsx("div",{className:"search",style:{backgroundColor:x,borderRadius:u},children:e.jsx("div",{className:"btns",children:e.jsxs(U,{type:"primary",onClick:()=>O("添 加"),children:[e.jsx(S,{})," 添 加"]})})}),e.jsxs("div",{className:"content",children:[e.jsx("div",{className:"organ",style:{backgroundColor:x,borderRadius:u},children:e.jsx(ae,{onSelectOrg:L})}),e.jsx("div",{className:"tableBox",style:{backgroundColor:x,borderRadius:u},children:e.jsx(te,{size:"small",showExpandColumn:!1,rowKey:a=>a.Id,columns:R,loading:v,dataSource:n,sticky:!0,pagination:{total:n.length,showSizeChanger:!0,showQuickJumper:!0,defaultPageSize:50,showTotal:a=>`共 ${a} 条`}})})]}),e.jsx(N,{text:e.jsxs("span",{style:{color:D,fontSize:"18px"},children:[e.jsx(W,{})," 温馨提示 : "]}),open:T,width:360,onOk:G,onCancel:$,maskClosable:!1,children:e.jsx("p",{children:"删除组织机构，可能导致相关联的人员异常，请先删除相应人员后才操作！"})}),e.jsx(N,{text:e.jsxs("span",{style:{fontSize:"24px"},children:[e.jsx(S,{}),"  ",f]}),width:618,open:P,onOk:M,onCancel:_,okButtonProps:{className:"ysh_antd_btn"},cancelButtonProps:{className:"ysh_antd_btn"},children:e.jsx(re,{children:e.jsxs(h,{className:"modalForm",form:c,labelAlign:"right",labelCol:{span:4},onFinish:A,initialValues:{id:"",name:"",organization:n[0]?n[0].Id:""},children:[f==="编 辑"&&e.jsx(h.Item,{label:"ID : ",name:"id",children:e.jsx(C,{disabled:!0,variant:!1})}),e.jsx(h.Item,{label:"名称 : ",name:"name",children:e.jsx(C,{allowClear:!0,className:"ysh_antd_input",placeholder:"请输入名称"})}),e.jsx(h.Item,{label:"上级机构 : ",name:"organization",children:n[0]&&e.jsx(se,{dropdownStyle:{maxHeight:400,overflow:"auto"},treeData:q(n,n[0].PId),placeholder:"请选择",treeDefaultExpandAll:!0,allowClear:!0,fieldNames:{label:"Name",value:"Id",children:"children"}})})]})})})]})});le.displayName="SystemOrgan";export{le as default};
