ClientDetailModal.tsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import React, { useState } from 'react';
  2. import { Modal, Tabs } from 'antd';
  3. import { App } from 'antd';
  4. import ClientInfoTab from './client-detail/ClientInfoTab';
  5. import ContactsTab from './client-detail/ContactsTab';
  6. import ContractsTab from './client-detail/ContractsTab';
  7. import ExpensesTab from './client-detail/ExpensesTab';
  8. import FilesTab from './client-detail/FilesTab';
  9. import LogsTab from './client-detail/LogsTab';
  10. import { useQuery } from '@tanstack/react-query';
  11. import { clientClient } from '@/client/api';
  12. import type { InferResponseType } from 'hono/client';
  13. const { TabPane } = Tabs;
  14. interface ClientDetailModalProps {
  15. clientId: number | null;
  16. visible: boolean;
  17. onClose: () => void;
  18. }
  19. const ClientDetailModal: React.FC<ClientDetailModalProps> = ({ clientId, visible, onClose }) => {
  20. const { message } = App.useApp();
  21. const [activeTab, setActiveTab] = useState('info');
  22. // 获取客户基本信息用于标题
  23. const { data: clientDetail } = useQuery({
  24. queryKey: ['client', clientId],
  25. queryFn: async () => {
  26. if (!clientId) return null;
  27. const res = await clientClient[':id'].$get({ param: { id: clientId } });
  28. if (!res.ok) throw new Error('获取客户详情失败');
  29. return res.json();
  30. },
  31. enabled: !!clientId,
  32. });
  33. const clientName = clientDetail?.companyName || '客户详情';
  34. return (
  35. <Modal
  36. title={`${clientName} - 详情`}
  37. open={visible}
  38. onCancel={onClose}
  39. footer={null}
  40. width={1000}
  41. className="client-detail-modal"
  42. destroyOnClose
  43. >
  44. <Tabs
  45. activeKey={activeTab}
  46. onChange={setActiveTab}
  47. tabPosition="top"
  48. items={[
  49. {
  50. key: 'info',
  51. label: '客户档案',
  52. children: clientId ? <ClientInfoTab clientId={clientId} /> : null,
  53. },
  54. {
  55. key: 'contacts',
  56. label: '相关联系人',
  57. children: clientId ? <ContactsTab clientId={clientId} /> : null,
  58. },
  59. {
  60. key: 'contracts',
  61. label: '合同记录',
  62. children: clientId ? <ContractsTab clientId={clientId} /> : null,
  63. },
  64. {
  65. key: 'expenses',
  66. label: '费用记录',
  67. children: clientId ? <ExpensesTab clientId={clientId} /> : null,
  68. },
  69. {
  70. key: 'files',
  71. label: '文件记录',
  72. children: clientId ? <FilesTab clientId={clientId} /> : null,
  73. },
  74. {
  75. key: 'logs',
  76. label: '操作记录',
  77. children: clientId ? <LogsTab clientId={clientId} /> : null,
  78. },
  79. ]}
  80. />
  81. </Modal>
  82. );
  83. };
  84. export default ClientDetailModal;