TicketActionModal.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. 'use client';
  2. import { useState } from 'react';
  3. import { Loader2, X } from 'lucide-react';
  4. import { ActionType } from '@/types';
  5. interface TicketActionModalProps {
  6. isOpen: boolean;
  7. onClose: () => void;
  8. ticketId: number | null;
  9. actionType: ActionType | null;
  10. onSubmit: (ticketId: number, type: ActionType, comment: string) => Promise<void>;
  11. }
  12. export default function TicketActionModal({ isOpen, onClose, ticketId, actionType, onSubmit }: TicketActionModalProps) {
  13. const [comment, setComment] = useState('');
  14. const [loading, setLoading] = useState(false);
  15. if (!isOpen || !ticketId || !actionType) return null;
  16. const handleSubmit = async () => {
  17. if (!comment.trim()) {
  18. alert("请输入处理备注");
  19. return;
  20. }
  21. setLoading(true);
  22. try {
  23. await onSubmit(ticketId, actionType, comment);
  24. setComment(''); // 清空
  25. onClose(); // 关闭
  26. } catch (error) {
  27. // 错误由父组件处理或在这里处理
  28. } finally {
  29. setLoading(false);
  30. }
  31. };
  32. const config = {
  33. 'approve': { title: '批准退款', btnColor: 'bg-green-600 hover:bg-green-700', text: '确认批准' },
  34. 'reject': { title: '拒绝申请', btnColor: 'bg-red-600 hover:bg-red-700', text: '确认拒绝' },
  35. 'need-info': { title: '要求补充资料', btnColor: 'bg-orange-500 hover:bg-orange-600', text: '发送请求' },
  36. };
  37. const currentConfig = config[actionType];
  38. return (
  39. <div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm">
  40. <div className="bg-white rounded-xl shadow-2xl w-full max-w-md overflow-hidden animate-in zoom-in duration-200">
  41. <div className="px-6 py-4 border-b flex justify-between items-center bg-gray-50">
  42. <h3 className="font-bold text-gray-900">{currentConfig.title} (工单 #{ticketId})</h3>
  43. <button onClick={onClose} className="text-gray-400 hover:text-gray-600">
  44. <X size={20} />
  45. </button>
  46. </div>
  47. <div className="p-6">
  48. <div className="mb-4">
  49. <label className="block text-sm font-medium text-gray-700 mb-2">
  50. 管理员备注 / 回复内容 <span className="text-red-500">*</span>
  51. </label>
  52. <textarea
  53. className="w-full border border-gray-300 rounded-lg p-3 text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none"
  54. rows={4}
  55. placeholder={actionType === 'reject' ? "请输入拒绝理由..." : "请输入备注..."}
  56. value={comment}
  57. onChange={e => setComment(e.target.value)}
  58. />
  59. </div>
  60. <div className="flex justify-end gap-3">
  61. <button
  62. onClick={onClose}
  63. className="px-4 py-2 border border-gray-300 rounded-lg text-sm font-medium text-gray-700 hover:bg-gray-50"
  64. >
  65. 取消
  66. </button>
  67. <button
  68. onClick={handleSubmit}
  69. disabled={loading}
  70. className={`px-4 py-2 text-white rounded-lg text-sm font-medium flex items-center gap-2 disabled:opacity-50 ${currentConfig.btnColor}`}
  71. >
  72. {loading && <Loader2 size={16} className="animate-spin" />}
  73. {currentConfig.text}
  74. </button>
  75. </div>
  76. </div>
  77. </div>
  78. </div>
  79. );
  80. }