/** * 门户提交工单(册 5 §6.2;enterprise 主账号/sub 下属分账号)。 * * 真调 `POST /ticket/create@v1`: * - 只收 `fault`/`after_sale`(create.rs `CREATE_TYPES`),开户/停机/服务开通联系运营办理; * - `customer_id` ⛔ 由前端传——服务端按登录会话派生(`resolve_customer`,跨客户 `KLT-C007`); * - `title` 是服务端必填(≤128 字),⛔ 服务端替提交方编标题; * - 「挂接团队自动分派」是服务端行为(分派引擎),⛔ 在本地演示数据里复刻; * ⚠️ 建单层**不做**同类未完成并入(2026-11-18 撤除),一次提交=一张单; * - 附件:`material_grant` 要 `ticket_id`,建单前拿不到上传凭证, * ⛔ 把未上传的文件名随单提交,材料在建单后到工单详情直传(§5.8)。 */ import { useCallback, useEffect, useRef, useState, type FormEvent } from "react"; import { ArrowRight, Check, CircleAlert, ClipboardCheck, ClipboardList, Clock3, FileText, Info, RefreshCw, Search, Send, X } from "lucide-react"; import { Link, useLocation, useSearchParams } from "react-router"; import { Button } from "../components/ui/button"; import { SearchInput } from "../components/ui/search-input"; import { FilterSelect } from "../components/ui/filter-select"; import { DateRangeFilter } from "../components/ui/date-range-filter"; import { FieldHint } from "../components/ui/field-hint"; import { ServerListPager } from "../components/ListPager"; import { TicketState } from "../components/ticketState"; import { TicketStatusTag, TicketTypeTag } from "../components/work-order/TicketBadges"; import { PageIntro } from "../components/PageIntro"; import { WorkspaceEmpty, WorkspaceHeading, WorkspacePanel } from "../components/RoleWorkspaceKit"; import { OpsNotice, OpsTableColumns } from "../components/OperationsKit"; import { useDemoIdentity } from "../lib/demo-session"; import { readCustomers } from "../lib/customer-records"; import { detailLinkState } from "../lib/detail-navigation"; import { classifyTicketError, fmtTime, TICKET_PAGE_SIZE, useTicketDetail, useTicketList } from "../lib/ticket"; import { ticketCreate, TICKET_STATUSES, TICKET_TYPES, statusLabel, nonMainlineStatusLabel, typeLabel, ticketConfirmClose, ticketWithdraw } from "../lib/api/ticket"; import type { TicketListItem } from "../lib/api/ticket"; import { useSubmit } from "../lib/useLoad"; import { customerLiveTicketActions } from "../lib/customer-workspace"; import { useHorizontalOverflow } from "../lib/use-horizontal-overflow"; import { useTicketStatusCounts } from "../lib/work-order-counts"; import "../styles/operations.css"; import "../styles/orders.css"; import "../styles/work-orders.css"; import "../styles/work-order-ledger.css"; export function CustomerSubmitPage() { const location = useLocation(); const identity = useDemoIdentity(); const customer = readCustomers().find((item) => item.no === identity?.customerNo); const [type, setType] = useState<"fault" | "after_sale">("fault"); const [title, setTitle] = useState(""); const [description, setDescription] = useState(""); const [errors, setErrors] = useState({ title: "", desc: "" }); const [done, setDone] = useState<{ id: string; no: string } | null>(location.state?.submittedTicket ?? null); const detailState = detailLinkState(location.pathname + location.search + location.hash, { ...location.state, submittedTicket: done }); const submit = useSubmit(); if (!identity || !["enterprise", "sub"].includes(identity.role)) return ; async function onSubmit(event: FormEvent) { event.preventDefault(); setDone(null); // D-17:⛔ HTML5 required 静默拦截——浏览器先拦则提示永不出现;校验一律走这里。 // 一次提交收集**全部**缺失项一并回显,⛔ 只报第一条(修完一条又冒下一条=挤牙膏)。 const next = { title: title.trim().length < 2 || title.trim().length > 128 ? "请填写事项标题(2–128 字,服务端必填)。" : "", desc: description.trim().length < 2 ? "请至少填写 2 个字,描述具体事项。" : "", }; setErrors(next); if (next.title || next.desc) return; const ok = await submit.run(() => ticketCreate({ ticket_type: type, title: title.trim(), detail: description.trim(), }).then((r) => { setDone({ id: r.ticket_id, no: r.ticket_no }); setTitle(""); setDescription(""); })); if (!ok) return; } const failure = submit.error ? classifyTicketError(submit.error) : null; const titleInvalid = Boolean(errors.title); const descInvalid = Boolean(errors.desc); return
查看工单进度 } />
{done &&
{`工单 ${done.no} 已提交,运维团队将尽快与您联系。`} 查看工单
}