|
|
@@ -1,5 +1,6 @@
|
|
|
import React, { useState } from 'react';
|
|
|
import { Table, Button, Space, Input, Modal, Form, Select, DatePicker, InputNumber } from 'antd';
|
|
|
+import ClientSelect from '@/client/admin/components/ClientSelect';
|
|
|
import { App } from 'antd';
|
|
|
import { PlusOutlined, EditOutlined, DeleteOutlined, SearchOutlined, FileTextOutlined } from '@ant-design/icons';
|
|
|
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
|
|
@@ -18,7 +19,10 @@ const Contracts: React.FC = () => {
|
|
|
const [modalVisible, setModalVisible] = useState(false);
|
|
|
const [editingKey, setEditingKey] = useState<string | null>(null);
|
|
|
const [searchText, setSearchText] = useState('');
|
|
|
- const [clients, setClients] = useState<ClientItem[]>([]);
|
|
|
+ const [pagination, setPagination] = useState({
|
|
|
+ current: 1,
|
|
|
+ pageSize: 10,
|
|
|
+ });
|
|
|
const queryClient = useQueryClient();
|
|
|
|
|
|
// 获取客户列表
|
|
|
@@ -28,17 +32,7 @@ const Contracts: React.FC = () => {
|
|
|
const response = await clientClient.$get({ query: { page: 1, pageSize: 1000 } });
|
|
|
if (response.status !== 200) throw new Error('Failed to fetch clients');
|
|
|
return response.json() as Promise<InferResponseType<typeof clientClient.$get, 200>>;
|
|
|
- },
|
|
|
- onSuccess: (result) => {
|
|
|
- setClients(result.data);
|
|
|
- },
|
|
|
- });
|
|
|
-
|
|
|
- const [dataSource, setDataSource] = useState<HetongItem[]>([]);
|
|
|
- const [pagination, setPagination] = useState({
|
|
|
- current: 1,
|
|
|
- pageSize: 10,
|
|
|
- total: 0,
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
// 获取合同列表数据
|
|
|
@@ -48,16 +42,9 @@ const Contracts: React.FC = () => {
|
|
|
return response.json() as Promise<HetongListResponse>;
|
|
|
};
|
|
|
|
|
|
- const { data, isLoading: loading, refetch } = useQuery({
|
|
|
+ const { data: contractsData, isLoading: loading, refetch } = useQuery({
|
|
|
queryKey: ['contracts', pagination.current, pagination.pageSize, searchText],
|
|
|
- queryFn: () => fetchContracts({ page: pagination.current, pageSize: pagination.pageSize }),
|
|
|
- onSuccess: (result: HetongListResponse) => {
|
|
|
- setDataSource(result.data);
|
|
|
- setPagination(prev => ({
|
|
|
- ...prev,
|
|
|
- total: result.pagination.total,
|
|
|
- }));
|
|
|
- },
|
|
|
+ queryFn: () => fetchContracts({ page: pagination.current, pageSize: pagination.pageSize })
|
|
|
});
|
|
|
|
|
|
// 搜索
|
|
|
@@ -69,7 +56,6 @@ const Contracts: React.FC = () => {
|
|
|
// 分页变化
|
|
|
const handleTableChange = (pagination: any) => {
|
|
|
setPagination(pagination);
|
|
|
- refetch();
|
|
|
};
|
|
|
|
|
|
// 显示添加/编辑弹窗
|
|
|
@@ -196,7 +182,7 @@ const Contracts: React.FC = () => {
|
|
|
dataIndex: 'clientId',
|
|
|
key: 'clientId',
|
|
|
render: (clientId: string) => {
|
|
|
- const client = clients.find(c => c.id.toString() === clientId);
|
|
|
+ const client = clientsData?.data.find(c => c.id.toString() === clientId);
|
|
|
return client ? client.companyName : '-';
|
|
|
},
|
|
|
},
|
|
|
@@ -277,10 +263,16 @@ const Contracts: React.FC = () => {
|
|
|
|
|
|
<Table
|
|
|
columns={columns}
|
|
|
- dataSource={dataSource}
|
|
|
+ dataSource={contractsData?.data || []}
|
|
|
rowKey="id"
|
|
|
loading={loading}
|
|
|
- pagination={pagination}
|
|
|
+ pagination={{
|
|
|
+ ...pagination,
|
|
|
+ total: contractsData?.pagination.total || 0,
|
|
|
+ showSizeChanger: true,
|
|
|
+ showQuickJumper: true,
|
|
|
+ showTotal: (total) => `共 ${total} 条记录`
|
|
|
+ }}
|
|
|
onChange={handleTableChange}
|
|
|
bordered
|
|
|
/>
|
|
|
@@ -334,13 +326,7 @@ const Contracts: React.FC = () => {
|
|
|
label="客户"
|
|
|
rules={[{ required: true, message: '请选择客户' }]}
|
|
|
>
|
|
|
- <Select placeholder="请选择客户">
|
|
|
- {clients.map(client => (
|
|
|
- <Select.Option key={client.id} value={client.id.toString()}>
|
|
|
- {client.companyName}
|
|
|
- </Select.Option>
|
|
|
- ))}
|
|
|
- </Select>
|
|
|
+ <ClientSelect />
|
|
|
</Form.Item>
|
|
|
|
|
|
<Form.Item
|