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