export function getPlVehicleStatusTagType(status: string) { const map: Record = { available: 'success', maintaining: 'warning', scrapped: 'danger' } return map[status] || 'info' } export function getPlVehicleStatusLabel(status: string) { const map: Record = { available: '可用', maintaining: '维修中', scrapped: '报废' } return map[status] || status } export function getPlVehicleTypeLabel(type: string) { return type === 'self' ? '自有' : type === 'carrier' ? '承运商' : type } export function getPlVehicleTypeTagType(type: string) { return type === 'self' ? 'success' : 'warning' } type VehicleTrailerLookup = ReadonlyMap | Record function resolveTrailerFromLookup(plate: string, lookup?: VehicleTrailerLookup) { if (!lookup || !plate) return '' if (lookup instanceof Map) return lookup.get(plate)?.trim() || '' return lookup[plate]?.trim() || '' } /** 按车牌构建挂车号查找表(仅 licensePlate 的业务列表用) */ export function buildVehicleTrailerLookup( vehicles: Array<{ licensePlate?: string | null; trailerNo?: string | null }> = [] ) { const map = new Map() for (const vehicle of vehicles) { const plate = vehicle.licensePlate?.trim() const trailer = vehicle.trailerNo?.trim() if (plate && trailer) map.set(plate, trailer) } return map } /** 列表/摘要:车牌号(挂车号) */ export function formatPlVehiclePlateDisplay( licensePlate?: string | null, trailerNo?: string | null, trailerLookup?: VehicleTrailerLookup ) { const plate = licensePlate?.trim() || '' const trailer = trailerNo?.trim() || resolveTrailerFromLookup(plate, trailerLookup) if (!plate && !trailer) return '—' if (plate && trailer) return `${plate}(${trailer})` return plate || trailer } export function getPlCarrierStatusLabel(status: string) { return status === '1' ? '合作中' : '已终止' } export function getPlCarrierStatusTagType(status: string) { return status === '1' ? 'success' : 'danger' } export function getPlCarrierAuditStatusLabel(status?: string) { const map: Record = { pending: '待审核', approved: '已通过', rejected: '已驳回' } return status ? map[status] || status : '待审核' } export function getPlCarrierAuditStatusTagType(status?: string) { const map: Record = { pending: 'warning', approved: 'success', rejected: 'danger' } return map[status || ''] || 'info' } export function getPlanProductSpec(product: { model?: string; packageSpec?: string }) { return product.model || product.packageSpec || '—' } export function getPlanProductQuantity(product: { quantity?: number | string | null actualQty?: number | string | null inboundEstimateQty?: number | string | null outboundEstimateQty?: number | string | null }) { const qty = product.actualQty ?? product.quantity ?? product.inboundEstimateQty ?? product.outboundEstimateQty if (qty === undefined || qty === null || qty === '') return '—' return String(qty) } export function getPlanProductPlannedQuantity(product: { quantity?: number | string | null }) { const qty = product.quantity if (qty === undefined || qty === null || qty === '') return '—' return String(qty) } export function formatPlanProductListText( product: { productName?: string model?: string packageSpec?: string unit?: string quantity?: number | string | null actualQty?: number | string | null inboundEstimateQty?: number | string | null outboundEstimateQty?: number | string | null }, getUnitLabel?: (unit: string) => string, options?: { usePlannedQuantity?: boolean } ) { const name = product.productName || '—' const spec = getPlanProductSpec(product) const qty = options?.usePlannedQuantity ? getPlanProductPlannedQuantity(product) : getPlanProductQuantity(product) const unitRaw = product.unit || '' const unit = unitRaw ? (getUnitLabel ? getUnitLabel(unitRaw) || unitRaw : unitRaw) : '' const specPart = spec && spec !== '—' ? `(${spec})` : '' let qtyUnit = '—' if (qty !== '—' && unit) { qtyUnit = `${qty}${unit}` } else if (qty !== '—') { qtyUnit = qty } else if (unit) { qtyUnit = unit } return `${name}${specPart},${qtyUnit}` } /** 司机公开页产品一行展示(含运输计划产品备注) */ export function formatPublicTransportProductLine(product: { productName?: string model?: string packageSpec?: string unit?: string quantity?: number | string | null remark?: string }) { const name = product.productName?.trim() || '—' const parts: string[] = [] const model = product.model?.trim() const packageSpec = product.packageSpec?.trim() if (model) parts.push(model) if (packageSpec) parts.push(packageSpec) const qty = getPlanProductPlannedQuantity(product) const unitRaw = product.unit || '吨' parts.push(qty !== '—' ? `${qty} ${unitRaw}` : unitRaw) const remark = product.remark?.trim() parts.push(`备注:${remark || '—'}`) return `${name}(${parts.join(',')})` } export function getPlPlanCompanyLabel(company?: string) { const map: Record = { shanxia: '安庆山峡', yundong: '安徽云栋' } return company ? map[company] || company : '—' } export function getPlPlanTypeTagType(type?: string) { const map: Record = { direct: 'primary', inbound: 'success', outbound: 'warning' } return map[type || ''] || 'info' } export function getPlPlanTypeLabel(type?: string) { const map: Record = { direct: '直销单', inbound: '入库单', outbound: '出库单' } return type ? map[type] || type : '—' } export function getPlPlanFollowStatusTagType(status?: string) { const map: Record = { draft: 'info', processing: 'warning', completed: 'success', cancelled: 'danger' } return map[status || ''] || 'info' } export function getPlPlanFollowStatusLabel(status?: string) { const map: Record = { draft: '草稿', processing: '进行中', completed: '已完成', cancelled: '已作废' } return status ? map[status] || status : '—' } export function getPlPlanArchiveStatusTagType(status?: string) { return status === 'archived' ? 'info' : 'success' } export function getPlPlanArchiveStatusLabel(status?: string) { return status === 'archived' ? '已归档' : '未归档' } export function getPlPlanCompleteStatusLabel(status?: string) { return status === 'yes' ? '是' : '否' } export function getPlFreightTypeLabel(type?: string) { const map: Record = { by_weight: '按重量', by_trip: '按趟' } return type ? map[type] || type : '—' } export function getPlYesNoLabel(value?: number | boolean | null) { return value === 1 || value === true ? '是' : '否' } export function getPlHasInvoiceLabelFromSettlement(settlement?: { invoiceNo?: string | null invoiceDate?: string | null invoiceAmount?: number | null invoiceAttachmentUrls?: string | null } | null) { if (!settlement) return '—' const hasInvoice = Boolean(settlement.invoiceNo?.trim()) || Boolean(settlement.invoiceDate) || (settlement.invoiceAmount != null && Number(settlement.invoiceAmount) > 0) || Boolean(settlement.invoiceAttachmentUrls?.trim()) return hasInvoice ? '是' : '否' } /** 解析运输单司机回传附件(JSON 数组或逗号分隔) */ export function parsePlFeedbackImages(raw?: string | string[] | null): string[] { if (!raw) return [] if (Array.isArray(raw)) return raw.map((item) => String(item).trim()).filter(Boolean) const text = String(raw).trim() if (!text) return [] try { const parsed = JSON.parse(text) if (Array.isArray(parsed)) { return parsed.map((item) => String(item).trim()).filter(Boolean) } } catch { // fall through } return text .split(',') .map((item) => item.trim()) .filter(Boolean) } export function getPlRechargeTypeLabel(type: string) { return type === 'etc' ? 'ETC' : type === 'fuel' ? '加油' : type } export function getPlRechargeTypeTagType(type: string) { return type === 'etc' ? 'primary' : type === 'fuel' ? 'success' : 'info' } export function getPlRechargeApplyStatusLabel(status: string) { const map: Record = { pending: '待发放', disbursed: '已发放', cancelled: '已作废' } return map[status] || status } export function getPlRechargeApplyStatusTagType(status: string) { const map: Record = { pending: 'warning', disbursed: 'success', cancelled: 'info' } return map[status] || 'info' } export const PL_GAS_STATION_PRESETS = ['中石化', '线上etc-app', '百链'] export const PL_MAINTENANCE_TYPE_PRESETS = ['保养', '维修', '年检'] export function getPlMaintenanceTypeLabel(type: string) { return type || '—' } export function getPlMaintenanceTypeTagType(type: string) { const map: Record = { 保养: 'success', 维修: 'warning', 年检: 'primary' } return map[type] || 'info' } export function getPlMaintenanceApplyStatusLabel(status: string) { const map: Record = { pending: '待处理', processed: '已处理', cancelled: '已作废' } return map[status] || status } export function getPlMaintenanceApplyStatusTagType(status: string) { const map: Record = { pending: 'warning', processed: 'success', cancelled: 'info' } return map[status] || 'info' } export const PL_UREA_UNIT_PRESETS = ['吨桶'] export function getPlUreaApplyStatusLabel(status: string) { const map: Record = { pending: '待发放', disbursed: '已发放', cancelled: '已作废' } return map[status] || status } export function getPlUreaApplyStatusTagType(status: string) { const map: Record = { pending: 'warning', disbursed: 'success', cancelled: 'info' } return map[status] || 'info' }