import{j as e,s as o}from"./index-3808da28.js";import{a6 as b,u as f,F as a,d as g,r as y,C as u,y as v,B as h,a7 as w,J as N,I as c,z as l,a8 as I}from"./vendor-61f0f29a.js";const{Title:k}=I,O=()=>{const{id:r}=b(),[x]=f(),d=r&&!x.get("edit"),[n]=a.useForm(),m=g(),p=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,level:s.attributes.level||"regular",status:s.attributes.status||"active",remark:s.attributes.remark})}catch(s){console.error("获取客户详情失败:",s)}};y.useEffect(()=>{r&&p()},[r]);const j=async s=>{try{const t={type:"customer",attributes:{name:s.name,contact:s.contact,phone:s.phone,address:s.address,level:s.level,status:s.status,remark:s.remark}};let i;if(r?i=await o.from("resources").update(t).eq("id",r).select():i=await o.from("resources").insert([t]).select(),i.error)throw i.error;m("/company/customer")}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(u,{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(k,{level:4,className:"mb-0 text-gray-800",children:r?"编辑客户":"新建客户"}),e.jsx("span",{className:"text-gray-400 text-sm",children:r?"请修改客户信息":"请填写客户信息"})]}),e.jsxs(v,{size:"middle",children:[e.jsx(h,{icon:e.jsx(w,{}),onClick:()=>m("/company/customer"),children:"返回"}),!d&&e.jsx(h,{type:"primary",icon:e.jsx(N,{}),onClick:()=>n.submit(),children:"保存"})]})]}),styles:{backgroundColor:"#fff"},children:e.jsx(a,{form:n,onFinish:j,layout:"vertical",initialValues:{status:"active",level:"regular"},className:"space-y-6",disabled:d,children:e.jsxs(u,{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(c,{placeholder:"请输入客户名称"})}),e.jsx(a.Item,{label:"联系人",name:"contact",rules:[{required:!0,message:"请输入联系人姓名"}],children:e.jsx(c,{placeholder:"请输入联系人姓名"})}),e.jsx(a.Item,{label:"联系电话",name:"phone",rules:[{required:!0,message:"请输入联系电话"}],children:e.jsx(c,{placeholder:"请输入联系电话"})}),e.jsx(a.Item,{label:"客户等级",name:"level",rules:[{required:!0,message:"请选择客户等级"}],children:e.jsxs(l,{children:[e.jsx(l.Option,{value:"vip",children:"VIP客户"}),e.jsx(l.Option,{value:"regular",children:"普通客户"}),e.jsx(l.Option,{value:"potential",children:"潜在客户"})]})}),e.jsx(a.Item,{label:"地址",name:"address",children:e.jsx(c.TextArea,{rows:3,placeholder:"请输入详细地址"})}),e.jsx(a.Item,{label:"状态",name:"status",rules:[{required:!0,message:"请选择状态"}],children:e.jsxs(l,{children:[e.jsx(l.Option,{value:"active",children:"启用"}),e.jsx(l.Option,{value:"inactive",children:"禁用"})]})}),e.jsx(a.Item,{label:"备注",name:"remark",children:e.jsx(c.TextArea,{rows:3,placeholder:"请输入备注信息"})})]})})})})};export{O as default};
//# sourceMappingURL=index-79bccede.js.map
