import{i as e,t}from"./react-B8IZ02wI.js";import{t as n}from"./button-DqbiydrF.js";import{t as r}from"./table-BvNKB5G4.js";import{t as i}from"./select-CDwQ-YxO.js";import{M as a,N as o,P as s}from"./authStore-BvQBJ9ky.js";import{at as c,ct as l,gt as u,n as d,pt as f,st as p,ut as m}from"./index-Bg7bo8aA.js";import{t as h}from"./UserSelect-DwxgSkKp.js";var g=e(t(),1),_=d();function v(){let[e,t]=(0,g.useState)([]),[d,v]=(0,g.useState)(!1),[y,b]=(0,g.useState)(!1),[x,S]=(0,g.useState)(null),[C,w]=(0,g.useState)([]),[T]=f.useForm(),E=()=>{v(!0),o.list().then(e=>{t(e.data||[])}).catch(e=>l.error(s(e,`加载失败`))).finally(()=>v(!1))};(0,g.useEffect)(()=>{E(),a.departments().then(e=>{let t=e.data||[],n=new Map(t.map(e=>[e.id,e.name]));w(t.map(e=>({value:e.id,label:e.parentId?`${n.get(e.parentId)||e.parentName||``} / ${e.name}`.replace(/^\s*\/\s*/,``):e.name})))}).catch(()=>{})},[]);let D=()=>{S(null),T.resetFields(),T.setFieldsValue({dept_ids:[],user_ids:[]}),b(!0)},O=e=>{S(e),T.setFieldsValue({name:e.name,remark:e.remark,status:e.status,dept_ids:e.deptIds||[],user_ids:e.userIds||[]}),b(!0)},k=async()=>{try{let e=await T.validateFields();x?(await o.update(x.id,e),l.success(`库房已更新`)):(await o.create(e),l.success(`库房已创建`)),b(!1),E()}catch(e){if(e&&typeof e==`object`&&`errorFields`in e)return;l.error(s(e,`保存失败`))}},A=async e=>{try{await o.update(e.id,{status:e.status===`ACTIVE`?`DISABLED`:`ACTIVE`}),l.success(e.status===`ACTIVE`?`已停用`:`已启用`),E()}catch(e){l.error(s(e,`操作失败`))}},j=e=>{p.confirm({title:`删除库房「${e.name}」？`,content:`仅空库可删除，删除后不可恢复。`,onOk:async()=>{try{await o.delete(e.id),l.success(`已删除`),E()}catch(e){l.error(s(e,`删除失败`))}}})};return(0,_.jsxs)(`div`,{children:[(0,_.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`flex-start`,gap:16,marginBottom:16},children:[(0,_.jsx)(`div`,{style:{color:`#6b7280`,fontSize:13},children:`配置物理库存归属与可见范围。未配置可见部门/人员的库为公司级，仅管理员可见。`}),(0,_.jsx)(n,{type:`primary`,onClick:D,children:`新建库房`})]}),(0,_.jsx)(r,{rowKey:`id`,loading:d,dataSource:e,pagination:!1,columns:[{title:`编号`,dataIndex:`code`,width:100},{title:`名称`,dataIndex:`name`},{title:`可见部门`,render:(e,t)=>t.isCompanyLevel?(0,_.jsx)(c,{children:`公司级`}):(t.depts||[]).map(e=>(0,_.jsx)(c,{children:e.name},e.id))},{title:`可见人员`,render:(e,t)=>(t.users||[]).length?t.users.map(e=>(0,_.jsx)(c,{children:e.realName},e.id)):(0,_.jsx)(`span`,{style:{color:`#9ca3af`},children:`—`})},{title:`在库设备`,dataIndex:`deviceCount`,width:90},{title:`在库号码`,dataIndex:`simCount`,width:90},{title:`状态`,dataIndex:`status`,width:90,render:e=>e===`ACTIVE`?(0,_.jsx)(c,{color:`green`,children:`启用`}):(0,_.jsx)(c,{children:`停用`})},{title:`操作`,width:200,render:(e,t)=>(0,_.jsxs)(u,{size:`small`,children:[(0,_.jsx)(n,{type:`link`,size:`small`,onClick:()=>O(t),children:`编辑`}),(0,_.jsx)(n,{type:`link`,size:`small`,onClick:()=>A(t),children:t.status===`ACTIVE`?`停用`:`启用`}),(0,_.jsx)(n,{type:`link`,size:`small`,danger:!0,onClick:()=>j(t),children:`删除`})]})}]}),(0,_.jsx)(p,{title:x?`编辑库房`:`新建库房`,open:y,onCancel:()=>b(!1),onOk:k,destroyOnHidden:!0,width:560,children:(0,_.jsxs)(f,{form:T,layout:`vertical`,children:[(0,_.jsx)(f.Item,{name:`name`,label:`库房名称`,rules:[{required:!0,message:`请输入名称`}],children:(0,_.jsx)(m,{placeholder:`如：H部库、备用机库`})}),(0,_.jsx)(f.Item,{name:`remark`,label:`备注`,children:(0,_.jsx)(m.TextArea,{rows:2})}),x&&(0,_.jsx)(f.Item,{name:`status`,label:`状态`,children:(0,_.jsx)(i,{options:[{value:`ACTIVE`,label:`启用`},{value:`DISABLED`,label:`停用`}]})}),(0,_.jsx)(f.Item,{name:`dept_ids`,label:`可见部门`,extra:`部门主管可见该库未分配库存，并计入部门库存统计`,children:(0,_.jsx)(i,{mode:`multiple`,options:C,placeholder:`不选则为公司级库`,allowClear:!0})}),(0,_.jsx)(f.Item,{name:`user_ids`,label:`可见人员`,extra:`指定人员可查看该库未分配库存（便于仓管兼岗）`,children:(0,_.jsx)(h,{mode:`multiple`,placeholder:`可选`})})]})})]})}export{v as default};