import { BizContainer, BizValueType, InvoicerStatisticCard, ModeType, OrderSupplierInvoiceList, PaymentTaskCreate, PaymentTaskPay, SupplierFarmerList, SupplierInvoiceList, } from '@/components'; import { business } from '@/services'; import { calculateOrderSupplierStatistics } from '@/utils/calculateOrderSupplierStatistics'; import { formatCurrency } from '@/utils/format'; import { useIntl } from '@@/exports'; import { ActionType, ProColumns, StatisticCard, } from '@ant-design/pro-components'; import { ProDescriptionsItemProps } from '@ant-design/pro-descriptions'; import { Image, Space } from 'antd'; import React, { useEffect, useRef, useState } from 'react'; interface IPaymentTaskListProps { ghost?: boolean; paymentTaskId?: BusinessAPI.PaymentTaskVO['paymentTaskId']; search?: boolean; onValueChange?: () => void; mode?: ModeType; trigger?: () => React.ReactNode; } export default function PaymentTaskList(props: IPaymentTaskListProps) { const { ghost = false, paymentTaskId, search = true, mode = 'page', trigger, onValueChange, } = props; const intl = useIntl(); const intlPrefix = 'paymentTask'; const actionRef = useRef(); const [activeKey, setActiveKey] = useState('PENDING'); const [statisticsPaymentTask, setStatisticsPaymentTask] = useState(); const [loading, setLoading] = useState(true); const initStatistic = async () => { const { data } = await business.paymentTask.statisticsPaymentTask({ statisticsQry: {}, }); setStatisticsPaymentTask(data); setLoading(false); }; useEffect(() => { initStatistic().then(); }, []); /** 状态文本映射 */ const stateMap: Record = { PENDING: { text: intl.formatMessage({ id: intlPrefix + '.state.pending' }), color: 'orange', }, PARTIAL: { text: intl.formatMessage({ id: intlPrefix + '.state.partial' }), color: 'blue', }, COMPLETED: { text: intl.formatMessage({ id: intlPrefix + '.state.completed' }), color: 'green', }, CANCELLED: { text: intl.formatMessage({ id: intlPrefix + '.state.cancelled' }), color: 'red', }, }; const columns: ProColumns[] = [ { title: intl.formatMessage({ id: intlPrefix + '.column.paymentTaskSn' }), dataIndex: 'paymentTaskSn', key: 'paymentTaskSn', }, { title: intl.formatMessage({ id: intlPrefix + '.column.taskName' }), dataIndex: 'taskName', key: 'taskName', }, { title: intl.formatMessage({ id: intlPrefix + '.column.supplier' }), dataIndex: 'supplierVO', key: 'supplierId', valueType: 'supplier', }, { title: intl.formatMessage({ id: intlPrefix + '.column.totalAmount' }), dataIndex: 'totalAmount', key: 'totalAmount', valueType: 'money', search: false, renderText: (value: number) => formatCurrency(value), }, { title: intl.formatMessage({ id: intlPrefix + '.column.paidAmount' }), dataIndex: 'paidAmount', key: 'paidAmount', valueType: 'money', search: false, renderText: (value: number) => formatCurrency(value), }, { title: intl.formatMessage({ id: intlPrefix + '.column.unpaidAmount' }), key: 'unpaidAmount', search: false, render: (_, record) => { const unpaid = (record.totalAmount || 0) - (record.paidAmount || 0); return {formatCurrency(unpaid)}; }, }, { title: intl.formatMessage({ id: intlPrefix + '.column.orderCount' }), dataIndex: 'orderCount', key: 'orderCount', search: false, }, { title: intl.formatMessage({ id: intlPrefix + '.column.state' }), dataIndex: 'state', key: 'state', valueType: 'select', valueEnum: { PENDING: { text: stateMap.PENDING.text, status: 'Warning' }, PARTIAL: { text: stateMap.PARTIAL.text, status: 'Processing' }, COMPLETED: { text: stateMap.COMPLETED.text, status: 'Success' }, CANCELLED: { text: stateMap.CANCELLED.text, status: 'Error' }, }, search: false, render: (_, record) => { const stateInfo = stateMap[record.state] || stateMap.PENDING; return {stateInfo.text}; }, }, ]; const detailColumns: ProDescriptionsItemProps< BusinessAPI.PaymentTaskVO, BizValueType >[] = columns as ProDescriptionsItemProps< BusinessAPI.PaymentTaskVO, BizValueType >[]; const detailContext = (paymentTaskVO: BusinessAPI.PaymentTaskVO) => { // 统计车次数据 const statistics = calculateOrderSupplierStatistics( paymentTaskVO.orderSupplierVOList, ); return [ // 统计卡片 Tab { label: intl.formatMessage({ id: intlPrefix + '.detail.tab.statistics', }), key: 'statistics', children: (
), }, // 开票方统计 Tab ...(statistics.invoicerStatistics.length > 0 ? [ { label: intl.formatMessage({ id: intlPrefix + '.detail.tab.invoicerStatistics', }), key: 'invoicerStatistics', children: (
{statistics.invoicerStatistics.map((stat, index) => ( ))}
), }, ] : []), // 自开车次列表 Tab ...(statistics.selfInvoiceList.length > 0 ? [ { label: intl.formatMessage( { id: intlPrefix + '.detail.tab.selfInvoiceList' }, { count: statistics.selfInvoiceCount }, ), key: 'selfInvoiceList', subTitle: intl.formatMessage( { id: intlPrefix + '.detail.tab.selfInvoiceList.subTitle' }, { count: statistics.selfInvoiceCount }, ), children: ( { return ( supplierInvoiceVO && ( ( {supplierInvoiceVO.supplierName} )} /> ) ); }, }, { title: '发票编码', dataIndex: 'supplierInvoiceVO', key: 'invoiceSn', render: ( supplierInvoiceVO: BusinessAPI.SupplierInvoiceVO, ) => { return ( ( {supplierInvoiceVO.invoiceSn} )} /> ); }, }, ]} pagination={false} size="small" /> ), }, ] : []), // 代开车次列表 Tab ...(statistics.proxyInvoiceList.length > 0 ? [ { label: intl.formatMessage( { id: intlPrefix + '.detail.tab.proxyInvoiceList' }, { count: statistics.proxyInvoiceCount }, ), key: 'proxyInvoiceList', subTitle: intl.formatMessage( { id: intlPrefix + '.detail.tab.proxyInvoiceList.subTitle' }, { count: statistics.proxyInvoiceCount }, ), children: ( { return ( supplierInvoiceVO && ( ( {supplierInvoiceVO.supplierName} )} /> ) ); }, }, { title: '发票编码', dataIndex: 'supplierInvoiceVO', key: 'invoiceSn', render: ( supplierInvoiceVO: BusinessAPI.SupplierInvoiceVO, ) => { return ( ( {supplierInvoiceVO.invoiceSn} )} /> ); }, }, ]} pagination={false} size="small" /> ), }, ] : []), // 无发票车次列表 Tab ...(statistics.noInvoiceList.length > 0 ? [ { label: intl.formatMessage( { id: intlPrefix + '.detail.tab.noInvoiceList' }, { count: statistics.noInvoiceCount }, ), key: 'noInvoiceList', subTitle: intl.formatMessage( { id: intlPrefix + '.detail.tab.noInvoiceList.subTitle' }, { count: statistics.noInvoiceCount }, ), children: ( { if (!wechatQr) { return '暂无微信收款码'; } return ( 微信收款码 ); }, }, ]} dataSource={statistics.noInvoiceList} pagination={false} size="small" /> ), }, ] : []), ]; }; return ( rowKey={'paymentTaskId'} permission={'operation-payment-task'} func={business.paymentTask} method={'paymentTask'} methodUpper={'PaymentTask'} intlPrefix={intlPrefix} modeType={mode} onValueChange={onValueChange} container={{ ghost, fieldProps: { loading, }, }} remark={{ mode: 'editor', }} page={{ fieldProps: { actionRef: actionRef, bordered: true, ...(!ghost && { tableExtraRender: () => ( = + + + ), }), ghost, //@ts-ignore search, params: { ...(activeKey !== 'ALL' && { state: activeKey as BusinessAPI.PaymentTaskVO['state'], }), taskType: 'MELON_FARMER', }, toolbar: { menu: { type: 'tab', activeKey: activeKey, items: [ { key: 'ALL', label: intl.formatMessage({ id: intlPrefix + '.tab.all', }), }, { key: 'PENDING', label: intl.formatMessage({ id: intlPrefix + '.tab.pending', }), }, { key: 'PARTIAL', label: intl.formatMessage({ id: intlPrefix + '.tab.partial', }), }, { key: 'COMPLETED', label: intl.formatMessage({ id: intlPrefix + '.tab.completed', }), }, { key: 'CANCELLED', label: intl.formatMessage({ id: intlPrefix + '.tab.cancelled', }), }, ], onChange: (key) => { setActiveKey(key as string); }, }, actions: [ { actionRef.current?.reload(); onValueChange?.(); }} />, ], }, }, columns, options: (paymentTaskVO: BusinessAPI.PaymentTaskVO, actionRef) => { return [ // 付款抽屉 { actionRef.current?.reload(); onValueChange?.(); }} />, ]; }, }} create={false} update={{ formType: 'drawer', formContext: [], }} destroy={{}} detail={{ rowId: paymentTaskId, formType: 'drawer', columns: detailColumns, formContext: detailContext, formContextMode: 'flat', trigger, }} /> ); }