import { OrderList, SupplierFarmerList } from '@/components';
import { Space, Table, TableProps } from 'antd';

type IOrderSupplierInvoiceListProps = TableProps<BusinessAPI.OrderSupplierVO>;

export default function OrderSupplierInvoiceList(
	props: IOrderSupplierInvoiceListProps,
) {
	const { ...tableProps } = props;
	// 订单列表列定义
	const orderColumns = [
		{
			title: '采购单',
			dataIndex: 'orderVO',
			key: 'orderId',
			render: (orderVO: BusinessAPI.OrderVO) => {
				return (
					orderVO && (
						<OrderList
							ghost={true}
							mode={'detail'}
							orderId={orderVO.orderId}
							trigger={() => (
								<Space>
									<a>
										{`${orderVO.orderVehicle?.dealerName} - 第 ${orderVO.orderVehicle?.vehicleNo || '暂无'} 车 - ${orderVO.orderSn || '暂无'}`}
									</a>
								</Space>
							)}
						/>
					)
				);
			},
		},
		{
			title: '瓜农名称',
			key: 'name',
			render: (orderSupplierVO: BusinessAPI.OrderSupplierVO) => {
				return (
					orderSupplierVO && (
						<SupplierFarmerList
							ghost={true}
							mode={'detail'}
							supplierId={orderSupplierVO.supplierId}
							trigger={() => <a>{orderSupplierVO.name}</a>}
						/>
					)
				);
			},
		},
		{
			title: '货款金额(元)',
			dataIndex: 'invoiceAmount',
			key: 'invoiceAmount',
			valueType: 'money',
		},
		{
			title: '定金金额(元)',
			dataIndex: 'depositAmount',
			key: 'depositAmount',
			valueType: 'money',
		},
		{
			title: '应付金额(元)',
			key: 'remainingAmount',
			valueType: 'money',
			search: false,
			render: (record: BusinessAPI.OrderSupplierVO) => {
				return record.invoiceAmount - record.depositAmount || 0;
			},
		},
		...(tableProps.columns || []),
	];

	return (
		<Table
			{...tableProps}
			rowKey="orderSupplierId"
			columns={orderColumns}
			pagination={false}
			size="small"
		/>
	);
}
