Files
shanxia2.0/web-admin/src/utils/mp-pl-plan-display.ts
T
2026-09-17 09:10:10 +08:00

55 lines
1.9 KiB
TypeScript

import type { PlanDelivery, PlanLoad } from '@/api/pl'
import { useDictStore } from '@/store/modules/dict'
import { formatDate } from '@/utils/format'
import { formatStopDibangLabel } from '@/utils/pl-plan-list-display-rows'
/** 移动端运输计划:日期只展示到年月日 */
export function formatMpPlanYmd(value?: string | number | Date | null): string {
if (value == null || value === '') return '—'
const text = formatDate(value)
if (text) return text
const raw = String(value).trim()
return raw.slice(0, 10) || '—'
}
export function formatMpPlanYmdList(values?: Array<string | null | undefined> | null): string {
const parts = (values || [])
.map((item) => formatMpPlanYmd(item))
.filter((item) => item && item !== '—')
return parts.length ? [...new Set(parts)].join('、') : '—'
}
export function resolveMpDictLabel(
dictType: string,
value?: string | null,
emptyFallback = '—'
): string {
const raw = String(value || '').trim()
if (!raw) return emptyFallback
const dictStore = useDictStore()
return dictStore.getLabel(dictType, raw) || raw
}
/** 产品单位:dun → 吨 */
export function resolveMpProductUnitLabel(unit?: string | null): string {
return resolveMpDictLabel('crm_product_unit', unit)
}
/** 包装规格字典 */
export function resolveMpPackageSpecLabel(spec?: string | null): string {
return resolveMpDictLabel('crm_product_gg', spec)
}
/** 送货方式字典 */
export function resolveMpDeliveryMethodLabel(method?: string | null): string {
return resolveMpDictLabel('crm_shfs', method)
}
/** 地磅:未生成 / 出库 / 入库(不用 outbound 等编码) */
export function formatMpStopDibangText(
stop: Pick<PlanLoad | PlanDelivery, 'generateDibang' | 'dibangDirection'> | null | undefined
): string {
if (!stop) return '—'
return formatStopDibangLabel(stop as PlanLoad | PlanDelivery) || '未生成'
}