plLabels.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /** 运输计划 / 运费状态展示 */
  2. export function dash(val) {
  3. if (val == null || val === '') return '—'
  4. return String(val)
  5. }
  6. export function formatMoney(val) {
  7. if (val == null || val === '') return '—'
  8. const n = Number(val)
  9. if (Number.isNaN(n)) return String(val)
  10. return `¥${n.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`
  11. }
  12. export function formatQty(val, unit = '') {
  13. if (val == null || val === '') return '—'
  14. const n = Number(val)
  15. const s = Number.isNaN(n) ? String(val) : String(n)
  16. return unit ? `${s} ${unit}` : s
  17. }
  18. export function planTypeLabel(planType) {
  19. const map = { direct: '直销单', inbound: '入库单', outbound: '出库单' }
  20. return map[planType] || planType || '—'
  21. }
  22. export function followStatusLabel(status) {
  23. const map = {
  24. draft: { text: '草稿', tag: 'muted' },
  25. processing: { text: '进行中', tag: 'warning' },
  26. completed: { text: '已完成', tag: 'success' },
  27. cancelled: { text: '已作废', tag: 'danger' }
  28. }
  29. return map[status] || { text: status || '—', tag: 'muted' }
  30. }
  31. export function transportStatusLabel(status) {
  32. const map = {
  33. pending: { text: '待安排', tag: 'warning' },
  34. arranged: { text: '已安排', tag: 'info' }
  35. }
  36. return map[status] || { text: status || '—', tag: 'muted' }
  37. }
  38. export function archiveStatusLabel(status) {
  39. const map = {
  40. unarchived: { text: '未归档', tag: 'info' },
  41. archived: { text: '已归档', tag: 'success' }
  42. }
  43. return map[status] || { text: status || '—', tag: 'muted' }
  44. }
  45. /**
  46. * Demo 列表 Tab 语义:待发运 / 在途 / 已完成
  47. * - 待发运:transportStatus=pending 且未作废
  48. * - 在途:已安排且跟进未完成
  49. * - 已完成:followStatus=completed
  50. */
  51. export function planListPhase(row) {
  52. if (!row) return { text: '—', tag: 'muted', key: 'unknown' }
  53. if (row.followStatus === 'cancelled') return { text: '已作废', tag: 'danger', key: 'cancelled' }
  54. if (row.followStatus === 'completed') return { text: '已完成', tag: 'success', key: 'done' }
  55. if (row.transportStatus === 'pending') return { text: '待发运', tag: 'warning', key: 'pending' }
  56. if (row.transportStatus === 'arranged') return { text: '在途', tag: 'info', key: 'transit' }
  57. return followStatusLabel(row.followStatus)
  58. }
  59. export function settlementStatusLabel(status) {
  60. const map = {
  61. pending: { text: '草稿', tag: 'muted' },
  62. rejected: { text: '已驳回', tag: 'danger' },
  63. approving: { text: '审批中', tag: 'warning' },
  64. approved: { text: '待发放', tag: 'info' },
  65. confirmed: { text: '已发放', tag: 'success' },
  66. cancelled: { text: '已作废', tag: 'danger' }
  67. }
  68. return map[status] || { text: status || '—', tag: 'muted' }
  69. }
  70. export function isEditableDraftSettlement(status) {
  71. return status === 'pending' || status === 'rejected'
  72. }
  73. /** 计划卡片副标题:品名 · 数量 · 路线 */
  74. export function planCardSub(row) {
  75. if (!row) return '—'
  76. const products = Array.isArray(row.products) ? row.products : []
  77. const names = products
  78. .map((p) => p.productName || p.product_name)
  79. .filter(Boolean)
  80. .slice(0, 2)
  81. const namePart = names.length ? names.join('、') : planTypeLabel(row.planType)
  82. const qty = products.reduce((sum, p) => sum + (Number(p.quantity) || Number(p.actualQty) || 0), 0)
  83. const unit = products[0]?.unit || ''
  84. const qtyPart = qty > 0 ? formatQty(qty, unit) : ''
  85. const from = row.pickupAddress || row.supplierName || ''
  86. const to = row.destinationAddress || row.customerName || row.destinationName || ''
  87. const route = from && to ? `${shortAddr(from)} → ${shortAddr(to)}` : dash(row.customerName || row.destinationName)
  88. return [namePart, qtyPart, route].filter(Boolean).join(' · ')
  89. }
  90. function shortAddr(s) {
  91. const t = String(s || '')
  92. return t.length > 10 ? `${t.slice(0, 10)}…` : t
  93. }
  94. export function certReadyLabel(ready) {
  95. return ready ? { text: '证书齐备', tag: 'success' } : { text: '待齐备', tag: 'warning' }
  96. }
  97. export function hasPurchaseCert(product) {
  98. const url = product?.purchaseCertUrl || product?.purchase_cert_url
  99. return !!(url && String(url).trim())
  100. }