import { useEffect, useState } from 'react'; import { View, Text, ScrollView, Button } from '@tarojs/components'; import { useDidShow } from '@tarojs/taro'; import HqHeader from '../../components/HqHeader'; import HqTabBar from '../../components/HqTabBar'; import { request, type Paginated, toast } from '../../lib/api'; import { useHqSession } from '../../lib/session'; import { badgeClass, fmtTime } from '../../lib/constants'; type TicketRow = { id: string; ticketNo: string; ticketType?: string; refType?: string; status: string; remark?: string; createdAt: string; }; const STATUS_LABELS: Record = { PENDING: '待处理', PROCESSING: '处理中', RESOLVED: '已解决', COMPLETED: '已完成', CLOSED: '已关闭', }; const TABS = [ { key: '', label: '全部' }, { key: 'PENDING', label: '待处理' }, { key: 'PROCESSING', label: '处理中' }, { key: 'COMPLETED', label: '已完成' }, ]; export default function TicketsPage() { useHqSession(); const [status, setStatus] = useState(''); const [rows, setRows] = useState([]); const [total, setTotal] = useState(0); const [loading, setLoading] = useState(true); function load() { setLoading(true); const qs = new URLSearchParams({ pageSize: '50' }); if (status) qs.set('status', status); request>(`/common/tickets?${qs.toString()}`) .then((d) => { setRows(d.items); setTotal(d.total); }) .catch(() => setRows([])) .finally(() => setLoading(false)); } useEffect(load, [status]); useDidShow(load); async function markProcessing(id: string) { try { await request(`/common/tickets/${id}/status`, { method: 'PUT', data: { status: 'PROCESSING' } }); toast('已受理', 'success'); load(); } catch (e) { toast(e instanceof Error ? e.message : '操作失败'); } } return ( {TABS.map((t) => ( setStatus(t.key)} > {t.label} ))} 工单列表 共 {total} 单 {loading && 加载中…} {!loading && rows.length === 0 && 暂无工单} {rows.map((t) => ( {t.ticketNo} {STATUS_LABELS[t.status] || t.status} {t.ticketType || '工单'} · {t.refType || ''} {t.remark ? {t.remark} : null} {fmtTime(t.createdAt)} {t.status === 'PENDING' && ( )} ))} ); }