Files
manage/dist/assets/index-4a46251b.js
2024-12-23 21:06:40 +08:00

10 lines
16 KiB
JavaScript
Raw Blame History

import{j as e,s as g}from"./index-3808da28.js";import{a6 as Ae,u as Te,F as d,d as Fe,r as c,C as D,y as De,B as x,a7 as _e,J as Ee,I as p,z as v,ae as Oe,K as ne,E as Me,af as ce,V as $e,P as _,X as Ie,a8 as Re,m as j,l as Ye}from"./vendor-61f0f29a.js";import{v as u}from"./v4-82fce61c.js";const{TextArea:Le}=p,{Title:Pe,Text:Ve}=Re,ie={CNY:"¥",TWD:"NT$",USD:"$"},We=()=>{const{id:h}=Ae(),[P]=Te(),w=P.get("edit")==="true",E=P.get("templateId"),b=h&&!w,[o]=d.useForm(),V=Fe();c.useState([{id:Date.now()}]),c.useState(0);const[le,N]=c.useState(!1),[k,z]=c.useState("CNY"),[B,oe]=c.useState([]),[ze,de]=c.useState([]),[i,f]=c.useState({}),[me,C]=c.useState(!1),[U,ue]=c.useState([]),[O,M]=c.useState(null),[$,S]=c.useState(""),[q,Q]=c.useState(0),[A,W]=c.useState(0),I=c.useMemo(()=>(s,t)=>{const n=Number(s)||0,r=Number(t)||0;return n*r},[]),R=c.useMemo(()=>(s=[])=>Array.isArray(s)?s.reduce((t,n)=>n?t+I(n.quantity,n.price):t,0):0,[I]),T=c.useMemo(()=>(s=[])=>Array.isArray(s)?s.reduce((t,n)=>n?t+R(n.items):t,0):0,[R]),y=c.useMemo(()=>(s,t=k)=>{const n=Number(s)||0;return`${ie[t]||""}${n.toLocaleString("zh-CN",{minimumFractionDigits:2,maximumFractionDigits:2})}`},[k]),xe=(s,t)=>{console.log("Form values changed:",t),f(t),s.currency&&z(s.currency)},Y={currency:"CNY",sections:[{key:u(),sectionName:"服务类型 1",items:[{key:u(),productName:"",quantity:1,price:0,note:"",unit:""}]}]},he=()=>{C(!0),je()},pe=(s,t)=>{s({key:u(),productName:"",quantity:1,price:0,note:""})},ye=async()=>{try{N(!0);const{data:s,error:t}=await g.from("resources").select("*").eq("id",h).single();if(t)throw t;if(s!=null&&s.attributes){const n={quataName:s.attributes.quataName,customers:s.attributes.customers.map(r=>r.id)||[],description:s.attributes.description,currency:s.attributes.currency||"CNY",sections:s.attributes.sections.map(r=>({key:u(),sectionName:r.sectionName,items:r.items.map(a=>({key:u(),productName:a.name,quantity:Number(a.quantity)||0,price:Number(a.price)||0,note:a.description||"",unit:a.unit||""}))})),taxRate:s.attributes.taxRate||0,discount:s.attributes.discount||0};o.setFieldsValue(n),f(n),z(s.attributes.currency||"CNY"),Q(s.attributes.taxRate||0),W(s.attributes.discount||0),s.attributes.customers&&de(s.attributes.customers)}}catch(s){console.error("获取报价单详情失败:",s),j.error("获取报价单详情失败")}finally{N(!1)}},je=async()=>{try{const{data:s,error:t}=await g.from("resources").select("*").eq("type","sections").order("created_at",{ascending:!1});if(t)throw t;ue(s||[])}catch(s){j.error("获取小节模版失败"),console.error(s)}},Ne=s=>{const t=o.getFieldValue("sections")||[],n={key:u(),sectionName:s.attributes.name,items:(s.attributes.items||[]).map(l=>({key:u(),productName:l.name||"",note:l.description||"",price:l.price||0,quantity:l.quantity||1,unit:l.unit||""}))},r=[...t,n];o.setFieldValue("sections",r);const a=o.getFieldsValue();f({...a,sections:r}),C(!1),j.success("套用模版成功")},ge=()=>{const s=o.getFieldValue("sections")||[],t={key:u(),sectionName:`服务类型 ${s.length+1}`,items:[{key:u(),productName:"",note:"",price:0,quantity:1,unit:""}]};o.setFieldValue("sections",[...s,t]),C(!1)},be=()=>e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:U.map(s=>{var t;return e.jsxs("div",{className:`group relative bg-white dark:bg-gray-800 rounded-lg shadow-sm
border border-gray-200 dark:border-gray-700 hover:shadow-lg
transition-all duration-300 cursor-pointer`,onClick:()=>Ne(s),children:[e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"text-center mb-4",children:[e.jsx("h3",{className:`text-lg font-medium text-gray-900 dark:text-gray-100
group-hover:text-blue-500 transition-colors`,children:s.attributes.name}),e.jsxs("div",{className:"text-sm text-gray-500 dark:text-gray-400 mt-1",children:[((t=s.attributes.items)==null?void 0:t.length)||0," 个项目"]})]}),e.jsxs("div",{className:"space-y-2 mt-4 border-t dark:border-gray-700 pt-4",children:[(s.attributes.items||[]).slice(0,3).map((n,r)=>e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-300 truncate flex-1",children:n.name}),e.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400 ml-2",children:y(n.price)})]},r)),(s.attributes.items||[]).length>3&&e.jsxs("div",{className:"text-sm text-gray-500 dark:text-gray-400 text-center",children:["还有 ",s.attributes.items.length-3," 个项目..."]})]}),e.jsxs("div",{className:"mt-4 pt-4 border-t dark:border-gray-700 flex justify-between items-center",children:[e.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-300",children:"总金额"}),e.jsx("span",{className:"text-base font-medium text-blue-500",children:y((s.attributes.items||[]).reduce((n,r)=>n+(r.price*(r.quantity||1)||0),0))})]})]}),e.jsx("div",{className:`absolute inset-0 border-2 border-transparent
group-hover:border-blue-500 rounded-lg transition-colors duration-300`}),e.jsx("div",{className:`absolute top-3 right-3 opacity-0 group-hover:opacity-100
transition-opacity duration-300`,children:e.jsx(x,{type:"primary",size:"small",className:"flex items-center gap-1",icon:e.jsx(_,{}),children:"套用"})})]},s.id)})}),U.length===0&&e.jsx("div",{className:"text-center py-8",children:e.jsx("div",{className:"text-gray-500 dark:text-gray-400",children:"暂无可用模版"})}),e.jsx(Ye,{className:"dark:border-gray-700"}),e.jsx("div",{className:"flex justify-center",children:e.jsx(x,{type:"dashed",icon:e.jsx(_,{}),onClick:ge,className:`w-1/3 border-2 hover:border-blue-400 hover:text-blue-500
dark:border-gray-600 dark:text-gray-400 dark:hover:text-blue-400
transition-all duration-300`,children:"自定义小节"})})]}),fe=async()=>{try{N(!0);const{data:s,error:t}=await g.from("resources").select("*").eq("type","serviceTemplate").eq("id",E).single();if(t)throw t;if(s!=null&&s.attributes){const n={quataName:s.attributes.templateName,description:s.attributes.description,currency:"CNY",category:s.attributes.category,sections:s.attributes.sections.map(r=>({key:u(),sectionName:r.sectionName,items:r.items.map(a=>({key:u(),productName:a.name,quantity:a.quantity,price:a.price,note:a.description,unit:a.unit}))}))};o.setFieldsValue(n),f(n)}}catch(s){console.error("获取模板数据失败:",s),j.error("获取模板数据失败")}finally{N(!1)}},F=c.useMemo(()=>{const s=T(i==null?void 0:i.sections)||0,t=s*(q/100);return s+t},[i==null?void 0:i.sections,q,T]),ve=async s=>{try{N(!0);const t=T(s.sections),n={type:"quota",attributes:{quataName:s.quataName,customers:B.filter(a=>s.customers.includes(a.id)).map(a=>({id:a.id,name:a.attributes.name})),description:s.description,currency:k,sections:s.sections.map(a=>({sectionName:a.sectionName,items:a.items.map(l=>({name:l.productName,unit:l.unit,price:l.price,quantity:l.quantity,description:l.note}))})),beforeTaxAmount:t,taxRate:q,afterTaxAmount:F,discount:A,finalAmount:A||F}};let r;if(h?r=await g.from("resources").update(n).eq("id",h).select():r=await g.from("resources").insert([n]).select(),r.error)throw r.error;j.success("保存成功"),V("/company/quotation")}catch(t){console.error("保存失败:",t),j.error("保存失败")}finally{N(!1)}},we=async()=>{try{const{data:s,error:t}=await g.from("resources").select("*").eq("type","customer");if(t)throw t;oe(s||[])}catch(s){console.error("获取客户列表失败:",s)}};c.useEffect(()=>{we()},[]),c.useEffect(()=>{h?ye():E?fe():(o.setFieldsValue(Y),f(Y))},[h,E]);const ke=(s,t)=>{M(s),S(t||"")},J=()=>{if(!$.trim()){j.error("请输入小节名称");return}const t=[...o.getFieldValue("sections")];t[O]={...t[O],sectionName:$.trim()},o.setFieldValue("sections",t),M(null),S("")},Ce=()=>{M(null),S("")};return e.jsxs("div",{className:"bg-gradient-to-b from-gray-50 to-white min-h-screen p-6",children:[e.jsx(D,{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(Pe,{level:4,className:"mb-0 text-gray-800",children:h?w?"编辑报价单":"查看报价单":"新建报价单"}),e.jsx("span",{className:"text-gray-400 text-sm",children:h?w?"请修改报价单信息":"报价单详情":"请填写报价单信息"})]}),e.jsxs(De,{size:"middle",children:[e.jsx(x,{icon:e.jsx(_e,{}),onClick:()=>V("/company/quotation"),children:"返回"}),!b&&e.jsx(x,{type:"primary",icon:e.jsx(Ee,{}),onClick:()=>o.submit(),loading:le,children:"保存"})]})]}),children:e.jsxs(d,{form:o,onFinish:ve,onValuesChange:xe,layout:"vertical",disabled:b,initialValues:Y,children:[e.jsx(D,{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:"基本信息"})]}),bordered:!1,children:e.jsxs("div",{className:"grid grid-cols-2 gap-8",children:[e.jsx(d.Item,{name:"quataName",label:e.jsx("span",{className:"text-gray-700 font-medium",children:"活动名称"}),rules:[{required:!0,message:"活动名称"}],children:e.jsx(p,{placeholder:"请输入活动名",className:"rounded-md hover:border-blue-400 focus:border-blue-500"})}),e.jsx(d.Item,{name:"currency",label:e.jsx("span",{className:"text-gray-700 font-medium",children:"货币类型"}),rules:[{required:!0,message:"请选择货币类型"}],children:e.jsxs(v,{className:"w-full",children:[e.jsx(v.Option,{value:"CNY",children:"RMB"}),e.jsx(v.Option,{value:"TWD",children:"台币"}),e.jsx(v.Option,{value:"USD",children:"美元"})]})}),e.jsx(d.Item,{name:"customers",label:e.jsx("span",{className:"text-gray-700 font-medium",children:"客户名称"}),rules:[{required:!0,message:"请选择至少一个客户"}],children:e.jsx(v,{mode:"multiple",placeholder:"请选择客户",className:"rounded-md hover:border-blue-400 focus:border-blue-500",showSearch:!0,optionFilterProp:"children",filterOption:(s,t)=>((t==null?void 0:t.label)??"").toLowerCase().includes(s.toLowerCase()),options:B.map(s=>({value:s.id,label:s.attributes.name})),value:(i.customers||[]).map(s=>s.id)})})]})}),e.jsx(d.List,{name:"sections",children:(s,{add:t,remove:n})=>e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-4",children:s.map((r,a)=>e.jsx(D,{className:"shadow-sm rounded-lg",type:"inner",title:e.jsx("div",{className:"flex items-center justify-between",children:e.jsx("div",{className:"flex items-center gap-2",children:O===a?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(p,{value:$,onChange:l=>S(l.target.value),onPressEnter:J,autoFocus:!0,className:"w-48"}),e.jsx(x,{type:"link",icon:e.jsx(Oe,{}),onClick:J,className:"text-green-500 hover:text-green-600"}),e.jsx(x,{type:"link",icon:e.jsx(ne,{}),onClick:Ce,className:"text-red-500 hover:text-red-600"})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-1 h-4 bg-purple-500 rounded-full"}),e.jsx(Ve,{strong:!0,className:"text-lg dark:text-gray-200",children:o.getFieldValue(["sections",a,"sectionName"])||`服务类<EFBFBD><EFBFBD> ${a+1}`}),(!h||w)&&e.jsx(x,{type:"link",icon:e.jsx(Me,{}),onClick:()=>ke(a,o.getFieldValue(["sections",a,"sectionName"])||`服务类型 ${a+1}`),className:"text-gray-400 hover:text-blue-500"})]})})}),children:e.jsx(d.List,{name:[r.name,"items"],children:(l,{add:Se,remove:qe})=>{var K,X;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-[3fr_4fr_1fr_1fr_2fr_1fr_40px] gap-4 mb-2 text-gray-500 px-2",children:[e.jsx("div",{children:"项目明细"}),e.jsx("div",{children:"描述/备注"}),e.jsx("div",{children:"单位"}),e.jsx("div",{className:"text-center",children:"数量"}),e.jsx("div",{className:"text-center",children:"单价"}),e.jsx("div",{className:"text-right",children:"小计"}),e.jsx("div",{children:"操作"})]}),l.map((m,L)=>{var G,H,Z,ee,se,te,ae,re;return e.jsxs("div",{className:"grid grid-cols-[3fr_4fr_1fr_1fr_2fr_1fr_40px] gap-4 mb-4 items-start",children:[e.jsx(d.Item,{...m,name:[m.name,"productName"],className:"!mb-0",children:e.jsx(p,{placeholder:"服务项目名称"})}),e.jsx(d.Item,{...m,name:[m.name,"note"],className:"!mb-0",children:e.jsx(p,{placeholder:"请输入描述/备注"})}),e.jsx(d.Item,{...m,name:[m.name,"unit"],className:"!mb-0",children:e.jsx(p,{placeholder:"单位"})}),e.jsx(d.Item,{...m,name:[m.name,"quantity"],className:"!mb-0",children:e.jsx(ce,{placeholder:"数量",min:0,className:"w-full"})}),e.jsx(d.Item,{...m,name:[m.name,"price"],className:"!mb-0",children:e.jsx(ce,{placeholder:"单价",min:0,className:"w-full"})}),e.jsx("div",{className:"text-right",children:e.jsx("span",{className:"text-gray-500",children:y(I((ee=(Z=(H=(G=i==null?void 0:i.sections)==null?void 0:G[a])==null?void 0:H.items)==null?void 0:Z[L])==null?void 0:ee.quantity,(re=(ae=(te=(se=i==null?void 0:i.sections)==null?void 0:se[a])==null?void 0:te.items)==null?void 0:ae[L])==null?void 0:re.price))})}),!b&&e.jsx(x,{type:"text",danger:!0,icon:e.jsx($e,{}),onClick:()=>qe(m.name),className:"flex items-center justify-center"})]},`${a}-${L}`)}),!b&&e.jsx(x,{type:"dashed",onClick:()=>pe(Se),icon:e.jsx(_,{}),className:"w-full hover:border-blue-400 hover:text-blue-500 mb-4",children:"添加服务项目"}),e.jsx("div",{className:"flex justify-end border-t pt-4",children:e.jsxs("span",{className:"text-gray-500",children:["小计总额:",e.jsx("span",{className:"text-blue-500 font-medium ml-2",children:y(R((X=(K=i==null?void 0:i.sections)==null?void 0:K[a])==null?void 0:X.items))})]})})]})}})},`section-${r.key}`))}),!b&&e.jsx("div",{className:"mt-6 flex justify-center",children:e.jsx(x,{type:"dashed",onClick:he,icon:e.jsx(_,{}),className:"w-1/3 border-2 hover:border-blue-400 hover:text-blue-500",children:"新建小节"})}),e.jsxs("div",{className:"mt-6 space-y-4 pt-4 border-t",children:[e.jsxs("div",{className:"flex justify-end items-center space-x-4",children:[e.jsx("span",{className:"text-gray-600 font-medium",children:"税前总计:"}),e.jsx("span",{className:"text-2xl font-semibold text-blue-600",children:y(T(i==null?void 0:i.sections))})]}),e.jsxs("div",{className:"flex justify-end items-center space-x-4",children:[e.jsx("span",{className:"text-gray-600",children:"税率:"}),e.jsx("div",{style:{width:"150px"},children:e.jsx(p,{value:q,suffix:"%",onChange:r=>{const a=r.target.value.replace(/[^\d]/g,"");Q(Number(a)||0)}})})]}),e.jsxs("div",{className:"flex justify-end items-center space-x-4",children:[e.jsx("span",{className:"text-gray-600 font-medium",children:"税后总计:"}),e.jsx("span",{className:"text-xl font-semibold text-blue-600",children:y(F)})]}),e.jsxs("div",{className:"flex justify-end items-center space-x-4",children:[e.jsx("span",{className:"text-gray-600",children:"折扣价:"}),e.jsx("div",{style:{width:"150px"},children:e.jsx(p,{value:A,prefix:ie[k],onChange:r=>{const a=r.target.value.replace(/[^\d]/g,"");W(Number(a)||0)}})})]}),e.jsxs("div",{className:"flex justify-end items-center space-x-4",children:[e.jsx("span",{className:"text-gray-600 font-medium",children:"最终金额:"}),e.jsx("span",{className:"text-2xl font-semibold text-blue-600",children:y(A||F)})]})]}),e.jsx(D,{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-purple-500 rounded-full"}),e.jsx("span",{children:"补充说明"})]}),bordered:!1,children:e.jsx(d.Item,{name:"description",className:"mb-0",children:e.jsx(Le,{rows:4,placeholder:"请输入补充说明信息",className:"rounded-md hover:border-purple-400 focus:border-purple-500"})})})]})})]})}),e.jsx(Ie,{title:e.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-gray-100",children:"选择小节模版"}),open:me,onCancel:()=>C(!1),footer:null,width:800,className:"dark:bg-gray-800",closeIcon:e.jsx(ne,{className:"text-gray-500 dark:text-gray-400"}),children:be()})]})};export{We as default};
//# sourceMappingURL=index-4a46251b.js.map