107 lines
3.7 KiB
TypeScript
107 lines
3.7 KiB
TypeScript
import { SearchOutlined } from '@ant-design/icons'
|
|
import { App, Button, Card, Form, Input, Result, Space, Typography } from 'antd'
|
|
import { useState } from 'react'
|
|
|
|
import { lookupCollectOrder, submitCollectOrder } from '@/services/worker'
|
|
import type { CollectField } from '@/types/worker-platform'
|
|
|
|
type LookupOrder = {
|
|
workOrderNo: string
|
|
platformOrderId: string
|
|
productName: string
|
|
status: string
|
|
}
|
|
|
|
export default function CollectPage() {
|
|
const { message } = App.useApp()
|
|
const [orderNo, setOrderNo] = useState('')
|
|
const [order, setOrder] = useState<LookupOrder | null>(null)
|
|
const [fields, setFields] = useState<CollectField[]>([])
|
|
const [lookupLoading, setLookupLoading] = useState(false)
|
|
const [submitLoading, setSubmitLoading] = useState(false)
|
|
const [complete, setComplete] = useState(false)
|
|
|
|
async function submitLookup(values: { orderNo: string }) {
|
|
setLookupLoading(true)
|
|
setComplete(false)
|
|
try {
|
|
const response = await lookupCollectOrder(values.orderNo)
|
|
setOrderNo(values.orderNo)
|
|
setOrder(response.data.order)
|
|
setFields(response.data.fields)
|
|
} catch (error) {
|
|
setOrder(null)
|
|
setFields([])
|
|
message.error(error instanceof Error ? error.message : '查询失败')
|
|
} finally {
|
|
setLookupLoading(false)
|
|
}
|
|
}
|
|
|
|
async function submitMaterial(values: Record<string, string>) {
|
|
setSubmitLoading(true)
|
|
try {
|
|
const response = await submitCollectOrder({ orderNo, fields: values })
|
|
setComplete(response.data.complete)
|
|
message.success(response.data.complete ? '资料已完善' : '资料已提交')
|
|
} catch (error) {
|
|
message.error(error instanceof Error ? error.message : '提交失败')
|
|
} finally {
|
|
setSubmitLoading(false)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<main className="collect-page">
|
|
<Card className="collect-card" bordered={false}>
|
|
<Typography.Title level={3}>订单资料补充</Typography.Title>
|
|
<Typography.Paragraph type="secondary">
|
|
请填写正确订单号,匹配成功后继续补充资料。
|
|
</Typography.Paragraph>
|
|
|
|
<Form layout="vertical" onFinish={submitLookup}>
|
|
<Space.Compact className="full-width">
|
|
<Form.Item
|
|
name="orderNo"
|
|
className="collect-order-input"
|
|
rules={[{ required: true, message: '请输入订单号' }]}
|
|
>
|
|
<Input placeholder="订单号" />
|
|
</Form.Item>
|
|
<Button type="primary" htmlType="submit" icon={<SearchOutlined />} loading={lookupLoading}>
|
|
查询
|
|
</Button>
|
|
</Space.Compact>
|
|
</Form>
|
|
|
|
{complete ? (
|
|
<Result status="success" title="资料已提交完成" subTitle="订单已进入待分配状态,请等待处理。" />
|
|
) : null}
|
|
|
|
{order && !complete ? (
|
|
<Card className="platform-section-gap" title={order.productName} size="small">
|
|
<Typography.Paragraph type="secondary">
|
|
订单号:{order.platformOrderId}
|
|
</Typography.Paragraph>
|
|
<Form layout="vertical" onFinish={submitMaterial}>
|
|
{fields.map((field) => (
|
|
<Form.Item
|
|
key={field.key}
|
|
label={field.label}
|
|
name={field.key}
|
|
rules={field.required ? [{ required: true, message: `请填写${field.label}` }] : []}
|
|
>
|
|
<Input />
|
|
</Form.Item>
|
|
))}
|
|
<Button type="primary" htmlType="submit" loading={submitLoading}>
|
|
提交资料
|
|
</Button>
|
|
</Form>
|
|
</Card>
|
|
) : null}
|
|
</Card>
|
|
</main>
|
|
)
|
|
}
|