import{i as e,t}from"./react-B8IZ02wI.js";import{t as n}from"./button-DqbiydrF.js";import{t as r}from"./select-CDwQ-YxO.js";import{M as i,m as a,v as o}from"./authStore-BvQBJ9ky.js";import{On as s,ct as c,n as l,pt as u,st as d,ut as f}from"./index-Bg7bo8aA.js";var p=e(t(),1),m=l();function h({open:e,resourceType:t,resourceId:l=null,resourceIds:h,deviceId:g,onClose:_,onSuccess:v}){let y=s(),[b,x]=(0,p.useState)([]),[S,C]=(0,p.useState)([]),[w,T]=(0,p.useState)(!1),[E]=u.useForm(),D=u.useWatch(`user_id`,E),O=h&&h.length>0?h:l==null?[]:[l];return(0,p.useEffect)(()=>{e&&(o.users().then(e=>{x((e.data||[]).map(e=>({id:e.id,realName:e.realName,username:e.username||e.realName})))}).catch(()=>{c.error(`无法加载员工列表`)}),E.resetFields(),C([]))},[e,E]),(0,p.useEffect)(()=>{if(!e||t!==`ACCOUNT`||!D||O.length>1){O.length>1&&C([]);return}a.list({page:1,size:200,status:`ASSIGNED`}).then(e=>{let t=e.data.list;C(t.filter(e=>e.holderId===D).map(e=>({id:e.id,deviceCode:e.deviceCode,brand:e.brand,model:e.model})))})},[e,t,D,O.length]),(0,m.jsx)(d,{title:O.length>1?`批量分配（${O.length}）`:`分配资产`,open:e,onCancel:_,onOk:()=>E.submit(),confirmLoading:w,width:560,destroyOnHidden:!0,children:(0,m.jsxs)(u,{form:E,layout:`vertical`,onFinish:async e=>{if(O.length){T(!0);try{O.length===1?(await i.assign({resource_type:t,resource_id:O[0],user_id:e.user_id,device_id:t===`ACCOUNT`?e.device_id:g,remark:e.remark}),c.success(`分配成功`)):(await i.batchAssign({user_id:e.user_id,remark:e.remark||`批量分配`,items:O.map(e=>({resource_type:t,resource_id:e}))}),c.success(`已分配 ${O.length} 项`)),v(),_()}catch(e){c.error(e instanceof Error?e.message:`分配失败`)}finally{T(!1)}}},children:[(0,m.jsx)(u.Item,{name:`user_id`,label:`分配给`,rules:[{required:!0}],children:(0,m.jsx)(r,{showSearch:!0,optionFilterProp:`label`,options:b.map(e=>({value:e.id,label:`${e.realName} (${e.username})`}))})}),t===`ACCOUNT`&&O.length===1&&(0,m.jsx)(u.Item,{name:`device_id`,label:`绑定主设备`,extra:`可选，仅显示该员工已分配的设备`,children:(0,m.jsx)(r,{allowClear:!0,showSearch:!0,optionFilterProp:`label`,placeholder:D?`选择设备`:`请先选择员工`,disabled:!D,options:S.map(e=>({value:e.id,label:`${e.deviceCode} ${e.brand||``} ${e.model||``}`.trim()}))})}),(0,m.jsx)(u.Item,{name:`remark`,label:`备注`,children:(0,m.jsx)(f.TextArea,{rows:2})}),(0,m.jsxs)(`div`,{style:{marginTop:4,fontSize:12,color:`#6b7280`},children:[`需签收单或一次领多项资产？`,(0,m.jsx)(n,{type:`link`,size:`small`,style:{padding:`0 4px`},onClick:()=>{_();let e=E.getFieldValue(`user_id`);y(e?`/assign?userId=${e}`:`/assign`)},children:`使用入职领用向导 →`})]})]})})}export{h as t};