/** * 第三方卡券采购价:只统计渠道,不产生履约动作。 * * 商品编码固定为 `tpv:`;成本写入 `sys_third_party_voucher_cost` 的 * 商品级版本,由成本快照管道消费。 */ import { ReloadOutlined } from '@ant-design/icons' import { Button, Card, Form, Input, InputNumber, Modal, Tag, Typography, message } from 'antd' import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' import { useState } from 'react' import PercentTable from '@/components/common/PercentTable' import { fetchAdminProductCatalog, setAdminProductPrice } from '@/services/admin' import type { ProductCatalogItem } from '@/types/admin' import { useCostCenter } from './CostCenterContext' const PAGE_SIZE = 100 export default function VoucherSkuPanel() { const queryClient = useQueryClient() const { canConfig, refreshAll } = useCostCenter() const [page] = useState(1) const [selected, setSelected] = useState(null) const [form] = Form.useForm<{ amountFen: number; changeReason?: string }>() const query = useQuery({ queryKey: ['cost-center-voucher-products', page], queryFn: () => fetchAdminProductCatalog({ carrierType: 'third_party_voucher', page, pageSize: PAGE_SIZE, }), }) const saveMutation = useMutation({ mutationFn: (values: { amountFen: number; changeReason?: string }) => setAdminProductPrice(selected!.id, { amountFen: Math.round(values.amountFen * 100), changeReason: values.changeReason || '第三方卡券采购价调整', }), onSuccess: () => { message.success('采购价已保存') setSelected(null) form.resetFields() void queryClient.invalidateQueries({ queryKey: ['cost-center-voucher-products'] }) refreshAll() }, onError: (error) => message.error(error instanceof Error ? error.message : '保存失败'), }) const items = query.data?.data.items || [] const total = query.data?.data.pagination.total || 0 const columns = [ { title: '商品', dataIndex: 'canonicalName', ellipsis: true }, { title: '编码', dataIndex: 'canonicalSku', width: 220 }, { title: '采购价', width: 140, render: (_: unknown, row: ProductCatalogItem) => row.activeCostAmountFen === null || row.activeCostAmountFen === undefined ? ( 未配价 ) : ( `¥${(row.activeCostAmountFen / 100).toFixed(2)}` ), }, { title: '生效时间', dataIndex: 'activeCostEffectiveFrom', width: 180, render: (value?: string | null) => value || '—', }, { title: '操作', width: 110, render: (_: unknown, row: ProductCatalogItem) => ( ), }, ] return ( } onClick={() => void query.refetch()}> 刷新 } > 卡券渠道只统计:命中规则后不创建任务、不发领取页,只记收入与采购成本。 商品编码以{' '} tpv: 开头。 setSelected(null)} onOk={() => form.submit()} confirmLoading={saveMutation.isPending} >
saveMutation.mutate(values)}>
) }