import { BizContainer, BizValueType, CompanyList, ModeType, PurchaseOrderList, } from '@/components'; import { business } from '@/services'; import { useIntl } from '@@/exports'; import { ProColumns } from '@ant-design/pro-components'; import { ProDescriptionsItemProps } from '@ant-design/pro-descriptions'; import React, { useState } from 'react'; import groupby from '@/utils/groupby'; interface IOrderCostListProps { ghost?: boolean; orderCostId?: BusinessAPI.OrderCostVO['orderCostId']; search?: boolean; onValueChange?: () => void; mode?: ModeType; trigger?: () => React.ReactNode; } export default function OrderCostList(props: IOrderCostListProps) { const { ghost = false, orderCostId, search = true, mode = 'page', trigger, onValueChange, } = props; const intl = useIntl(); const intlPrefix = 'orderCost'; const [activeKey, setActiveKey] = useState('ALL'); const columns: ProColumns[] = [ { title: intl.formatMessage({ id: intlPrefix + '.column.name' }), dataIndex: 'name', key: 'costId', valueType: 'select', fieldProps: { fetchDataOnSearch: false, showSearch: true, autoClearSearchValue: true, }, request: async () => { const { data } = await business.cost.listCost({ costListQry: {}, }); const costGroup = groupby(data || [], (item) => item.type); const options = Object.keys(costGroup).map((key) => ({ label: intl.formatMessage({ id: 'cost.column.type.enum.' + key .toLowerCase() .replace(/_([a-z])/g, (_, char) => char.toUpperCase()), }), title: key, options: costGroup[key].map((item) => ({ label: item.name, value: item.costId, })), })); return options || []; }, }, { title: intl.formatMessage({ id: intlPrefix + '.column.principal' }), dataIndex: 'principal', key: 'principal', }, { title: intl.formatMessage({ id: intlPrefix + '.column.belong' }), dataIndex: 'belong', key: 'belong', valueType: 'select', valueEnum: { WORKER_TYPE: { text: intl.formatMessage({ id: intlPrefix + '.column.belong.workerType', }), }, PRODUCTION_TYPE: { text: intl.formatMessage({ id: intlPrefix + '.column.belong.productionType', }), }, DRIVER_TYPE: { text: intl.formatMessage({ id: intlPrefix + '.column.belong.driverType', }), }, }, }, { title: intl.formatMessage({ id: intlPrefix + '.column.price' }), dataIndex: 'price', key: 'price', valueType: 'money', search: false, }, { title: intl.formatMessage({ id: intlPrefix + '.column.purchaseOrder' }), dataIndex: 'purchaseOrderVO', key: 'poOrderSn', render: (_, record) => { return ( {record.purchaseOrderVO.orderSn}} /> ); }, }, { title: intl.formatMessage({ id: intlPrefix + '.column.orderVehicle' }), dataIndex: 'orderVehicle', key: 'ovVehicleNo', render: (_, record) => { return ( {record.orderVehicle.origin} 至 {record.orderVehicle.destination} ); }, }, { title: intl.formatMessage({ id: intlPrefix + '.column.orderCompany' }), dataIndex: 'orderCompany', valueType: 'select', request: async (params) => { const { data } = await business.company.listCompany({ companyListQry: { ...params, }, }); return ( data?.map((item) => { return { label: item.fullName, value: item.companyId, }; }) || [] ); }, render: (_, record) => { return ( {record.orderCompany.fullName}} /> ); }, }, { title: intl.formatMessage({ id: intlPrefix + '.column.isPaid' }), dataIndex: 'isPaid', key: 'isPaid', valueType: 'select', valueEnum: { true: { text: intl.formatMessage({ id: intlPrefix + '.column.isPaid.paid', }), status: 'success', }, false: { text: intl.formatMessage({ id: intlPrefix + '.column.isPaid.unpaid', }), status: 'processing', }, }, }, ]; const detailColumns: ProDescriptionsItemProps< BusinessAPI.OrderCostVO, BizValueType >[] = columns as ProDescriptionsItemProps< BusinessAPI.OrderCostVO, BizValueType >[]; return ( rowKey={'orderCostId'} permission={'operation-order-cost'} func={business.orderCost} method={'orderCost'} methodUpper={'OrderCost'} intlPrefix={intlPrefix} modeType={mode} onValueChange={onValueChange} container={{ ghost, }} status={false} page={{ fieldProps: { bordered: true, ghost, //@ts-ignore search, params: { ...(activeKey !== 'ALL' && { isPaid: activeKey! as any, }), poStates: ['COMPLETED'], belongs: ['WORKER_TYPE', 'PRODUCTION_TYPE', 'DRIVER_TYPE'], }, toolbar: { menu: { type: 'tab', activeKey: activeKey, items: [ // 全部 { key: 'ALL', label: intl.formatMessage({ id: intlPrefix + '.tab.all', }), }, // 已支付 { key: 'true', label: intl.formatMessage({ id: intlPrefix + '.tab.paid', }), }, // 未支付 { key: 'false', label: intl.formatMessage({ id: intlPrefix + '.tab.unpaid', }), }, ], onChange: (key) => { setActiveKey(key as string); }, }, }, }, columns, }} create={false} update={false} destroy={false} detail={{ rowId: orderCostId, formType: 'drawer', columns: detailColumns, trigger, }} /> ); }