TicketActionModal.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. 'use client';
  2. import { useState } from 'react';
  3. import { Loader2, X, AlertTriangle } from 'lucide-react';
  4. import { toast } from 'react-hot-toast';
  5. import { ActionType } from '@/types';
  6. interface TicketActionModalProps {
  7. isOpen: boolean;
  8. onClose: () => void;
  9. ticketId: number | null;
  10. actionType: ActionType | null;
  11. onSubmit: (ticketId: number, type: ActionType, comment: string) => Promise<void>;
  12. }
  13. export default function TicketActionModal({ isOpen, onClose, ticketId, actionType, onSubmit }: TicketActionModalProps) {
  14. const [comment, setComment] = useState('');
  15. const [loading, setLoading] = useState(false);
  16. if (!isOpen || !ticketId || !actionType) return null;
  17. const handleSubmit = async () => {
  18. if (!comment.trim()) {
  19. toast.error("请输入处理备注");
  20. return;
  21. }
  22. setLoading(true);
  23. try {
  24. await onSubmit(ticketId, actionType, comment);
  25. setComment('');
  26. toast.success('工单处理成功');
  27. onClose();
  28. } catch (error) {
  29. // ignore
  30. } finally {
  31. setLoading(false);
  32. }
  33. };
  34. const config = {
  35. 'approve': { title: '批准退款申请', text: '确认核销批准' },
  36. 'reject': { title: '驳回申请诉求', text: '确认驳回' },
  37. 'need-info': { title: '要求申请人补件', text: '下发补件通知' },
  38. };
  39. const currentConfig = config[actionType];
  40. return (
  41. <div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/60 backdrop-grayscale font-mono">
  42. <div className="bg-neutral-50 border-2 border-black shadow-[8px_8px_0px_#000] w-full max-w-md overflow-hidden animate-in zoom-in-95 duration-200">
  43. {/* Header */}
  44. <div className="px-5 py-3.5 border-b-2 border-black flex justify-between items-center bg-neutral-200 text-black select-none">
  45. <div className="flex items-center gap-2 text-xs font-bold uppercase tracking-wider">
  46. <span className="w-2.5 h-2.5 bg-amber-300 border border-black inline-block" />
  47. <span>[ ACTION // #{ticketId} // {currentConfig.title} ]</span>
  48. </div>
  49. <button
  50. onClick={onClose}
  51. className="w-6 h-6 bg-white hover:bg-amber-300 border border-black flex items-center justify-center font-bold text-xs transition"
  52. >
  53. ✕
  54. </button>
  55. </div>
  56. <div className="p-6 bg-white space-y-4">
  57. <div className="space-y-1">
  58. <label className="block text-xs font-bold uppercase text-black">
  59. [ 管理员处理核批意见 / 答复说明 ]: <span className="text-black">*</span>
  60. </label>
  61. <textarea
  62. className="w-full border-2 border-black bg-neutral-50 p-2.5 text-xs font-sans focus:bg-white outline-none shadow-[2px_2px_0px_#000] resize-none text-black"
  63. rows={4}
  64. placeholder={actionType === 'reject' ? "请输入详细驳回理由..." : "请输入批准备注或补件指引..."}
  65. value={comment}
  66. onChange={e => setComment(e.target.value)}
  67. />
  68. </div>
  69. <div className="pt-2 flex justify-end gap-3 border-t-2 border-dashed border-neutral-300">
  70. <button
  71. onClick={onClose}
  72. className="px-4 py-2 border-2 border-black bg-neutral-100 hover:bg-neutral-200 text-black font-bold text-xs shadow-[2px_2px_0px_#000] transition active:translate-x-0.5 active:translate-y-0.5 uppercase"
  73. >
  74. [ 取消 ]
  75. </button>
  76. <button
  77. onClick={handleSubmit}
  78. disabled={loading}
  79. className="px-6 py-2 bg-amber-300 hover:bg-amber-400 text-black border-2 border-black font-black text-xs shadow-[3px_3px_0px_#000] transition active:translate-x-0.5 active:translate-y-0.5 active:shadow-none flex items-center gap-1.5 uppercase disabled:opacity-50"
  80. >
  81. {loading ? <Loader2 size={14} className="animate-spin" /> : null}
  82. <span>[ {currentConfig.text} ]</span>
  83. </button>
  84. </div>
  85. </div>
  86. </div>
  87. </div>
  88. );
  89. }