PageSourceSearch

https://nationalcatalog.kz/assets/CategoriesSection-CORDeaV2.js

js nationalcatalog.kz collected 2026-10-08 23:42:26 UTC 15,605 bytes, 1 lines download raw bytes

1import{u as ue,f as o,ac as je,j as e,D as Ee,a as Pe,b as ze,S as Q,d as J,a6 as _,v as D,P as he,T as b,I as re,c as Me,ad as Be,a9 as N,R as O,B as p,w as $e,ae as Ue,y as Fe,af as ce,ag as _e,ah as se}from"./index-CVZHw6o0.js";import{D as Ne}from"./DataTable-C1WKM_pH.js";import{s as Ce,a as Ve}from"./styles-BC89_VNa.js";import{E as He}from"./Edit-D4tEmle0.js";import{D as Ke}from"./Delete-D22Q7w95.js";import{D as Xe}from"./DeleteOutline-CBKK_uok.js";import{A as Ge}from"./AddCircle-Cqh2u12f.js";import{a as ve}from"./attribute.service-4fJTr4z2.js";import{c as xe}from"./category-attributes.service-o3opRw62.js";import{T as Qe,a as Je,b as Se,c as F}from"./TableRow-hPGKIpBS.js";import{S as ye}from"./Switch-CkyN8WLK.js";import{A as Ye}from"./ArrowCircleLeft-BTqjVysU.js";import{P as Ze}from"./PageSwitcher-DKal37GC.js";import{S as et}from"./SearchNormal-CKH5BeE-.js";import"./MoreVert-Bo-lUaZe.js";import"./KeyboardArrowDown-V3Bhl8GV.js";import"./Checkbox-DCuPBDks.js";const tt=({open:u,categoryId:V,onClose:d,onSaved:A,initialSelected:I=[]})=>{const{language:M}=ue(),[g,T]=o.useState([]),[C,R]=o.useState(!1),[w,v]=o.useState(!1),[k,j]=o.useState(!1),[S,f]=o.useState({open:!1,message:"",severity:"error"}),[c,h]=o.useState([]);o.useEffect(()=>{if(!u)return;R(!0),(async()=>{try{const r=await ve.getAttributesByTypes(["compound","advanced"],!0);T(r)}catch(r){je(r,"Не удалось загрузить атрибуты",(a,l)=>{f({open:!0,severity:"error",message:a?`${a}: ${l}`:l})}),T([])}finally{R(!1)}})();const i=I.length>0?I.slice().sort((r,a)=>(r.attributeOrder||0)-(a.attributeOrder||0)).map((r,a)=>({attributeCode:r.attributeCode,attributeOrder:r.attributeOrder||a+1,isUnique:!!r.isUnique,isRequired:!!r.isRequired})):[];h(i),v(!1)},[u,I]);const L=i=>N(i,M)+` (${E(i.attributeType)})`,E=i=>{switch(i){case"advanced":return"Расширенный";case"compound":return"Составной";default:return i}},H=o.useMemo(()=>{const i=new Set(c.map(r=>r.attributeCode));return g.filter(r=>!i.has(r.code))},[g,c]),B=i=>{const r=new Set(c.filter((a,l)=>l!==i).map(a=>a.attributeCode));return g.filter(a=>!r.has(a.code))},$=(i,r)=>{r&&(h(a=>{var l,x;return[...a,{attributeCode:r.code,attributeOrder:a.length+1,isUnique:((l=r.details)==null?void 0:l.isUnique)||!1,isRequired:((x=r.details)==null?void 0:x.isRequired)||!1}]}),v(!1))},Y=(i,r)=>{r&&h(a=>{var x,y;const l=[...a];return l[i]={...l[i],attributeCode:r.code,isUnique:((x=r.details)==null?void 0:x.isUnique)||!1,isRequired:((y=r.details)==null?void 0:y.isRequired)||!1},l})},Z=i=>{h(r=>r.filter(a=>a.attributeCode!==i).map((a,l)=>({...a,attributeOrder:l+1})))},W=(i,r)=>{h(a=>{const l=[...a],x=i;let y=Math.max(1,Math.floor(r));y=Math.min(y,l.length);const[U]=l.splice(x,1);return l.splice(y-1,0,U),l.map((q,P)=>({...q,attributeOrder:P+1}))})},ee=(i,r)=>{h(a=>a.map(l=>l.attributeCode===i?{...l,isUnique:r}:l))},K=(i,r)=>{h(a=>a.map(l=>l.attributeCode===i?{...l,isRequired:r}:l))},X=async()=>{try{j(!0),await xe.save(V,c),A==null||A(),f({open:!0,severity:"success",message:"Сохранено"}),d()}catch(i){je(i,"Ошибка сохранения",(r,a)=>{f({open:!0,severity:"error",message:r?`${r}: ${a}`:a})})}finally{j(!1)}};return e.jsxs(Ee,{open:u,onClose:d,fullWidth:!0,maxWidth:"md",children:[e.jsx(Pe,{children:"Редактирование атрибутов категории"}),e.jsx(ze,{dividers:!0,children:e.jsxs(Q,{spacing:2,children:[e.jsx(J,{variant:"outlined",startIcon:e.jsx(Ge,{}),onClick:()=>v(!0),disabled:w||C,sx:{alignSelf:"flex-start",borderRadius:2,textTransform:"none"},children:"Добавить атрибут"}),w&&e.jsx(_,{options:H,loading:C,getOptionLabel:L,onChange:$,renderInput:i=>e.jsx(D,{...i,autoFocus:!0,placeholder:"Поиск атрибута"})}),e.jsx(he,{variant:"outlined",children:e.jsx(Qe,{children:e.jsxs(Je,{children:[c.map((i,r)=>e.jsxs(Se,{children:[e.jsx(F,{sx:{minWidth:280,width:"40%"},children:e.jsx(_,{options:B(r),value:B(r).find(a=>a.code===i.attributeCode)||g.find(a=>a.code===i.attributeCode)||null,getOptionLabel:L,onChange:(a,l)=>Y(r,l),renderInput:a=>e.jsx(D,{...a,size:"small",label:"Атрибут",placeholder:"Поиск"}),fullWidth:!0})}),e.jsx(F,{sx:{width:1,minWidth:80,maxWidth:100},children:e.jsx(D,{type:"number",label:"Порядок",value:i.attributeOrder,onChange:a=>W(r,Number(a.target.value)),inputProps:{min:1,step:1,style:{textAlign:"center",width:50}},size:"small",sx:{width:80,minWidth:60,maxWidth:100}})}),e.jsx(F,{children:e.jsxs(Q,{direction:"row",alignItems:"center",spacing:1,children:[e.jsx(b,{variant:"body2",children:"Уникальный"}),e.jsx(ye,{checked:i.isUnique,onChange:(a,l)=>ee(i.attributeCode,l)})]})}),e.jsx(F,{children:e.jsxs(Q,{direction:"row",alignItems:"center",spacing:1,children:[e.jsx(b,{variant:"body2",children:"Обязательный"}),e.jsx(ye,{checked:i.isRequired,onChange:(a,l)=>K(i.attributeCode,l)})]})}),e.jsx(F,{children:e.jsx(re,{color:"error",onClick:()=>Z(i.attributeCode),children:e.jsx(Xe,{})})})]},i.attributeCode+"-"+r)),c.length===0&&e.jsx(Se,{children:e.jsx(F,{colSpan:5,children:e.jsx(b,{variant:"body2",color:"text.secondary",children:"Атрибуты не выбраны"})})})]})})})]})}),e.jsxs(Me,{children:[e.jsx(J,{onClick:d,children:"Отмена"}),e.jsx(J,{variant:"contained",onClick:X,disabled:c.length===0||k,children:"Сохранить"})]}),e.jsx(Be,{open:S.open,severity:S.severity,message:S.message,onClose:()=>f(i=>({...i,open:!1}))})]})},st=({category:u,onBack:V,standardAttrs:d})=>{const{language:A}=ue(),[I,M]=O.useState(!1),[g,T]=O.useState(!1),[C,R]=O.useState([]),[w,v]=O.useState({open:!1,message:""}),k=O.useMemo(()=>{var h;if(typeof u.level=="number")return u.level===4;const c=((h=u==null?void 0:u.properties)==null?void 0:h.code)||"";return c?c.split("-").length===4:!1},[u]),j=O.useCallback(async()=>{T(!0);try{const c=await xe.getBoundAttributes(u.id);Array.isArray(c)&&c.sort((h,L)=>(h.attributeOrder??0)-(L.attributeOrder??0)),R(Array.isArray(c)?c:[])}catch{R([])}finally{T(!1)}},[u.id]),S=O.useCallback(async()=>{await j(),M(!0)},[j]);O.useEffect(()=>{j()},[j]);const f=O.useMemo(()=>C.map((c,h)=>({attributeCode:c.attributeCode,attributeOrder:c.attributeOrder??h+1,isUnique:!!c.isUnique,isRequired:!!c.isRequired})),[C]);return e.jsxs(he,{elevation:0,sx:Ce,children:[e.jsxs(p,{sx:{p:3},children:[e.jsxs(Q,{direction:"row",alignItems:"center",spacing:2,mb:{xs:2,md:3},children:[e.jsx(re,{onClick:V,size:"small",children:e.jsx(Ye,{})}),e.jsxs(b,{variant:"h4",gutterBottom:!0,children:[u.properties.nameRu," / ",u.properties.nameKk]})]}),e.jsxs(p,{sx:{mt:4},children:[e.jsx(b,{variant:"subtitle1",fontWeight:"bold",gutterBottom:!0,children:"Данные о категории"}),e.jsxs(p,{sx:{mt:2},children:[e.jsxs(p,{sx:{display:"flex",mb:2}
1,children:[e.jsx(b,{sx:{width:167,color:"#3b3b3b",fontWeight:"bold"},variant:"body2",children:"ID"}),e.jsx(b,{variant:"body2",fontWeight:"medium",children:u.id})]}),e.jsxs(p,{sx:{display:"flex",mb:2},children:[e.jsx(b,{sx:{width:167,color:"#3b3b3b",fontWeight:"bold"},variant:"body2",children:"Код ОКТРУ"}),e.jsx(b,{variant:"body2",fontWeight:"medium",children:u.properties.code})]}),e.jsxs(p,{sx:{display:"flex",mb:2},children:[e.jsx(b,{sx:{width:167,color:"#3b3b3b",fontWeight:"bold"},variant:"body2",children:"Уровень"}),e.jsx(b,{variant:"body2",fontWeight:"medium",children:u.level})]}),e.jsxs(p,{sx:{display:"flex",mb:2},children:[e.jsx(b,{sx:{width:167,color:"#3b3b3b",fontWeight:"bold"},variant:"body2",children:"Статус"}),e.jsx(b,{variant:"body2",fontWeight:"medium",children:u.isDeleted?"Не активна":"Активна"})]}),e.jsxs(p,{sx:{display:"flex",mb:2},children:[e.jsx(b,{sx:{width:167,color:"#3b3b3b",fontWeight:"bold"},variant:"body2",children:"Стандартные    атрибуты"}),e.jsx(p,{children:d.length?e.jsx(p,{children:d.map((c,h)=>e.jsx(b,{variant:"body2",fontWeight:"medium",sx:{mb:1},children:N(c,A)},h))}):e.jsx(b,{variant:"body2",color:"text.secondary",children:"Нет стандартных атрибутов"})})]}),e.jsxs(p,{sx:{display:"flex",mb:2},children:[e.jsx(b,{sx:{width:167,color:"#3b3b3b",fontWeight:"bold"},variant:"body2",children:"Расширенные атрибуты"}),e.jsxs(p,{children:[g?e.jsx($e,{size:24}):C.length?e.jsx(p,{children:C.map((c,h)=>e.jsx(b,{variant:"body2",fontWeight:"medium",sx:{mb:1},children:N(c.attribute,A)},h))}):e.jsx(b,{variant:"body2",color:"text.secondary",children:"Расширенных атрибутов нет"}),e.jsx(J,{variant:"outlined",startIcon:e.jsx(He,{}),size:"small",disabled:!k||g,onClick:()=>k&&!g&&S(),sx:{mt:1,borderRadius:2,textTransform:"none",boxShadow:1},children:"Редактировать"})]})]})]})]})]}),e.jsx(p,{sx:{display:"flex",justifyContent:"flex-end",p:2,borderTop:"1px solid",borderColor:"divider"},children:e.jsx(J,{variant:"outlined",color:"error",onClick:()=>{},startIcon:e.jsx(Ke,{}),sx:{borderRadius:2,textTransform:"none",boxShadow:1,px:2,py:1},children:"Удалить"})}),e.jsx(tt,{open:k&&I,categoryId:u.id,initialSelected:f,onClose:()=>M(!1),onSaved:async()=>{await j(),v({open:!0,message:"Изменения сохранены"})}}),e.jsx(Ue,{open:w.open,autoHideDuration:2e3,onClose:()=>v(c=>({...c,open:!1})),anchorOrigin:{vertical:"bottom",horizontal:"right"},children:e.jsx(Fe,{onClose:()=>v(c=>({...c,open:!1})),severity:"success",variant:"filled",sx:{width:"100%"},children:w.message})})]})},St=()=>{const{language:u,t:V}=ue(),d=V.categoriesSection,[A,I]=o.useState([]),[M,g]=o.useState({}),[T,C]=o.useState([]),[R,w]=o.useState([]),[v,k]=o.useState([]),[j,S]=o.useState([]),[f,c]=o.useState(""),[h,L]=o.useState(""),[E,H]=o.useState(""),[B,$]=o.useState(""),[Y,Z]=o.useState(null),[W,ee]=o.useState(""),[K,X]=o.useState([]),[i,r]=o.useState(0),[a,l]=o.useState(!1),[x,y]=o.useState(!1),U=o.useRef(""),[q,P]=o.useState(1),[G,ke]=o.useState(10),[ae,Ae]=o.useState("id"),[be,we]=o.useState("ASC"),pe=o.useMemo(()=>B||E||h||f||void 0,[f,h,E,B]);o.useEffect(()=>{let t=!0;return(async()=>{try{const s=await ce.getRoot();t&&C(s||[])}catch{t&&C([])}})(),()=>{t=!1}},[]),o.useEffect(()=>{let t=!0;return ve.getAttributesByTypes(["standard","compoundStandard"]).then(s=>t&&I(s)).catch(()=>t&&I([])),()=>{t=!1}},[]);const ie=async(t,s)=>{try{const n=await ce.getChildren(s);switch(t){case 2:w(n||[]);break;case 3:k(n||[]);break;case 4:S(n||[]);break}}catch{switch(t){case 2:w([]);break;case 3:k([]);break;case 4:S([]);break}}},ne=o.useCallback(async t=>{const s=W.trim();l(!0);try{const n=await ce.searchChildrenPaged(s,{parentId:t||pe,page:q,size:G}),m=n.items||n.content||[];if(m.length){const le={};await Promise.all(m.map(async de=>{try{const Le=await xe.getCategoryAttributes(de.id);le[de.id]=Le||[]}catch{le[de.id]=[]}})),g(le)}else g({});const oe=n.total??n.totalElements??m.length,De=Math.max(1,Math.ceil(oe/G));X(m),r(De),y(!0),U.current=s}catch{X([]),r(0),y(!0),U.current=s}finally{l(!1)}},[W,pe,q,G]);o.useEffect(()=>{x&&ne()},[q,G,x]);const me=()=>{if(!x&&q!==1){P(1);return}ne()},z=t=>{q!==1&&P(1),ne(t)},Oe=(t,s)=>{ee(s),x&&s.trim()!==U.current&&y(!1)},Ie=()=>{y(!1),X([]),r(0),ee(""),U.current="",P(1)},Te=t=>{const s=M[t.id]||[],n=new Map;return A.forEach(m=>
1n.set(m.code,m)),s.forEach(m=>n.set(m.code,m)),Array.from(n.values())},fe=t=>N(t,u),ge=o.useCallback(t=>{const s=t.map(fe).filter(Boolean),n=s.length;if(!n)return d.attributesEmpty;const m=s.slice(0,3).join(", "),oe=d.attributesSummary.replace("{count}",String(n)).replace("{list}",m);return n>3?d.attributesSummaryMore.replace("{count}",String(n)).replace("{list}",m):oe},[d,fe]),Re=o.useMemo(()=>K.map(s=>{const n=Te(s);return{id:s.id,categoryName:N(s,u)||d.noName,okturCode:s.properties.code||"-",level:s.level,attributesDisplay:ge(n),status:s.isDeleted?d.statusInactive:d.statusActive,statusColor:s.isDeleted?"#f04d53":"#1e9e32",raw:s}}),[K,u,ge,d,ae,be,x]),We=o.useMemo(()=>[{key:"id",label:"ID",width:80,sortable:!x},{key:"categoryName",label:d.categoryName,sortable:!x},{key:"okturCode",label:d.okturCode,sortable:!x,hideOnXs:!0},{key:"level",label:d.level,width:120,sortable:!x},{key:"attributesDisplay",label:d.attributes,sortable:!1,minWidth:200},{key:"status",label:d.status,width:140,sortable:!x}],[x,d]),qe=t=>{if(x||!t.sortable)return;const s=t.key;Ae(s),we(n=>n==="ASC"&&s===ae?"DESC":"ASC")},te=t=>N(t,u)||d.noName;return Y?e.jsx(st,{category:Y,standardAttrs:A,onBack:()=>Z(null)}):e.jsxs(he,{elevation:0,sx:Ce,children:[e.jsx(b,{variant:"h4",sx:Ve,children:d.title}),e.jsxs(p,{sx:{mb:2},children:[e.jsx(D,{fullWidth:!0,size:"small",value:W,onChange:t=>Oe(null,t.target.value),placeholder:d.searchPlaceholder,onKeyDown:t=>{t.key==="Enter"&&(t.preventDefault(),me())},InputProps:{startAdornment:e.jsx(_e,{position:"start",sx:{pl:.5},children:e.jsx(re,{size:"small",onClick:me,disabled:a||!W.trim(),sx:{mr:.5,color:W.trim()?"#2d5064":"#94a3ab","&:hover":{bgcolor:"transparent"}},children:e.jsx(et,{size:18})})}),endAdornment:e.jsx(e.Fragment,{children:x&&!a&&!!W.trim()&&e.jsx(re,{size:"small",onClick:Ie,sx:{color:"#b6b6b6","&:hover":{color:"#2d5064"}},children:"✕"})}),sx:{bgcolor:"#fff",borderRadius:3,height:44,"& fieldset":{border:"1px solid #e3e3e3"}}}}),e.jsx(b,{variant:"caption",sx:{mt:.5,display:"block",color:"#6b7b84"},children:a?d.searchHint.loading:x&&K.length===0?d.searchHint.empty:d.searchHint.default})]}),e.jsxs(Q,{direction:"row",spacing:1,flexWrap:"wrap",useFlexGap:!0,sx:{mb:3},children:[e.jsx(se,{sx:{flex:1,minWidth:180},children:e.jsx(_,{size:"small",options:T,value:T.find(t=>String(t.id)===f)||null,onChange:(t,s)=>{const n=s?String(s.id):"";c(n),L(""),H(""),$(""),w([]),k([]),S([]),n&&(ie(2,n),z(n))},getOptionLabel:t=>t?`${te(t)} (${t.properties.code})`:"",isOptionEqualToValue:(t,s)=>String(t.id)===String(s==null?void 0:s.id),renderInput:t=>e.jsx(D,{...t,placeholder:d.levelPlaceholders.level1})})}),e.jsx(se,{sx:{flex:1,minWidth:180},children:e.jsx(_,{size:"small",options:R,value:R.find(t=>String(t.id)===h)||null,onChange:(t,s)=>{const n=s?String(s.id):"";L(n),H(""),$(""),k([]),S([]),n?(ie(3,n),z(n)):z(f)},disabled:!f,getOptionLabel:t=>t?`${te(t)} (${t.properties.code})`:"",isOptionEqualToValue:(t,s)=>String(t.id)===String(s==null?void 0:s.id),renderInput:t=>e.jsx(D,{...t,placeholder:d.levelPlaceholders.level2})})}),e.jsx(se,{sx:{flex:1,minWidth:180},children:e.jsx(_,{size:"small",options:v,value:v.find(t=>String(t.id)===E)||null,onChange:(t,s)=>{const n=s?String(s.id):"";H(n),$(""),S([]),n?(ie(4,n),z(n)):z(h)},disabled:!h,getOptionLabel:t=>t?`${te(t)} (${t.properties.code})`:"",isOptionEqualToValue:(t,s)=>String(t.id)===String(s==null?void 0:s.id),renderInput:t=>e.jsx(D,{...t,placeholder:d.levelPlaceholders.level3})})}),e.jsx(se,{sx:{flex:1,minWidth:180},children:e.jsx(_,{size:"small",options:j,value:j.find(t=>String(t.id)===B)||null,onChange:(t,s)=>{const n=s?String(s.id):"";$(n),z(n||E)},disabled:!E,getOptionLabel:t=>t?`${te(t)} (${t.properties.code})`:"",isOptionEqualToValue:(t,s)=>String(t.id)===String(s==null?void 0:s.id),renderInput:t=>e.jsx(D,{...t,placeholder:d.levelPlaceholders.level4})})})]}),e.jsxs(p,{sx:{width:"100%",overflowX:"auto",borderRadius:2,border:"1px solid rgba(68,112,134,0.08)",position:"relative",bgcolor:"#fff",pb:1.5},children:[e.jsx(Ne,{columns:We,data:Re,loading:a,sortField:ae,sortDirection:be,onSort:qe,emptyMessage:a?d.tableLoading:d.tableEmpty,onRowClick:t=>Z(t.raw)}),e.jsx(p,{sx:{px:2,pt:1},children:e.jsx(Ze,{page:q,totalPages:i,onChange:t=>P(t),pageSize:G,onPageSizeChange:t=>{ke(t),P(1)},pageSizeOptions:[10,20,50]})})]})]})};export{St as CategoriesSection};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.