/** * 人工履约待办页:客服确认履约。 * * 口径(2026-10-24 确认): * * 渠道与消耗积分在成本中心提前配好,客服不选、不填; * * 固定成本 → 点「确认履约」零输入; * * 成本不固定(消耗积分 = 0)→ 只填本次实际成本; * * 确认后自动扣对应平台的积分并写成本快照。 */ import { CheckOutlined, ReloadOutlined } from '@ant-design/icons' import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' import { Alert, App, Button, Card, Form, Input, InputNumber, Modal, Space, Statistic, Tag, Typography, } from 'antd' import PercentTable from '@/components/common/PercentTable' import type { TableColumnsType } from 'antd' import { useState } from 'react' import PageHeader from '@/components/admin/PageHeader' import { confirmAdminManualFulfillment, fetchAdminManualFulfillmentPending } from '@/services/admin' import type { ManualFulfillmentPendingItem } from '@/types/admin' import { ADMIN_DEFAULT_PAGE_SIZE, buildAdminTablePagination } from '@/utils/admin-pagination' import { formatAdminDateTime } from '@/utils/admin-time' type ConfirmFormValues = { costYuan?: number payeeName?: string note?: string } const PLATFORM_TAG_COLORS: Record = { nanhang: 'blue', lewan: 'purple', rock: 'cyan', fund_cash: 'orange', } export default function AdminManualFulfillmentPage() { const { message } = App.useApp() const queryClient = useQueryClient() const [form] = Form.useForm() const [status, setStatus] = useState<'pending' | 'fulfilled' | ''>('pending') const [keyword, setKeyword] = useState('') const [page, setPage] = useState(1) const [pageSize, setPageSize] = useState(ADMIN_DEFAULT_PAGE_SIZE) const [confirming, setConfirming] = useState(null) const [showCostInput, setShowCostInput] = useState(false) const listQuery = useQuery({ queryKey: ['admin-manual-fulfillment-pending', status, keyword, page, pageSize], queryFn: () => fetchAdminManualFulfillmentPending({ status: status || undefined, keyword: keyword || undefined, page, pageSize, }), }) const confirmMutation = useMutation({ mutationFn: (values: ConfirmFormValues) => confirmAdminManualFulfillment({ orderItemId: confirming?.orderItemId || 0, costFen: values.costYuan === undefined ? undefined : Math.round(values.costYuan * 100), payeeName: values.payeeName || '', note: values.note || '', }), onSuccess: (response) => { const result = response.data message.success( `履约已确认,扣 ${result.creditQuantity} 积分,成本 ¥${(result.costFen / 100).toFixed(2)}`, ) setConfirming(null) setShowCostInput(false) void queryClient.invalidateQueries({ queryKey: ['admin-manual-fulfillment-pending'], }) void queryClient.invalidateQueries({ queryKey: ['admin-fund-my'] }) void queryClient.invalidateQueries({ queryKey: ['admin-fund-accounts'] }) void queryClient.invalidateQueries({ queryKey: ['admin-platform-credit-accounts'] }) void queryClient.invalidateQueries({ queryKey: ['admin-platform-credit-entries'] }) }, onError: (error) => { message.error(error instanceof Error ? error.message : '确认履约失败') }, }) function openConfirm(item: ManualFulfillmentPendingItem) { setConfirming(item) setShowCostInput(item.costFen === null) form.resetFields() } const columns: TableColumnsType = [ { title: '商品', key: 'sku', width: 260, render: (_, row) => (
{row.skuName || row.skuCode} {row.internalSku || row.skuCode}
), }, { title: '平台单号', dataIndex: 'platformOrderId', width: 170, render: (value: string) => ( {value} ), }, { title: '履约渠道', key: 'platform', width: 110, render: (_, row) => ( {row.platformLabel} ), }, { title: '消耗', key: 'credit', width: 120, render: (_, row) => row.isFundCash ? ( — ) : ( {row.creditQuantity} 积分 ), }, { title: '成本', key: 'cost', width: 120, align: 'right', render: (_, row) => row.costFen === null ? ( 待填写 ) : ( ¥{(row.costFen / 100).toFixed(2)} ), }, { title: '订单金额', key: 'revenue', width: 100, align: 'right', render: (_, row) => `¥${(row.revenueFen / 100).toFixed(2)}`, }, { title: '支付时间', dataIndex: 'paidAt', width: 150, render: (value: string) => formatAdminDateTime(value), }, { title: '操作', key: 'actions', width: 110, fixed: 'right', render: (_, row) => row.fulfilled ? ( 已履约 ) : ( ), }, ] const total = listQuery.data?.data.pagination.total ?? 0 return (
{ setPage(nextPage) if (nextPageSize !== pageSize) setPageSize(nextPageSize) }, })} /> { void form.validateFields().then((values) => confirmMutation.mutate(values)) }} onCancel={() => { setConfirming(null) setShowCostInput(false) }} destroyOnHidden width={520} > {confirming ? (
商品: {confirming.skuName || confirming.skuCode}
内部 SKU: {confirming.internalSku}
履约渠道: {confirming.platformLabel} {!confirming.isFundCash ? ( 消耗 {confirming.creditQuantity} 积分 ) : null}
{showCostInput ? ( ) : ( )}
) : null} form={form} layout="vertical"> {showCostInput ? ( ) : null}
) }