import{j as e,s as o}from"./index-3808da28.js";import{a6 as b,u as y,F as a,d as g,r as w,C as p,y as N,B as h,a7 as v,J as k,I as i,z as d,a8 as I}from"./vendor-61f0f29a.js";const{Title:q}=I,C=()=>{const{id:r}=b(),[x]=y(),c=x.get("edit")==="true",m=r&&!c,[n]=a.useForm(),u=g(),j=async()=>{try{const{data:s,error:t}=await o.from("resources").select("*").eq("id",r).single();if(t)throw t;r&&n.setFieldsValue({name:s.attributes.name,contact:s.attributes.contact,phone:s.attributes.phone,address:s.attributes.address,status:s.attributes.status||"active",remark:s.attributes.remark})}catch(s){console.error("获取供应商详情失败:",s)}};w.useEffect(()=>{r&&j()},[r]);const f=async s=>{try{const t={type:"supplier",attributes:{name:s.name,contact:s.contact,phone:s.phone,address:s.address,status:s.status,remark:s.remark}};let l;if(r?l=await o.from("resources").update(t).eq("id",r).select():l=await o.from("resources").insert([t]).select(),l.error)throw l.error;u("/company/supplier")}catch(t){console.error("保存失败:",t)}};return e.jsx("div",{className:"bg-gradient-to-b from-gray-50 to-white min-h-screen p-6",children:e.jsx(p,{className:"shadow-lg rounded-lg border-0",title:e.jsxs("div",{className:"flex justify-between items-center py-2",children:[e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx(q,{level:4,className:"mb-0 text-gray-800",children:r?c?"编辑供应商":"查看供应商":"新建供应商"}),e.jsx("span",{className:"text-gray-400 text-sm",children:r?c?"请修改供应商信息":"供应商详情":"请填写供应商信息"})]}),e.jsxs(N,{size:"middle",children:[e.jsx(h,{icon:e.jsx(v,{}),onClick:()=>u("/company/supplier"),children:"返回"}),!m&&e.jsx(h,{type:"primary",icon:e.jsx(k,{}),onClick:()=>n.submit(),children:"保存"})]})]}),style:{backgroundColor:"#fff"},children:e.jsx(a,{form:n,onFinish:f,layout:"vertical",initialValues:{status:"active"},className:"space-y-6",disabled:m,children:e.jsxs(p,{className:"shadow-sm rounded-lg",type:"inner",title:e.jsxs("span",{className:"flex items-center space-x-2 text-gray-700",children:[e.jsx("span",{className:"w-1 h-4 bg-blue-500 rounded-full"}),e.jsx("span",{children:"基本信息"})]}),children:[e.jsx(a.Item,{label:"供应商名称",name:"name",rules:[{required:!0,message:"请输入供应商名称"}],children:e.jsx(i,{placeholder:"请输入供应商名称"})}),e.jsx(a.Item,{label:"联系人",name:"contact",rules:[{required:!0,message:"请输入联系人姓名"}],children:e.jsx(i,{placeholder:"请输入联系人姓名"})}),e.jsx(a.Item,{label:"联系电话",name:"phone",rules:[{required:!0,message:"请输入联系电话"}],children:e.jsx(i,{placeholder:"请输入联系电话"})}),e.jsx(a.Item,{label:"地址",name:"address",children:e.jsx(i.TextArea,{rows:3,placeholder:"请输入详细地址"})}),e.jsx(a.Item,{label:"状态",name:"status",rules:[{required:!0,message:"请选择状态"}],children:e.jsxs(d,{children:[e.jsx(d.Option,{value:"active",children:"启用"}),e.jsx(d.Option,{value:"inactive",children:"禁用"})]})}),e.jsx(a.Item,{label:"备注",name:"remark",children:e.jsx(i.TextArea,{rows:3,placeholder:"请输入备注信息"})})]})})})})};export{C as default};
//# sourceMappingURL=index-b415efab.js.map
