import{t as a,W as u,r as c,n as m,E as d}from"./index.BDe1Jdfj.js";import{d as p}from"./index.DqGCo7wf.js";import{s as h}from"./vue.D1BjjNmv.js";const n="/api/system/device-damage-records/";function f(t){return a({url:n+"?damage_type=0",method:"get",params:t})}function g(t){return a({url:n,method:"post",data:t})}function w(t){return a({url:n+t.id+"/",method:"put",data:t})}function y(t){return a({url:n+t+"/",method:"delete",data:{id:t}})}function x(){return a({url:n+"?damage_type=0",method:"get"})}function v(t){return a({url:n+t.id+"/cancel_damage/",method:"post",data:t})}const q=function({crudExpose:t}){return{crudOptions:{request:{pageRequest:async e=>await f(e),addRequest:async({form:e})=>await g(e),editRequest:async({form:e,row:o})=>(e.id=o.id,await w(e)),delRequest:async({row:e})=>await y(e.id)},form:{wrapper:{buttons:{ok:{text:"提交",show:c(e=>e.mode!=="view")}}}},actionbar:{buttons:{add:{show:!0}}},toolbar:{show:!1},rowHandle:{fixed:"right",width:290,buttons:{remove:{show:!0},edit:{show:!0},cancelDamage:{text:"撤销",type:"danger",order:98,show:c(({row:e})=>e.status!==5),click({row:e}){m.confirm("确认撤销该报损记录?","提示",{confirmButtonText:"确定",cancelButtonText:"取消",type:"warning"}).then(async()=>{try{const o=await v(e);console.log("res::::",o),o.code===2e3?(d.success("撤销成功"),t.doRefresh()):d.error(o.msg||"撤销失败")}catch{d.error("请求失败")}}).catch(()=>{})}}}},pagination:{show:!0},columns:{_index:{title:"序号",form:{show:!1},column:{type:"index",align:"center",width:"70px",columnSetDisabled:!0}},search:{title:"关键字搜索",search:{show:!0,type:"input"},type:"input",form:{component:{placeholder:"请输入"},show:!1},column:{show:!1}},damage_no:{title:"编号",search:{show:!1},treeNode:!0,type:"input",column:{minWidth:120},form:{show:!1,component:{placeholder:"请输入编号"}},viewForm:{component:{placeholder:""},rules:[{required:!0,message:""}]}},device_code:{title:"设备编号",type:"input",column:{show:!0,minWidth:120},form:{show:!0,component:{placeholder:"请填写设备编号",onBlur:async e=>{var s;const o=(s=e.target.value)==null?void 0:s.trim();if(console.log("onBlur deviceCode:",o),!!o)try{const r=await a({url:`/api/system/device/?code=${encodeURIComponent(o)}`,method:"get"});if(console.log("设备搜索响应:",r),r.code===2e3&&r.data&&r.data.length>0){const l=r.data[0];console.log("找到设备:",l);const i=t.getFormData();i.device=l.id,i.device_code=l.code,i.device_name=l.name,t.setFormData(i)}else console.log("未找到匹配的设备")}catch(r){console.error("搜索设备信息失败:",r)}}},rules:[{required:!0,message:"请填写设备编号"}]},editForm:{component:{disabled:!0}},viewForm:{component:{placeholder:""},rules:[{required:!0,message:""}]}},device:{title:"设备名称",type:"table-selector",column:{show:!1,minWidth:120},form:{component:{name:h(p),vModel:"modelValue",displayLabel:c(({row:e})=>e&&e.device_name?e.device_name:null),tableConfig:{url:"/api/system/device/",label:"name",value:"id",columns:[{prop:"name",label:"设备名称",width:150},{prop:"code",label:"设备编号",width:120}]},onChange:async e=>{if(console.log("onChange selectedDeviceId:",e),!!e)try{const o=await a({url:`/api/system/device/${e}/`,method:"get"});if(console.log("response::::",o),o.code==2e3){const s=o.data;console.log("设备数据:",s);const r=t.getFormData();r.device_code=s.code,r.device_name=s.name,t.setFormData(r)}}catch(o){console.error("获取设备信息失败:",o)}}},rules:[{required:!0,message:"请填写设备名称"}]},editForm:{component:{disabled:!0}},viewForm:{component:{placeholder:""},rules:[{required:!0,message:""}]}},device_name:{title:"设备名称",type:"input",column:{show:!0,minWidth:120},form:{show:!1,component:{placeholder:"请填写设备名称"},rules:[{required:!0,message:"请填写设备名称"}]},viewForm:{component:{placeholder:""},rules:[{required:!0,message:""}]}},quantity:{title:"报废数量",type:"input",column:{minWidth:120},form:{component:{placeholder:"请填写报废数量"},rules:[{required:!0,message:"请填写报废数量"}]},editForm:{component:{disabled:!0}},valueResolve({form:e,value:o}){e.quantity=Number(o)},viewForm:{component:{placeholder:""},rules:[{required:!0,message:""}]}},damage_type:{title:"报损类型",type:"dict-select",dict:u({data:[{label:"报废",value:0}]}),column:{show:!1,minWidth:120},form:{value:0,show:!1,component:{placeholder:"请填写报损类型"},rules:[{required:!1,message:"请填写报损类型"}]},editForm:{component:{disabled:!0}},viewForm:{component:{placeholder:""},rules:[{required:!0,message:""}]}},damage_reason:{title:"报废原因",type:"input",column:{minWidth:120},form:{component:{placeholder:"请填写报废原因"},rules:[{required:!0,message:"请填写报废原因"}]},viewForm:{component:{placeholder:""},rules:[{required:!0,message:""}]}},estimated_loss:{title:"维修费用",type:"input",column:{minWidth:120,show:!1},form:{show:!1,component:{placeholder:"请填写维修费用"},rules:[{required:!1,message:"请填写维修费用"}]},viewForm:{component:{placeholder:""},rules:[{required:!0,message:""}],show:c(({form:e})=>e&&e.damage_type===1)}},reporter_person:{title:"负责人",type:"input",column:{minWidth:120},form:{show:!1,component:{placeholder:"请填写负责人"},rules:[{required:!1,message:"请填写负责人"}]},viewForm:{component:{placeholder:""},rules:[{required:!0,message:""}]}},status:{title:"状态",type:"dict-select",dict:u({data:[{value:4,label:"已确认"},{value:5,label:"已撤销"}]}),search:{show:!0},column:{show:!1},form:{show:!1}},status_display:{title:"状态",type:"input",column:{minWidth:120},form:{show:!1,component:{placeholder:"请填写负责人"},rules:[{required:!1,message:"请填写负责人"}]},viewForm:{component:{placeholder:""},rules:[{required:!0,message:""}]}},create_datetime:{title:"创建时间",type:"datetime",column:{minWidth:120},form:{show:!1}}}}}},O=Object.freeze(Object.defineProperty({__proto__:null,createCrudOptions:q},Symbol.toStringTag,{value:"Module"}));export{x as G,O as a,q as c};