import { useState } from "react" import { useMutation, useQueryClient } from "@tanstack/react-query" import { rosterApi } from '../../lib/api-services' import Card from "../../components/ui/Card" import Button from "../../components/ui/Button" import { Input, Label, Select } from "../../components/ui/Input" import { AlertTriangle, Check, Download } from "lucide-react" import { toast } from "sonner" import { useAuthStore } from '../../store/authStore' // ========== 违纪记录管理 ========== export default function DisciplinaryInfo({ employeeId, records }: { employeeId: string; records: any[] }) { const queryClient = useQueryClient() const [showForm, setShowForm] = useState(false) const [form, setForm] = useState({ violationDate: '', violationType: 'LATE', description: '', severity: 'WARNING', action: 'ORAL_WARNING', actionDetail: '', employeeAck: false, ackDate: '', ackMethod: 'SIGN', witness: '' }) const createMutation = useMutation({ mutationFn: (data: any) => rosterApi.createDisciplinary(employeeId, data), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['roster-profile'] }); setShowForm(false) }, }) const deleteMutation = useMutation({ mutationFn: (id: string) => rosterApi.removeDisciplinary(employeeId, id), onSuccess: () => queryClient.invalidateQueries({ queryKey: ['roster-profile'] }), }) const typeMap: Record = { LATE: '迟到', ABSENT: '旷工', INSUBORDINATION: '不服从管理', MISCONDUCT: '违纪', VIOLATE_POLICY: '违反规章制度', OTHER: '其他' } const actionMap: Record = { ORAL_WARNING: '口头警告', WRITTEN_WARNING: '书面警告', DEDUCTION: '扣款', DEMOTION: '降职', TERMINATION: '解除劳动合同' } const severityMap: Record = { WARNING: '警告', SERIOUS: '严重', SEVERE: '重度' } return (

违纪记录({records?.length || 0}条)

{showForm && (
setForm({ ...form, violationDate: e.target.value })} />
setForm({ ...form, description: e.target.value })} placeholder="详细描述违纪事实" />
setForm({ ...form, actionDetail: e.target.value })} placeholder="扣款金额/降职说明等" />
setForm({ ...form, witness: e.target.value })} />
setForm({ ...form, employeeAck: e.target.checked })} />
{form.employeeAck &&
setForm({ ...form, ackDate: e.target.value })} />
}
)} {records?.length === 0 ? (
暂无违纪记录
) : records?.map((r) => (
{r.violationDate?.toString().slice(0, 10)} {severityMap[r.severity] || r.severity} {typeMap[r.violationType] || r.violationType}
{r.description}
处理方式 {actionMap[r.action] || r.action} {r.actionDetail && {r.actionDetail}}
{r.employeeAck ? ( 已签字({r.ackDate?.toString().slice(0, 10)}) ) : ( 未签字 )} {r.witness && 见证人:{r.witness}} {r.ackMethod && 确认方式:{r.ackMethod === 'SIGN' ? '签字' : r.ackMethod === 'ELECTRONIC' ? '电子' : '拒绝'}}
{r.employeeAck && ( )}
))}
) }