|
|
@@ -0,0 +1,892 @@
|
|
|
+import React, { useState } from 'react';
|
|
|
+import { useQuery, useMutation } from '@tanstack/react-query';
|
|
|
+import { Plus, Edit, Trash2, Search, Eye } from 'lucide-react';
|
|
|
+import { format } from 'date-fns';
|
|
|
+import { Input } from '@d8d/shared-ui-components/components/ui/input';
|
|
|
+import { Button } from '@d8d/shared-ui-components/components/ui/button';
|
|
|
+import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@d8d/shared-ui-components/components/ui/card';
|
|
|
+import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@d8d/shared-ui-components/components/ui/table';
|
|
|
+import { Skeleton } from '@d8d/shared-ui-components/components/ui/skeleton';
|
|
|
+import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@d8d/shared-ui-components/components/ui/dialog';
|
|
|
+import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@d8d/shared-ui-components/components/ui/form';
|
|
|
+import { useForm } from 'react-hook-form';
|
|
|
+import { zodResolver } from '@hookform/resolvers/zod';
|
|
|
+import { toast } from 'sonner';
|
|
|
+import { DataTablePagination } from '@d8d/shared-ui-components/components/admin/DataTablePagination';
|
|
|
+import { disabilityClientManager } from '../api/disabilityClient';
|
|
|
+import { CreateDisabledPersonSchema, UpdateDisabledPersonSchema } from '@d8d/allin-disability-module/schemas';
|
|
|
+import type { CreateDisabledPersonRequest, UpdateDisabledPersonRequest } from '../api/disabilityClient';
|
|
|
+import { DISABILITY_TYPES, getDisabilityTypeLabel } from '@d8d/allin-enums';
|
|
|
+import { DISABILITY_LEVELS, getDisabilityLevelLabel } from '@d8d/allin-enums';
|
|
|
+import { AreaSelect } from '@d8d/area-management-ui/components';
|
|
|
+import { FileSelector } from '@d8d/file-management-ui/components';
|
|
|
+
|
|
|
+interface DisabilityPersonSearchParams {
|
|
|
+ page: number;
|
|
|
+ limit: number;
|
|
|
+ search: string;
|
|
|
+}
|
|
|
+
|
|
|
+const DisabilityPersonManagement: React.FC = () => {
|
|
|
+ const [searchParams, setSearchParams] = useState<DisabilityPersonSearchParams>({ page: 1, limit: 10, search: '' });
|
|
|
+ const [isModalOpen, setIsModalOpen] = useState(false);
|
|
|
+ const [isCreateForm, setIsCreateForm] = useState(true);
|
|
|
+ const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
|
|
|
+ const [personToDelete, setPersonToDelete] = useState<number | null>(null);
|
|
|
+ const [viewDialogOpen, setViewDialogOpen] = useState(false);
|
|
|
+ const [personToView, setPersonToView] = useState<number | null>(null);
|
|
|
+
|
|
|
+ // 表单实例 - 创建表单
|
|
|
+ const createForm = useForm<CreateDisabledPersonRequest>({
|
|
|
+ resolver: zodResolver(CreateDisabledPersonSchema),
|
|
|
+ defaultValues: {
|
|
|
+ name: '',
|
|
|
+ gender: '男',
|
|
|
+ idCard: '',
|
|
|
+ disabilityId: '',
|
|
|
+ disabilityType: '',
|
|
|
+ disabilityLevel: '',
|
|
|
+ idAddress: '',
|
|
|
+ phone: '',
|
|
|
+ province: '',
|
|
|
+ city: '',
|
|
|
+ district: '',
|
|
|
+ detailedAddress: '',
|
|
|
+ nation: '',
|
|
|
+ isMarried: 0,
|
|
|
+ canDirectContact: 0,
|
|
|
+ isInBlackList: 0,
|
|
|
+ jobStatus: 0
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 表单实例 - 更新表单
|
|
|
+ const updateForm = useForm<UpdateDisabledPersonRequest>({
|
|
|
+ resolver: zodResolver(UpdateDisabledPersonSchema),
|
|
|
+ defaultValues: {}
|
|
|
+ });
|
|
|
+
|
|
|
+ // 数据查询
|
|
|
+ const { data, isLoading, refetch } = useQuery({
|
|
|
+ queryKey: ['disabled-persons', searchParams],
|
|
|
+ queryFn: async () => {
|
|
|
+ const res = await disabilityClientManager.get().getAllDisabledPersons.$get({
|
|
|
+ query: {
|
|
|
+ skip: (searchParams.page - 1) * searchParams.limit,
|
|
|
+ take: searchParams.limit
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (res.status !== 200) throw new Error('获取残疾人列表失败');
|
|
|
+ return await res.json();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 查看详情查询
|
|
|
+ const { data: viewData } = useQuery({
|
|
|
+ queryKey: ['disabled-person-detail', personToView],
|
|
|
+ queryFn: async () => {
|
|
|
+ if (!personToView) return null;
|
|
|
+ const res = await disabilityClientManager.get().getDisabledPerson[':id'].$get({
|
|
|
+ param: { id: personToView }
|
|
|
+ });
|
|
|
+ if (res.status !== 200) throw new Error('获取残疾人详情失败');
|
|
|
+ return await res.json();
|
|
|
+ },
|
|
|
+ enabled: !!personToView && viewDialogOpen
|
|
|
+ });
|
|
|
+
|
|
|
+ // 创建残疾人
|
|
|
+ const createMutation = useMutation({
|
|
|
+ mutationFn: async (data: CreateDisabledPersonRequest) => {
|
|
|
+ const res = await disabilityClientManager.get().createDisabledPerson.$post({ json: data });
|
|
|
+ if (res.status !== 200) throw new Error('创建残疾人失败');
|
|
|
+ return await res.json();
|
|
|
+ },
|
|
|
+ onSuccess: () => {
|
|
|
+ toast.success('残疾人创建成功');
|
|
|
+ setIsModalOpen(false);
|
|
|
+ createForm.reset();
|
|
|
+ refetch();
|
|
|
+ },
|
|
|
+ onError: (error) => {
|
|
|
+ toast.error(error instanceof Error ? error.message : '创建残疾人失败');
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 更新残疾人
|
|
|
+ const updateMutation = useMutation({
|
|
|
+ mutationFn: async (data: UpdateDisabledPersonRequest) => {
|
|
|
+ const res = await disabilityClientManager.get().updateDisabledPerson.$post({
|
|
|
+ json: data
|
|
|
+ });
|
|
|
+ if (res.status !== 200) throw new Error('更新残疾人失败');
|
|
|
+ return await res.json();
|
|
|
+ },
|
|
|
+ onSuccess: () => {
|
|
|
+ toast.success('残疾人更新成功');
|
|
|
+ setIsModalOpen(false);
|
|
|
+ refetch();
|
|
|
+ },
|
|
|
+ onError: (error) => {
|
|
|
+ toast.error(error instanceof Error ? error.message : '更新残疾人失败');
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 删除残疾人
|
|
|
+ const deleteMutation = useMutation({
|
|
|
+ mutationFn: async (id: number) => {
|
|
|
+ const res = await disabilityClientManager.get().deleteDisabledPerson.$post({
|
|
|
+ json: { id }
|
|
|
+ });
|
|
|
+ if (res.status !== 200) throw new Error('删除残疾人失败');
|
|
|
+ return await res.json();
|
|
|
+ },
|
|
|
+ onSuccess: () => {
|
|
|
+ toast.success('残疾人删除成功');
|
|
|
+ setDeleteDialogOpen(false);
|
|
|
+ refetch();
|
|
|
+ },
|
|
|
+ onError: (error) => {
|
|
|
+ toast.error(error instanceof Error ? error.message : '删除残疾人失败');
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 处理搜索
|
|
|
+ const handleSearch = (e: React.FormEvent) => {
|
|
|
+ e.preventDefault();
|
|
|
+ refetch();
|
|
|
+ };
|
|
|
+
|
|
|
+ // 打开创建模态框
|
|
|
+ const handleCreateOpen = () => {
|
|
|
+ setIsCreateForm(true);
|
|
|
+ createForm.reset();
|
|
|
+ setIsModalOpen(true);
|
|
|
+ };
|
|
|
+
|
|
|
+ // 打开编辑模态框
|
|
|
+ const handleEditOpen = (person: any) => {
|
|
|
+ setIsCreateForm(false);
|
|
|
+ updateForm.reset(person);
|
|
|
+ setIsModalOpen(true);
|
|
|
+ };
|
|
|
+
|
|
|
+ // 打开查看模态框
|
|
|
+ const handleViewOpen = (id: number) => {
|
|
|
+ setPersonToView(id);
|
|
|
+ setViewDialogOpen(true);
|
|
|
+ };
|
|
|
+
|
|
|
+ // 打开删除确认对话框
|
|
|
+ const handleDeleteOpen = (id: number) => {
|
|
|
+ setPersonToDelete(id);
|
|
|
+ setDeleteDialogOpen(true);
|
|
|
+ };
|
|
|
+
|
|
|
+ // 提交创建表单
|
|
|
+ const onSubmitCreate = (data: CreateDisabledPersonRequest) => {
|
|
|
+ createMutation.mutate(data);
|
|
|
+ };
|
|
|
+
|
|
|
+ // 提交更新表单
|
|
|
+ const onSubmitUpdate = (data: UpdateDisabledPersonRequest) => {
|
|
|
+ updateMutation.mutate(data);
|
|
|
+ };
|
|
|
+
|
|
|
+ // 确认删除
|
|
|
+ const confirmDelete = () => {
|
|
|
+ if (personToDelete) {
|
|
|
+ deleteMutation.mutate(personToDelete);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ return (
|
|
|
+ <div className="space-y-6">
|
|
|
+ <Card>
|
|
|
+ <CardHeader>
|
|
|
+ <CardTitle>残疾人个人管理</CardTitle>
|
|
|
+ <CardDescription>管理残疾人个人信息,包括创建、编辑、查看和删除操作</CardDescription>
|
|
|
+ </CardHeader>
|
|
|
+ <CardContent>
|
|
|
+ <div className="flex items-center justify-between mb-6">
|
|
|
+ <form onSubmit={handleSearch} className="flex items-center space-x-2">
|
|
|
+ <Input
|
|
|
+ placeholder="搜索姓名或身份证号"
|
|
|
+ value={searchParams.search}
|
|
|
+ onChange={(e) => setSearchParams({ ...searchParams, search: e.target.value })}
|
|
|
+ className="w-64"
|
|
|
+ />
|
|
|
+ <Button type="submit" size="sm">
|
|
|
+ <Search className="h-4 w-4 mr-2" />
|
|
|
+ 搜索
|
|
|
+ </Button>
|
|
|
+ </form>
|
|
|
+ <Button onClick={handleCreateOpen} data-testid="add-disabled-person-button">
|
|
|
+ <Plus className="h-4 w-4 mr-2" />
|
|
|
+ 新增残疾人
|
|
|
+ </Button>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {isLoading ? (
|
|
|
+ <div className="space-y-2">
|
|
|
+ {Array.from({ length: 5 }).map((_, i) => (
|
|
|
+ <Skeleton key={i} className="h-12 w-full" />
|
|
|
+ ))}
|
|
|
+ </div>
|
|
|
+ ) : (
|
|
|
+ <>
|
|
|
+ <Table>
|
|
|
+ <TableHeader>
|
|
|
+ <TableRow>
|
|
|
+ <TableHead>姓名</TableHead>
|
|
|
+ <TableHead>性别</TableHead>
|
|
|
+ <TableHead>身份证号</TableHead>
|
|
|
+ <TableHead>残疾证号</TableHead>
|
|
|
+ <TableHead>残疾类型</TableHead>
|
|
|
+ <TableHead>残疾等级</TableHead>
|
|
|
+ <TableHead>联系电话</TableHead>
|
|
|
+ <TableHead>创建时间</TableHead>
|
|
|
+ <TableHead className="text-right">操作</TableHead>
|
|
|
+ </TableRow>
|
|
|
+ </TableHeader>
|
|
|
+ <TableBody>
|
|
|
+ {data?.data?.map((person: any) => (
|
|
|
+ <TableRow key={person.id}>
|
|
|
+ <TableCell>{person.name}</TableCell>
|
|
|
+ <TableCell>{person.gender}</TableCell>
|
|
|
+ <TableCell>{person.idCard}</TableCell>
|
|
|
+ <TableCell>{person.disabilityId}</TableCell>
|
|
|
+ <TableCell>{person.disabilityType}</TableCell>
|
|
|
+ <TableCell>{person.disabilityLevel}</TableCell>
|
|
|
+ <TableCell>{person.phone}</TableCell>
|
|
|
+ <TableCell>{format(new Date(person.createTime), 'yyyy-MM-dd HH:mm')}</TableCell>
|
|
|
+ <TableCell className="text-right">
|
|
|
+ <div className="flex justify-end space-x-2">
|
|
|
+ <Button
|
|
|
+ variant="ghost"
|
|
|
+ size="sm"
|
|
|
+ onClick={() => handleViewOpen(person.id)}
|
|
|
+ data-testid={`view-person-${person.id}`}
|
|
|
+ >
|
|
|
+ <Eye className="h-4 w-4" />
|
|
|
+ </Button>
|
|
|
+ <Button
|
|
|
+ variant="ghost"
|
|
|
+ size="sm"
|
|
|
+ onClick={() => handleEditOpen(person)}
|
|
|
+ data-testid={`edit-person-${person.id}`}
|
|
|
+ >
|
|
|
+ <Edit className="h-4 w-4" />
|
|
|
+ </Button>
|
|
|
+ <Button
|
|
|
+ variant="ghost"
|
|
|
+ size="sm"
|
|
|
+ onClick={() => handleDeleteOpen(person.id)}
|
|
|
+ data-testid={`delete-person-${person.id}`}
|
|
|
+ >
|
|
|
+ <Trash2 className="h-4 w-4" />
|
|
|
+ </Button>
|
|
|
+ </div>
|
|
|
+ </TableCell>
|
|
|
+ </TableRow>
|
|
|
+ ))}
|
|
|
+ </TableBody>
|
|
|
+ </Table>
|
|
|
+
|
|
|
+ {data && (
|
|
|
+ <div className="mt-4">
|
|
|
+ <DataTablePagination
|
|
|
+ currentPage={searchParams.page}
|
|
|
+ pageSize={searchParams.limit}
|
|
|
+ totalCount={data.total}
|
|
|
+ onPageChange={(page, pageSize) => setSearchParams({ ...searchParams, page, limit: pageSize })}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
+ </>
|
|
|
+ )}
|
|
|
+ </CardContent>
|
|
|
+ </Card>
|
|
|
+
|
|
|
+ {/* 创建/编辑模态框 */}
|
|
|
+ <Dialog open={isModalOpen} onOpenChange={setIsModalOpen}>
|
|
|
+ <DialogContent className="max-w-4xl max-h-[90vh] overflow-y-auto">
|
|
|
+ <DialogHeader>
|
|
|
+ <DialogTitle data-testid={isCreateForm ? 'create-disabled-person-dialog-title' : 'edit-disabled-person-dialog-title'}>
|
|
|
+ {isCreateForm ? '新增残疾人' : '编辑残疾人信息'}
|
|
|
+ </DialogTitle>
|
|
|
+ <DialogDescription>
|
|
|
+ {isCreateForm ? '填写残疾人基本信息,带*的为必填项' : '修改残疾人信息'}
|
|
|
+ </DialogDescription>
|
|
|
+ </DialogHeader>
|
|
|
+
|
|
|
+ {isCreateForm ? (
|
|
|
+ <Form {...createForm}>
|
|
|
+ <form onSubmit={createForm.handleSubmit(onSubmitCreate, (errors) => console.debug('创建表单验证错误:', errors))} className="space-y-4">
|
|
|
+ <div className="grid grid-cols-2 gap-4">
|
|
|
+ <FormField
|
|
|
+ control={createForm.control}
|
|
|
+ name="name"
|
|
|
+ render={({ field }) => (
|
|
|
+ <FormItem>
|
|
|
+ <FormLabel>姓名 *</FormLabel>
|
|
|
+ <FormControl>
|
|
|
+ <Input placeholder="请输入姓名" {...field} />
|
|
|
+ </FormControl>
|
|
|
+ <FormMessage />
|
|
|
+ </FormItem>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+
|
|
|
+ <FormField
|
|
|
+ control={createForm.control}
|
|
|
+ name="gender"
|
|
|
+ render={({ field }) => (
|
|
|
+ <FormItem>
|
|
|
+ <FormLabel>性别 *</FormLabel>
|
|
|
+ <FormControl>
|
|
|
+ <select
|
|
|
+ className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
|
|
|
+ data-testid="gender-select"
|
|
|
+ {...field}
|
|
|
+ >
|
|
|
+ <option value="男">男</option>
|
|
|
+ <option value="女">女</option>
|
|
|
+ </select>
|
|
|
+ </FormControl>
|
|
|
+ <FormMessage />
|
|
|
+ </FormItem>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+
|
|
|
+ <FormField
|
|
|
+ control={createForm.control}
|
|
|
+ name="idCard"
|
|
|
+ render={({ field }) => (
|
|
|
+ <FormItem>
|
|
|
+ <FormLabel>身份证号 *</FormLabel>
|
|
|
+ <FormControl>
|
|
|
+ <Input placeholder="请输入身份证号" {...field} />
|
|
|
+ </FormControl>
|
|
|
+ <FormMessage />
|
|
|
+ </FormItem>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+
|
|
|
+ <FormField
|
|
|
+ control={createForm.control}
|
|
|
+ name="disabilityId"
|
|
|
+ render={({ field }) => (
|
|
|
+ <FormItem>
|
|
|
+ <FormLabel>残疾证号 *</FormLabel>
|
|
|
+ <FormControl>
|
|
|
+ <Input placeholder="请输入残疾证号" {...field} />
|
|
|
+ </FormControl>
|
|
|
+ <FormMessage />
|
|
|
+ </FormItem>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+
|
|
|
+ <FormField
|
|
|
+ control={createForm.control}
|
|
|
+ name="disabilityType"
|
|
|
+ render={({ field }) => (
|
|
|
+ <FormItem>
|
|
|
+ <FormLabel>残疾类型 *</FormLabel>
|
|
|
+ <FormControl>
|
|
|
+ <select
|
|
|
+ className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
|
|
|
+ data-testid="disability-type-select"
|
|
|
+ {...field}
|
|
|
+ >
|
|
|
+ <option value="">请选择残疾类型</option>
|
|
|
+ {DISABILITY_TYPES.map((type) => (
|
|
|
+ <option key={type} value={getDisabilityTypeLabel(type)}>
|
|
|
+ {getDisabilityTypeLabel(type)}
|
|
|
+ </option>
|
|
|
+ ))}
|
|
|
+ </select>
|
|
|
+ </FormControl>
|
|
|
+ <FormMessage />
|
|
|
+ </FormItem>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+
|
|
|
+ <FormField
|
|
|
+ control={createForm.control}
|
|
|
+ name="disabilityLevel"
|
|
|
+ render={({ field }) => (
|
|
|
+ <FormItem>
|
|
|
+ <FormLabel>残疾等级 *</FormLabel>
|
|
|
+ <FormControl>
|
|
|
+ <select
|
|
|
+ className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
|
|
|
+ data-testid="disability-level-select"
|
|
|
+ {...field}
|
|
|
+ >
|
|
|
+ <option value="">请选择残疾等级</option>
|
|
|
+ {DISABILITY_LEVELS.map((level) => (
|
|
|
+ <option key={level} value={getDisabilityLevelLabel(level)}>
|
|
|
+ {getDisabilityLevelLabel(level)}
|
|
|
+ </option>
|
|
|
+ ))}
|
|
|
+ </select>
|
|
|
+ </FormControl>
|
|
|
+ <FormMessage />
|
|
|
+ </FormItem>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+
|
|
|
+ <FormField
|
|
|
+ control={createForm.control}
|
|
|
+ name="phone"
|
|
|
+ render={({ field }) => (
|
|
|
+ <FormItem>
|
|
|
+ <FormLabel>联系电话 *</FormLabel>
|
|
|
+ <FormControl>
|
|
|
+ <Input placeholder="请输入联系电话" {...field} />
|
|
|
+ </FormControl>
|
|
|
+ <FormMessage />
|
|
|
+ </FormItem>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+
|
|
|
+ <FormField
|
|
|
+ control={createForm.control}
|
|
|
+ name="idAddress"
|
|
|
+ render={({ field }) => (
|
|
|
+ <FormItem className="col-span-2">
|
|
|
+ <FormLabel>身份证地址 *</FormLabel>
|
|
|
+ <FormControl>
|
|
|
+ <Input placeholder="请输入身份证地址" {...field} />
|
|
|
+ </FormControl>
|
|
|
+ <FormMessage />
|
|
|
+ </FormItem>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+
|
|
|
+ <div className="col-span-2">
|
|
|
+ <FormLabel>居住地址 *</FormLabel>
|
|
|
+ <div className="space-y-4">
|
|
|
+ <AreaSelect
|
|
|
+ value={{
|
|
|
+ provinceId: createForm.watch('province') ? Number(createForm.watch('province')) : undefined,
|
|
|
+ cityId: createForm.watch('city') ? Number(createForm.watch('city')) : undefined,
|
|
|
+ districtId: createForm.watch('district') ? Number(createForm.watch('district')) : undefined
|
|
|
+ }}
|
|
|
+ onChange={(value) => {
|
|
|
+ createForm.setValue('province', value.provinceId?.toString() || '');
|
|
|
+ createForm.setValue('city', value.cityId?.toString() || '');
|
|
|
+ createForm.setValue('district', value.districtId?.toString() || '');
|
|
|
+ }}
|
|
|
+ />
|
|
|
+
|
|
|
+ <FormField
|
|
|
+ control={createForm.control}
|
|
|
+ name="detailedAddress"
|
|
|
+ render={({ field }) => (
|
|
|
+ <FormItem>
|
|
|
+ <FormControl>
|
|
|
+ <Input placeholder="详细地址(街道、门牌号等)" {...field} />
|
|
|
+ </FormControl>
|
|
|
+ <FormMessage />
|
|
|
+ </FormItem>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <FormField
|
|
|
+ control={createForm.control}
|
|
|
+ name="nation"
|
|
|
+ render={({ field }) => (
|
|
|
+ <FormItem>
|
|
|
+ <FormLabel>民族</FormLabel>
|
|
|
+ <FormControl>
|
|
|
+ <Input placeholder="请输入民族" {...field} />
|
|
|
+ </FormControl>
|
|
|
+ <FormMessage />
|
|
|
+ </FormItem>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+
|
|
|
+ <FormField
|
|
|
+ control={createForm.control}
|
|
|
+ name="isMarried"
|
|
|
+ render={({ field }) => (
|
|
|
+ <FormItem>
|
|
|
+ <FormLabel>婚姻状况</FormLabel>
|
|
|
+ <FormControl>
|
|
|
+ <select
|
|
|
+ className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
|
|
|
+ {...field}
|
|
|
+ value={field.value?.toString()}
|
|
|
+ onChange={(e) => field.onChange(Number(e.target.value))}
|
|
|
+ >
|
|
|
+ <option value="0">未婚</option>
|
|
|
+ <option value="1">已婚</option>
|
|
|
+ </select>
|
|
|
+ </FormControl>
|
|
|
+ <FormMessage />
|
|
|
+ </FormItem>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+
|
|
|
+ <div className="col-span-2">
|
|
|
+ <FormLabel>照片上传</FormLabel>
|
|
|
+ <FileSelector
|
|
|
+ value={null}
|
|
|
+ onChange={() => {
|
|
|
+ // 这里需要处理文件ID的存储
|
|
|
+ // 由于后端Schema没有photoFileId字段,暂时注释
|
|
|
+ // createForm.setValue('photoFileId', fileId as number);
|
|
|
+ }}
|
|
|
+ accept="image/*"
|
|
|
+ filterType="image"
|
|
|
+ placeholder="选择或上传照片"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <DialogFooter>
|
|
|
+ <Button type="button" variant="outline" onClick={() => setIsModalOpen(false)}>
|
|
|
+ 取消
|
|
|
+ </Button>
|
|
|
+ <Button type="submit" disabled={createMutation.isPending}>
|
|
|
+ {createMutation.isPending ? '创建中...' : '创建'}
|
|
|
+ </Button>
|
|
|
+ </DialogFooter>
|
|
|
+ </form>
|
|
|
+ </Form>
|
|
|
+ ) : (
|
|
|
+ <Form {...updateForm}>
|
|
|
+ <form onSubmit={updateForm.handleSubmit(onSubmitUpdate)} className="space-y-4">
|
|
|
+ <div className="grid grid-cols-2 gap-4">
|
|
|
+ <FormField
|
|
|
+ control={updateForm.control}
|
|
|
+ name="name"
|
|
|
+ render={({ field }) => (
|
|
|
+ <FormItem>
|
|
|
+ <FormLabel>姓名 *</FormLabel>
|
|
|
+ <FormControl>
|
|
|
+ <Input placeholder="请输入姓名" {...field} />
|
|
|
+ </FormControl>
|
|
|
+ <FormMessage />
|
|
|
+ </FormItem>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+
|
|
|
+ <FormField
|
|
|
+ control={updateForm.control}
|
|
|
+ name="gender"
|
|
|
+ render={({ field }) => (
|
|
|
+ <FormItem>
|
|
|
+ <FormLabel>性别 *</FormLabel>
|
|
|
+ <FormControl>
|
|
|
+ <select
|
|
|
+ className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
|
|
|
+ data-testid="gender-select"
|
|
|
+ {...field}
|
|
|
+ >
|
|
|
+ <option value="男">男</option>
|
|
|
+ <option value="女">女</option>
|
|
|
+ </select>
|
|
|
+ </FormControl>
|
|
|
+ <FormMessage />
|
|
|
+ </FormItem>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+
|
|
|
+ <FormField
|
|
|
+ control={updateForm.control}
|
|
|
+ name="idCard"
|
|
|
+ render={({ field }) => (
|
|
|
+ <FormItem>
|
|
|
+ <FormLabel>身份证号 *</FormLabel>
|
|
|
+ <FormControl>
|
|
|
+ <Input placeholder="请输入身份证号" {...field} />
|
|
|
+ </FormControl>
|
|
|
+ <FormMessage />
|
|
|
+ </FormItem>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+
|
|
|
+ <FormField
|
|
|
+ control={updateForm.control}
|
|
|
+ name="disabilityId"
|
|
|
+ render={({ field }) => (
|
|
|
+ <FormItem>
|
|
|
+ <FormLabel>残疾证号 *</FormLabel>
|
|
|
+ <FormControl>
|
|
|
+ <Input placeholder="请输入残疾证号" {...field} />
|
|
|
+ </FormControl>
|
|
|
+ <FormMessage />
|
|
|
+ </FormItem>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+
|
|
|
+ <FormField
|
|
|
+ control={updateForm.control}
|
|
|
+ name="disabilityType"
|
|
|
+ render={({ field }) => (
|
|
|
+ <FormItem>
|
|
|
+ <FormLabel>残疾类型 *</FormLabel>
|
|
|
+ <FormControl>
|
|
|
+ <select
|
|
|
+ className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
|
|
|
+ data-testid="gender-select"
|
|
|
+ {...field}
|
|
|
+ >
|
|
|
+ <option value="">请选择残疾类型</option>
|
|
|
+ {DISABILITY_TYPES.map((type) => (
|
|
|
+ <option key={type} value={getDisabilityTypeLabel(type)}>
|
|
|
+ {getDisabilityTypeLabel(type)}
|
|
|
+ </option>
|
|
|
+ ))}
|
|
|
+ </select>
|
|
|
+ </FormControl>
|
|
|
+ <FormMessage />
|
|
|
+ </FormItem>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+
|
|
|
+ <FormField
|
|
|
+ control={updateForm.control}
|
|
|
+ name="disabilityLevel"
|
|
|
+ render={({ field }) => (
|
|
|
+ <FormItem>
|
|
|
+ <FormLabel>残疾等级 *</FormLabel>
|
|
|
+ <FormControl>
|
|
|
+ <select
|
|
|
+ className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
|
|
|
+ data-testid="gender-select"
|
|
|
+ {...field}
|
|
|
+ >
|
|
|
+ <option value="">请选择残疾等级</option>
|
|
|
+ {DISABILITY_LEVELS.map((level) => (
|
|
|
+ <option key={level} value={getDisabilityLevelLabel(level)}>
|
|
|
+ {getDisabilityLevelLabel(level)}
|
|
|
+ </option>
|
|
|
+ ))}
|
|
|
+ </select>
|
|
|
+ </FormControl>
|
|
|
+ <FormMessage />
|
|
|
+ </FormItem>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+
|
|
|
+ <FormField
|
|
|
+ control={updateForm.control}
|
|
|
+ name="phone"
|
|
|
+ render={({ field }) => (
|
|
|
+ <FormItem>
|
|
|
+ <FormLabel>联系电话 *</FormLabel>
|
|
|
+ <FormControl>
|
|
|
+ <Input placeholder="请输入联系电话" {...field} />
|
|
|
+ </FormControl>
|
|
|
+ <FormMessage />
|
|
|
+ </FormItem>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+
|
|
|
+ <FormField
|
|
|
+ control={updateForm.control}
|
|
|
+ name="idAddress"
|
|
|
+ render={({ field }) => (
|
|
|
+ <FormItem className="col-span-2">
|
|
|
+ <FormLabel>身份证地址 *</FormLabel>
|
|
|
+ <FormControl>
|
|
|
+ <Input placeholder="请输入身份证地址" {...field} />
|
|
|
+ </FormControl>
|
|
|
+ <FormMessage />
|
|
|
+ </FormItem>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+
|
|
|
+ <div className="col-span-2">
|
|
|
+ <FormLabel>居住地址 *</FormLabel>
|
|
|
+ <div className="space-y-4">
|
|
|
+ <AreaSelect
|
|
|
+ value={{
|
|
|
+ provinceId: updateForm.watch('province') ? Number(updateForm.watch('province')) : undefined,
|
|
|
+ cityId: updateForm.watch('city') ? Number(updateForm.watch('city')) : undefined,
|
|
|
+ districtId: updateForm.watch('district') ? Number(updateForm.watch('district')) : undefined
|
|
|
+ }}
|
|
|
+ onChange={(value) => {
|
|
|
+ updateForm.setValue('province', value.provinceId?.toString() || '');
|
|
|
+ updateForm.setValue('city', value.cityId?.toString() || '');
|
|
|
+ updateForm.setValue('district', value.districtId?.toString() || '');
|
|
|
+ }}
|
|
|
+ />
|
|
|
+
|
|
|
+ <FormField
|
|
|
+ control={updateForm.control}
|
|
|
+ name="detailedAddress"
|
|
|
+ render={({ field }) => (
|
|
|
+ <FormItem>
|
|
|
+ <FormControl>
|
|
|
+ <Input placeholder="详细地址(街道、门牌号等)" {...field} />
|
|
|
+ </FormControl>
|
|
|
+ <FormMessage />
|
|
|
+ </FormItem>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <FormField
|
|
|
+ control={updateForm.control}
|
|
|
+ name="nation"
|
|
|
+ render={({ field }) => (
|
|
|
+ <FormItem>
|
|
|
+ <FormLabel>民族</FormLabel>
|
|
|
+ <FormControl>
|
|
|
+ <Input placeholder="请输入民族" {...field} />
|
|
|
+ </FormControl>
|
|
|
+ <FormMessage />
|
|
|
+ </FormItem>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+
|
|
|
+ <FormField
|
|
|
+ control={updateForm.control}
|
|
|
+ name="isMarried"
|
|
|
+ render={({ field }) => (
|
|
|
+ <FormItem>
|
|
|
+ <FormLabel>婚姻状况</FormLabel>
|
|
|
+ <FormControl>
|
|
|
+ <select
|
|
|
+ className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
|
|
|
+ {...field}
|
|
|
+ value={field.value?.toString()}
|
|
|
+ onChange={(e) => field.onChange(Number(e.target.value))}
|
|
|
+ >
|
|
|
+ <option value="0">未婚</option>
|
|
|
+ <option value="1">已婚</option>
|
|
|
+ </select>
|
|
|
+ </FormControl>
|
|
|
+ <FormMessage />
|
|
|
+ </FormItem>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <DialogFooter>
|
|
|
+ <Button type="button" variant="outline" onClick={() => setIsModalOpen(false)}>
|
|
|
+ 取消
|
|
|
+ </Button>
|
|
|
+ <Button type="submit" disabled={updateMutation.isPending}>
|
|
|
+ {updateMutation.isPending ? '更新中...' : '更新'}
|
|
|
+ </Button>
|
|
|
+ </DialogFooter>
|
|
|
+ </form>
|
|
|
+ </Form>
|
|
|
+ )}
|
|
|
+ </DialogContent>
|
|
|
+ </Dialog>
|
|
|
+
|
|
|
+ {/* 查看详情模态框 */}
|
|
|
+ <Dialog open={viewDialogOpen} onOpenChange={setViewDialogOpen}>
|
|
|
+ <DialogContent className="max-w-4xl">
|
|
|
+ <DialogHeader>
|
|
|
+ <DialogTitle>残疾人详情</DialogTitle>
|
|
|
+ <DialogDescription>查看残疾人详细信息</DialogDescription>
|
|
|
+ </DialogHeader>
|
|
|
+
|
|
|
+ {viewData && (
|
|
|
+ <div className="space-y-4">
|
|
|
+ <div className="grid grid-cols-2 gap-4">
|
|
|
+ <div>
|
|
|
+ <label className="text-sm font-medium">姓名</label>
|
|
|
+ <p className="text-sm text-muted-foreground">{viewData.name}</p>
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <label className="text-sm font-medium">性别</label>
|
|
|
+ <p className="text-sm text-muted-foreground">{viewData.gender}</p>
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <label className="text-sm font-medium">身份证号</label>
|
|
|
+ <p className="text-sm text-muted-foreground">{viewData.idCard}</p>
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <label className="text-sm font-medium">残疾证号</label>
|
|
|
+ <p className="text-sm text-muted-foreground">{viewData.disabilityId}</p>
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <label className="text-sm font-medium">残疾类型</label>
|
|
|
+ <p className="text-sm text-muted-foreground">{viewData.disabilityType}</p>
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <label className="text-sm font-medium">残疾等级</label>
|
|
|
+ <p className="text-sm text-muted-foreground">{viewData.disabilityLevel}</p>
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <label className="text-sm font-medium">联系电话</label>
|
|
|
+ <p className="text-sm text-muted-foreground">{viewData.phone}</p>
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <label className="text-sm font-medium">身份证地址</label>
|
|
|
+ <p className="text-sm text-muted-foreground">{viewData.idAddress}</p>
|
|
|
+ </div>
|
|
|
+ <div className="col-span-2">
|
|
|
+ <label className="text-sm font-medium">居住地址</label>
|
|
|
+ <p className="text-sm text-muted-foreground">
|
|
|
+ {viewData.province} {viewData.city} {viewData.district} {viewData.detailedAddress}
|
|
|
+ </p>
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <label className="text-sm font-medium">民族</label>
|
|
|
+ <p className="text-sm text-muted-foreground">{viewData.nation || '未填写'}</p>
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <label className="text-sm font-medium">婚姻状况</label>
|
|
|
+ <p className="text-sm text-muted-foreground">
|
|
|
+ {viewData.isMarried === 1 ? '已婚' : viewData.isMarried === 0 ? '未婚' : '未知'}
|
|
|
+ </p>
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <label className="text-sm font-medium">创建时间</label>
|
|
|
+ <p className="text-sm text-muted-foreground">
|
|
|
+ {format(new Date(viewData.createTime), 'yyyy-MM-dd HH:mm:ss')}
|
|
|
+ </p>
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <label className="text-sm font-medium">更新时间</label>
|
|
|
+ <p className="text-sm text-muted-foreground">
|
|
|
+ {format(new Date(viewData.updateTime), 'yyyy-MM-dd HH:mm:ss')}
|
|
|
+ </p>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
+
|
|
|
+ <DialogFooter>
|
|
|
+ <Button onClick={() => setViewDialogOpen(false)}>关闭</Button>
|
|
|
+ </DialogFooter>
|
|
|
+ </DialogContent>
|
|
|
+ </Dialog>
|
|
|
+
|
|
|
+ {/* 删除确认对话框 */}
|
|
|
+ <Dialog open={deleteDialogOpen} onOpenChange={setDeleteDialogOpen}>
|
|
|
+ <DialogContent>
|
|
|
+ <DialogHeader>
|
|
|
+ <DialogTitle data-testid="delete-confirmation-dialog-title">确认删除</DialogTitle>
|
|
|
+ <DialogDescription>
|
|
|
+ 确定要删除这个残疾人记录吗?此操作不可恢复。
|
|
|
+ </DialogDescription>
|
|
|
+ </DialogHeader>
|
|
|
+ <DialogFooter>
|
|
|
+ <Button variant="outline" onClick={() => setDeleteDialogOpen(false)}>
|
|
|
+ 取消
|
|
|
+ </Button>
|
|
|
+ <Button variant="destructive" onClick={confirmDelete} disabled={deleteMutation.isPending}>
|
|
|
+ {deleteMutation.isPending ? '删除中...' : '确认删除'}
|
|
|
+ </Button>
|
|
|
+ </DialogFooter>
|
|
|
+ </DialogContent>
|
|
|
+ </Dialog>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+};
|
|
|
+
|
|
|
+export default DisabilityPersonManagement;
|