| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- 'use client';
- import { useState } from 'react';
- import { Loader2, X } from 'lucide-react';
- import { ActionType } from '@/types';
- interface TicketActionModalProps {
- isOpen: boolean;
- onClose: () => void;
- ticketId: number | null;
- actionType: ActionType | null;
- onSubmit: (ticketId: number, type: ActionType, comment: string) => Promise<void>;
- }
- export default function TicketActionModal({ isOpen, onClose, ticketId, actionType, onSubmit }: TicketActionModalProps) {
- const [comment, setComment] = useState('');
- const [loading, setLoading] = useState(false);
- if (!isOpen || !ticketId || !actionType) return null;
- const handleSubmit = async () => {
- if (!comment.trim()) {
- alert("请输入处理备注");
- return;
- }
- setLoading(true);
- try {
- await onSubmit(ticketId, actionType, comment);
- setComment(''); // 清空
- onClose(); // 关闭
- } catch (error) {
- // 错误由父组件处理或在这里处理
- } finally {
- setLoading(false);
- }
- };
- const config = {
- 'approve': { title: '批准退款', btnColor: 'bg-green-600 hover:bg-green-700', text: '确认批准' },
- 'reject': { title: '拒绝申请', btnColor: 'bg-red-600 hover:bg-red-700', text: '确认拒绝' },
- 'need-info': { title: '要求补充资料', btnColor: 'bg-orange-500 hover:bg-orange-600', text: '发送请求' },
- };
- const currentConfig = config[actionType];
- return (
- <div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm">
- <div className="bg-white rounded-xl shadow-2xl w-full max-w-md overflow-hidden animate-in zoom-in duration-200">
- <div className="px-6 py-4 border-b flex justify-between items-center bg-gray-50">
- <h3 className="font-bold text-gray-900">{currentConfig.title} (工单 #{ticketId})</h3>
- <button onClick={onClose} className="text-gray-400 hover:text-gray-600">
- <X size={20} />
- </button>
- </div>
-
- <div className="p-6">
- <div className="mb-4">
- <label className="block text-sm font-medium text-gray-700 mb-2">
- 管理员备注 / 回复内容 <span className="text-red-500">*</span>
- </label>
- <textarea
- 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"
- rows={4}
- placeholder={actionType === 'reject' ? "请输入拒绝理由..." : "请输入备注..."}
- value={comment}
- onChange={e => setComment(e.target.value)}
- />
- </div>
- <div className="flex justify-end gap-3">
- <button
- onClick={onClose}
- className="px-4 py-2 border border-gray-300 rounded-lg text-sm font-medium text-gray-700 hover:bg-gray-50"
- >
- 取消
- </button>
- <button
- onClick={handleSubmit}
- disabled={loading}
- className={`px-4 py-2 text-white rounded-lg text-sm font-medium flex items-center gap-2 disabled:opacity-50 ${currentConfig.btnColor}`}
- >
- {loading && <Loader2 size={16} className="animate-spin" />}
- {currentConfig.text}
- </button>
- </div>
- </div>
- </div>
- </div>
- );
- }
|