feat: 完善履约路由、订单服务与自动核销
This commit is contained in:
@@ -2,8 +2,10 @@ import {
|
||||
ArrowDownOutlined,
|
||||
ArrowUpOutlined,
|
||||
DeleteOutlined,
|
||||
DownOutlined,
|
||||
PlusOutlined,
|
||||
ReloadOutlined,
|
||||
RightOutlined,
|
||||
SaveOutlined,
|
||||
SearchOutlined,
|
||||
} from '@ant-design/icons'
|
||||
@@ -41,6 +43,7 @@ import {
|
||||
retryAdminOrderServiceAutoPublishJob,
|
||||
saveAdminOrderServiceProfile,
|
||||
type AdminOrderServiceAutoPublishJob,
|
||||
type AdminOrderServiceCategory,
|
||||
type AdminOrderServiceProfile,
|
||||
type OrderServiceField,
|
||||
type OrderServiceMaterialConfirmation,
|
||||
@@ -81,6 +84,11 @@ type OrderServiceFormValues = {
|
||||
statusSteps: OrderServiceStatusSteps
|
||||
}
|
||||
|
||||
type OrderServiceCategoryNode = {
|
||||
category: AdminOrderServiceCategory
|
||||
children: AdminOrderServiceCategory[]
|
||||
}
|
||||
|
||||
const DEFAULT_SCREENSHOTS: ScreenshotForm = {
|
||||
enabled: true,
|
||||
required: true,
|
||||
@@ -245,6 +253,7 @@ export default function OrderServicePanel() {
|
||||
const [form] = Form.useForm<OrderServiceFormValues>()
|
||||
const [selectedCategoryId, setSelectedCategoryId] = useState<number | null>(null)
|
||||
const [categoryKeyword, setCategoryKeyword] = useState('')
|
||||
const [expandedCategoryIds, setExpandedCategoryIds] = useState<Set<number>>(() => new Set())
|
||||
const [fields, setFields] = useState<OrderServiceField[]>([])
|
||||
const [guideImage, setGuideImage] = useState<UploadedFile | Record<string, unknown> | null>(null)
|
||||
const [saving, setSaving] = useState(false)
|
||||
@@ -268,22 +277,56 @@ export default function OrderServicePanel() {
|
||||
[profiles],
|
||||
)
|
||||
const normalizedKeyword = categoryKeyword.trim().toLowerCase()
|
||||
const filteredCategories = useMemo(
|
||||
() =>
|
||||
categories.filter((item) => {
|
||||
if (!normalizedKeyword) return true
|
||||
return (
|
||||
item.name.toLowerCase().includes(normalizedKeyword) ||
|
||||
item.categoryKey.toLowerCase().includes(normalizedKeyword)
|
||||
)
|
||||
}),
|
||||
[categories, normalizedKeyword],
|
||||
const categoryTree = useMemo<OrderServiceCategoryNode[]>(() => {
|
||||
const childrenByParent = new Map<number, AdminOrderServiceCategory[]>()
|
||||
const roots: AdminOrderServiceCategory[] = []
|
||||
for (const category of categories) {
|
||||
if (category.parentId) {
|
||||
const children = childrenByParent.get(category.parentId) || []
|
||||
children.push(category)
|
||||
childrenByParent.set(category.parentId, children)
|
||||
} else {
|
||||
roots.push(category)
|
||||
}
|
||||
}
|
||||
const matches = (category: AdminOrderServiceCategory) =>
|
||||
!normalizedKeyword ||
|
||||
category.name.toLowerCase().includes(normalizedKeyword) ||
|
||||
category.categoryKey.toLowerCase().includes(normalizedKeyword)
|
||||
|
||||
return roots.flatMap((category) => {
|
||||
const children = childrenByParent.get(category.categoryId) || []
|
||||
if (!normalizedKeyword) return [{ category, children }]
|
||||
if (matches(category)) return [{ category, children }]
|
||||
const matchedChildren = children.filter(matches)
|
||||
return matchedChildren.length > 0 ? [{ category, children: matchedChildren }] : []
|
||||
})
|
||||
}, [categories, normalizedKeyword])
|
||||
const filteredCategoryCount = categoryTree.reduce(
|
||||
(total, node) => total + 1 + node.children.length,
|
||||
0,
|
||||
)
|
||||
const configuredCount = categories.filter((item) =>
|
||||
profileByCategoryId.has(item.categoryId),
|
||||
).length
|
||||
const configuredCount = new Set(
|
||||
profiles.filter((item) => item.status !== 'archived').map((item) => item.categoryId),
|
||||
).size
|
||||
const selectedCategory = categories.find((item) => item.categoryId === selectedCategoryId) || null
|
||||
const profile = (selectedCategoryId ? profileByCategoryId.get(selectedCategoryId) : null) || null
|
||||
const ownProfile =
|
||||
(selectedCategoryId ? profileByCategoryId.get(selectedCategoryId) : null) || null
|
||||
const parentCategory = selectedCategory?.parentId
|
||||
? categories.find((item) => item.categoryId === selectedCategory.parentId) || null
|
||||
: null
|
||||
const parentProfileCandidate = parentCategory
|
||||
? profileByCategoryId.get(parentCategory.categoryId) || null
|
||||
: null
|
||||
const parentProfile =
|
||||
parentProfileCandidate?.currentVersionNo && parentProfileCandidate.status !== 'archived'
|
||||
? parentProfileCandidate
|
||||
: null
|
||||
const profile = ownProfile || parentProfile
|
||||
const inheritsParentProfile = !ownProfile && Boolean(parentProfile)
|
||||
const runtimeInheritsParent =
|
||||
Boolean(parentProfile) &&
|
||||
(!ownProfile || ownProfile.status === 'archived' || !ownProfile.currentVersionNo)
|
||||
const guideFiles = useMemo(() => {
|
||||
const image = resolveGuideImage(guideImage)
|
||||
return image ? [image] : []
|
||||
@@ -311,7 +354,10 @@ export default function OrderServicePanel() {
|
||||
|
||||
function applyProfile(nextProfile: AdminOrderServiceProfile | null) {
|
||||
form.setFieldsValue({
|
||||
name: nextProfile?.name || selectedCategory?.name || '',
|
||||
name:
|
||||
inheritsParentProfile && selectedCategory
|
||||
? selectedCategory.name
|
||||
: nextProfile?.name || selectedCategory?.name || '',
|
||||
title: nextProfile?.title || '',
|
||||
description: nextProfile?.description || '',
|
||||
guideImageDescription: nextProfile?.guideImageDescription || '',
|
||||
@@ -436,7 +482,11 @@ export default function OrderServicePanel() {
|
||||
successText: values.successText,
|
||||
postSubmitText: values.postSubmitText,
|
||||
})
|
||||
message.success('草稿已保存;点击“发布新版本”后才会影响新工单')
|
||||
message.success(
|
||||
inheritsParentProfile
|
||||
? '已创建二级分类独立草稿;发布后优先使用该配置'
|
||||
: '草稿已保存;点击“发布新版本”后才会影响新工单',
|
||||
)
|
||||
await refresh()
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : '保存失败')
|
||||
@@ -446,13 +496,13 @@ export default function OrderServicePanel() {
|
||||
}
|
||||
|
||||
async function handlePublish() {
|
||||
if (!profile) {
|
||||
message.warning('请先保存配置草稿')
|
||||
if (!ownProfile) {
|
||||
message.warning('当前分类继承父级配置,请先保存二级分类独立草稿')
|
||||
return
|
||||
}
|
||||
setPublishing(true)
|
||||
try {
|
||||
const response = await publishAdminOrderServiceProfile(profile.id)
|
||||
const response = await publishAdminOrderServiceProfile(ownProfile.id)
|
||||
const backfilled = Number(response.data.backfilledPendingOrders || 0)
|
||||
message.success(
|
||||
backfilled > 0
|
||||
@@ -468,10 +518,10 @@ export default function OrderServicePanel() {
|
||||
}
|
||||
|
||||
async function handleArchive() {
|
||||
if (!profile) return
|
||||
if (!ownProfile) return
|
||||
setPublishing(true)
|
||||
try {
|
||||
await archiveAdminOrderServiceProfile(profile.id)
|
||||
await archiveAdminOrderServiceProfile(ownProfile.id)
|
||||
message.success('配置已归档;已有工单快照不受影响')
|
||||
await refresh()
|
||||
} catch (error) {
|
||||
@@ -571,7 +621,7 @@ export default function OrderServicePanel() {
|
||||
<Space size={6}>
|
||||
<Text strong>接单分类</Text>
|
||||
<Text type="secondary">
|
||||
{filteredCategories.length}/{categories.length}
|
||||
{filteredCategoryCount}/{categories.length}
|
||||
</Text>
|
||||
</Space>
|
||||
<Input
|
||||
@@ -584,34 +634,97 @@ export default function OrderServicePanel() {
|
||||
/>
|
||||
</div>
|
||||
<div className="order-service-category-list">
|
||||
{filteredCategories.map((category) => {
|
||||
{categoryTree.map(({ category, children }) => {
|
||||
const rowProfile = profileByCategoryId.get(category.categoryId)
|
||||
const status = resolveProfileStatus(rowProfile)
|
||||
const expanded =
|
||||
Boolean(normalizedKeyword) || expandedCategoryIds.has(category.categoryId)
|
||||
return (
|
||||
<button
|
||||
key={category.categoryId}
|
||||
type="button"
|
||||
className={`order-service-category-item${
|
||||
category.categoryId === selectedCategoryId ? ' is-active' : ''
|
||||
}`}
|
||||
onClick={() => setSelectedCategoryId(category.categoryId)}
|
||||
>
|
||||
<span className="order-service-category-main">
|
||||
<span className="order-service-category-name">{category.name}</span>
|
||||
</span>
|
||||
<span className="order-service-category-meta">
|
||||
<span className="order-service-category-key">
|
||||
{category.categoryKey}
|
||||
{category.status === 'active' ? '' : ' · 已停用'}
|
||||
<div className="order-service-category-group" key={category.categoryId}>
|
||||
<button
|
||||
type="button"
|
||||
className={`order-service-category-item${
|
||||
category.categoryId === selectedCategoryId ? ' is-active' : ''
|
||||
}`}
|
||||
onClick={() => {
|
||||
setSelectedCategoryId(category.categoryId)
|
||||
if (children.length === 0) return
|
||||
setExpandedCategoryIds((current) => {
|
||||
const next = new Set(current)
|
||||
if (next.has(category.categoryId)) {
|
||||
next.delete(category.categoryId)
|
||||
} else {
|
||||
next.add(category.categoryId)
|
||||
}
|
||||
return next
|
||||
})
|
||||
}}
|
||||
>
|
||||
<span className="order-service-category-main">
|
||||
{children.length > 0 ? (
|
||||
<span className="order-service-category-toggle">
|
||||
{expanded ? <DownOutlined /> : <RightOutlined />}
|
||||
</span>
|
||||
) : (
|
||||
<span className="order-service-category-toggle is-empty" />
|
||||
)}
|
||||
<span className="order-service-category-name">{category.name}</span>
|
||||
{children.length > 0 ? (
|
||||
<Tag className="order-service-category-count">
|
||||
{children.length} 个二级
|
||||
</Tag>
|
||||
) : null}
|
||||
</span>
|
||||
<span className={`order-service-status-pill is-${status.tone}`}>
|
||||
{status.label}
|
||||
<span className="order-service-category-meta">
|
||||
<span className="order-service-category-key">
|
||||
{category.categoryKey}
|
||||
{category.status === 'active' ? '' : ' · 已停用'}
|
||||
</span>
|
||||
<span className={`order-service-status-pill is-${status.tone}`}>
|
||||
{status.label}
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
</button>
|
||||
</button>
|
||||
{expanded ? (
|
||||
<div className="order-service-subcategory-list">
|
||||
{children.map((child) => {
|
||||
const childProfile = profileByCategoryId.get(child.categoryId)
|
||||
const childStatus = resolveInheritedProfileStatus(
|
||||
childProfile,
|
||||
rowProfile,
|
||||
)
|
||||
return (
|
||||
<button
|
||||
key={child.categoryId}
|
||||
type="button"
|
||||
className={`order-service-category-item is-child${
|
||||
child.categoryId === selectedCategoryId ? ' is-active' : ''
|
||||
}`}
|
||||
onClick={() => setSelectedCategoryId(child.categoryId)}
|
||||
>
|
||||
<span className="order-service-category-main">
|
||||
<span className="order-service-category-name">{child.name}</span>
|
||||
</span>
|
||||
<span className="order-service-category-meta">
|
||||
<span className="order-service-category-key">
|
||||
{child.categoryKey}
|
||||
{child.status === 'active' ? '' : ' · 已停用'}
|
||||
</span>
|
||||
<span
|
||||
className={`order-service-status-pill is-${childStatus.tone}`}
|
||||
>
|
||||
{childStatus.label}
|
||||
</span>
|
||||
</span>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
{filteredCategories.length === 0 ? (
|
||||
{categoryTree.length === 0 ? (
|
||||
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="没有匹配分类" />
|
||||
) : null}
|
||||
</div>
|
||||
@@ -627,21 +740,39 @@ export default function OrderServicePanel() {
|
||||
<Tag color={selectedCategory.status === 'active' ? 'green' : 'default'}>
|
||||
{selectedCategory.status === 'active' ? '启用' : '停用'}
|
||||
</Tag>
|
||||
<Tag color={profile?.status === 'published' ? 'green' : 'orange'}>
|
||||
{profile?.status === 'published'
|
||||
? `线上 v${profile.currentVersionNo || 1}`
|
||||
: profile?.currentVersionNo
|
||||
? `线上 v${profile.currentVersionNo} · 有草稿`
|
||||
: '尚未发布'}
|
||||
<Tag
|
||||
color={
|
||||
ownProfile?.status === 'published'
|
||||
? 'green'
|
||||
: inheritsParentProfile
|
||||
? 'blue'
|
||||
: 'orange'
|
||||
}
|
||||
>
|
||||
{ownProfile
|
||||
? resolveProfileStatus(ownProfile).label
|
||||
: inheritsParentProfile
|
||||
? `继承「${parentCategory?.name || '父级'}」v${parentProfile?.currentVersionNo}`
|
||||
: '尚未配置'}
|
||||
</Tag>
|
||||
{ownProfile && runtimeInheritsParent ? (
|
||||
<Tag color="gold">
|
||||
线上继承「{parentCategory?.name || '父级'}」v
|
||||
{parentProfile?.currentVersionNo}
|
||||
</Tag>
|
||||
) : null}
|
||||
</Space>
|
||||
<Text type="secondary">分类标识:{selectedCategory.categoryKey}</Text>
|
||||
</div>
|
||||
<Space size={8} wrap>
|
||||
<Button loading={publishing} onClick={() => void handlePublish()}>
|
||||
<Button
|
||||
disabled={!ownProfile}
|
||||
loading={publishing}
|
||||
onClick={() => void handlePublish()}
|
||||
>
|
||||
发布新版本
|
||||
</Button>
|
||||
{profile ? (
|
||||
{ownProfile ? (
|
||||
<Button danger loading={publishing} onClick={() => void handleArchive()}>
|
||||
归档
|
||||
</Button>
|
||||
@@ -651,9 +782,17 @@ export default function OrderServicePanel() {
|
||||
|
||||
<Alert
|
||||
className="order-service-tip"
|
||||
type="info"
|
||||
type={runtimeInheritsParent ? 'warning' : 'info'}
|
||||
showIcon
|
||||
message="一个分类复用一套资料配置,接单模板通过“所属分类”自动关联。"
|
||||
message={
|
||||
inheritsParentProfile
|
||||
? `当前二级分类没有独立配置,线上直接继承一级分类「${parentCategory?.name || '父级'}」的已发布模板。修改并保存后会创建二级分类独立草稿。`
|
||||
: ownProfile && runtimeInheritsParent
|
||||
? `当前二级分类草稿尚未发布,线上仍继承一级分类「${parentCategory?.name || '父级'}」的已发布模板。`
|
||||
: selectedCategory.parentId
|
||||
? '二级分类优先使用独立配置;没有独立已发布配置时自动继承一级分类模板。'
|
||||
: '一级分类作为默认模板,其下二级分类未独立配置时会自动继承。'
|
||||
}
|
||||
/>
|
||||
|
||||
<Form form={form} layout="vertical" onFinish={handleSave}>
|
||||
@@ -1204,6 +1343,33 @@ function resolveProfileStatus(profile: AdminOrderServiceProfile | undefined) {
|
||||
return { label: '已归档', tone: 'muted' }
|
||||
}
|
||||
|
||||
function resolveInheritedProfileStatus(
|
||||
profile: AdminOrderServiceProfile | undefined,
|
||||
parentProfile: AdminOrderServiceProfile | undefined,
|
||||
) {
|
||||
if (profile) {
|
||||
const status = resolveProfileStatus(profile)
|
||||
if (profile.status === 'archived' && parentProfile?.currentVersionNo) {
|
||||
return { label: `已归档 · 继承 v${parentProfile.currentVersionNo}`, tone: 'muted' }
|
||||
}
|
||||
if (
|
||||
!profile.currentVersionNo &&
|
||||
profile.status !== 'archived' &&
|
||||
parentProfile?.currentVersionNo
|
||||
) {
|
||||
return { label: `草稿 · 继承 v${parentProfile.currentVersionNo}`, tone: 'warning' }
|
||||
}
|
||||
return status
|
||||
}
|
||||
if (parentProfile?.currentVersionNo && parentProfile.status !== 'archived') {
|
||||
return {
|
||||
label: `继承 v${parentProfile.currentVersionNo}`,
|
||||
tone: 'inherited',
|
||||
}
|
||||
}
|
||||
return { label: '未配置', tone: 'muted' }
|
||||
}
|
||||
|
||||
function OrderServiceSectionTitle({
|
||||
index,
|
||||
title,
|
||||
|
||||
Reference in New Issue
Block a user