Browse Source

✨ feat(clients): 新增客户审核功能

- 添加审核状态筛选器,支持按待审核/已审核/已拒绝筛选客户
- 实现审核操作功能,包括通过和拒绝审核按钮
- 在客户列表中显示审核状态,并对未审核客户显示操作按钮
- 添加审核确认弹窗,防止误操作
- 更新查询参数,支持按审核状态筛选客户数据

🐛 fix(clients): 修复客户列表查询条件

- 修改查询参数结构,仅在审核状态筛选器有值时才添加auditStatus参数
- 确保筛选条件正确应用到API请求中
yourname 8 months ago
parent
commit
b142c36f72
1 changed files with 69 additions and 11 deletions
  1. 69 11
      src/client/admin/pages/Clients.tsx

+ 69 - 11
src/client/admin/pages/Clients.tsx

@@ -77,15 +77,19 @@ const Clients: React.FC = () => {
   
   // 获取客户列表数据
   const { data: clientsData, isLoading: clientsLoading, error: clientsError } = useQuery({
-    queryKey: ['clients', pagination.current, pagination.pageSize, searchText],
+    queryKey: ['clients', pagination.current, pagination.pageSize, searchText, auditStatusFilter],
     queryFn: async () => {
-      const res = await clientClient.$get({
-        query: {
-          page: pagination.current,
-          pageSize: pagination.pageSize,
-          keyword: searchText
-        }
-      });
+      const query: any = {
+        page: pagination.current,
+        pageSize: pagination.pageSize,
+        keyword: searchText
+      };
+      
+      if (auditStatusFilter !== undefined) {
+        query.auditStatus = auditStatusFilter;
+      }
+      
+      const res = await clientClient.$get({ query });
       if (!res.ok) {
         throw new Error('获取客户列表失败');
       }
@@ -250,6 +254,23 @@ const Clients: React.FC = () => {
       message.error('删除失败,请重试');
     }
   };
+
+  const handleAudit = (id: number, auditStatus: number) => {
+    const actionText = auditStatus === 1 ? '通过审核' : '拒绝审核';
+    Modal.confirm({
+      title: '确认审核',
+      content: `确定要${actionText}该客户吗?`,
+      okText: '确定',
+      cancelText: '取消',
+      onOk: async () => {
+        try {
+          await auditClient.mutateAsync({ id, auditStatus });
+        } catch (error) {
+          message.error('审核操作失败,请重试');
+        }
+      },
+    });
+  };
   
   // 表格列定义
   const columns = [
@@ -278,15 +299,40 @@ const Clients: React.FC = () => {
       title: '登记审核',
       dataIndex: 'auditStatus',
       key: 'auditStatus',
-      width: 100,
-      render: (status: number) => {
+      width: 150,
+      render: (status: number, record: ClientItem) => {
         const statusMap = {
           0: { text: '待审核', color: 'orange' },
           1: { text: '已审核', color: 'green' },
           2: { text: '已拒绝', color: 'red' }
         };
         const config = statusMap[status as keyof typeof statusMap] || { text: '-', color: 'default' };
-        return <span style={{ color: config.color }}>{config.text}</span>;
+        
+        return (
+          <div className="flex items-center space-x-2">
+            <span style={{ color: config.color }}>{config.text}</span>
+            {status === 0 && (
+              <Space size="small">
+                <Button
+                  size="small"
+                  type="primary"
+                  onClick={() => handleAudit(record.id, 1)}
+                  loading={auditClient.isPending}
+                >
+                  通过
+                </Button>
+                <Button
+                  size="small"
+                  danger
+                  onClick={() => handleAudit(record.id, 2)}
+                  loading={auditClient.isPending}
+                >
+                  拒绝
+                </Button>
+              </Space>
+            )}
+          </div>
+        );
       },
     },
     {
@@ -412,6 +458,17 @@ const Clients: React.FC = () => {
             className="max-w-md"
             allowClear
           />
+          <Select
+            placeholder="审核状态"
+            value={auditStatusFilter}
+            onChange={setAuditStatusFilter}
+            style={{ width: 120 }}
+            allowClear
+          >
+            <Select.Option value={0}>待审核</Select.Option>
+            <Select.Option value={1}>已审核</Select.Option>
+            <Select.Option value={2}>已拒绝</Select.Option>
+          </Select>
           <Button
             type="primary"
             onClick={handleSearch}
@@ -421,6 +478,7 @@ const Clients: React.FC = () => {
           </Button>
           <Button onClick={() => {
             setSearchText('');
+            setAuditStatusFilter(undefined);
             setPagination({ ...pagination, current: 1 });
           }}>
             重置