78 lines
2.6 KiB
TypeScript
78 lines
2.6 KiB
TypeScript
import type { InventoryRecord } from '@/api/db/inventory'
|
||
import type { TransportInventoryLink } from '@/api/pl'
|
||
import { formatDate } from '@/utils/format'
|
||
|
||
const SITE_INSTRUCTION = '说明:请打开链接上传现场附件并填写备注。'
|
||
|
||
type SiteSummaryRecord = {
|
||
productName?: string
|
||
productText?: string
|
||
batchNo?: string
|
||
planNo?: string
|
||
siteUrl?: string
|
||
}
|
||
|
||
function formatSiteSummaryProductLine(record: SiteSummaryRecord) {
|
||
return record.productText || record.productName || '—'
|
||
}
|
||
|
||
export function buildSiteSummaryFromInventoryLinks(options: {
|
||
planNo?: string
|
||
licensePlate?: string
|
||
pickupTime?: string
|
||
planDate?: string
|
||
records: SiteSummaryRecord[]
|
||
}) {
|
||
const lines = ['【运输现场】']
|
||
const planNo = options.planNo || options.records[0]?.planNo
|
||
if (planNo) lines.push(`计划号:${planNo}`)
|
||
if (options.licensePlate) lines.push(`车牌:${options.licensePlate}`)
|
||
const time = formatDate(options.pickupTime) || options.planDate
|
||
if (time) lines.push(`时间:${time}`)
|
||
|
||
const validRecords = options.records.filter(item => item.siteUrl)
|
||
if (!validRecords.length) {
|
||
lines.push('现场链接:—')
|
||
return lines.join('\n')
|
||
}
|
||
|
||
if (validRecords.length === 1) {
|
||
const record = validRecords[0]
|
||
lines.push(`产品:${formatSiteSummaryProductLine(record)}`)
|
||
if (record.batchNo) lines.push(`出入库单号:${record.batchNo}`)
|
||
lines.push(`现场链接:${record.siteUrl}`)
|
||
} else {
|
||
lines.push('')
|
||
validRecords.forEach((record, index) => {
|
||
lines.push(`【${index + 1}】${formatSiteSummaryProductLine(record)}`)
|
||
if (record.batchNo) lines.push(`出入库单号:${record.batchNo}`)
|
||
lines.push(`现场链接:${record.siteUrl}`)
|
||
if (index < validRecords.length - 1) lines.push('')
|
||
})
|
||
}
|
||
|
||
lines.push('')
|
||
lines.push(SITE_INSTRUCTION)
|
||
return lines.join('\n')
|
||
}
|
||
|
||
export function buildSiteSummaryFromInventory(record: InventoryRecord, siteUrl: string) {
|
||
const spec = record.specification?.trim()
|
||
const product = spec ? `${record.product}(${spec})` : record.product
|
||
const lines = [
|
||
'【出入库现场】',
|
||
`出入库单号:${record.batchNo || '—'}`,
|
||
`业务类型:${record.businessType}`,
|
||
`日期:${record.date || '—'}`,
|
||
`往来单位:${record.partnerCompany || '—'}`,
|
||
`产品:${product}`,
|
||
`数量(吨):${record.quantity ?? '—'}`,
|
||
`车牌:${record.vehicleNo || '—'}`
|
||
]
|
||
if (record.planNo) lines.push(`计划号:${record.planNo}`)
|
||
lines.push(`现场链接:${siteUrl}`)
|
||
lines.push('')
|
||
lines.push(SITE_INSTRUCTION)
|
||
return lines.join('\n')
|
||
}
|