66 lines
2.2 KiB
JavaScript
66 lines
2.2 KiB
JavaScript
/** 地磅状态 / 重量展示 */
|
|
|
|
export function dash(val) {
|
|
if (val == null || val === '') return '—'
|
|
return String(val)
|
|
}
|
|
|
|
export function formatWeight(val, unit = 'kg') {
|
|
if (val == null || val === '') return '—'
|
|
const n = Number(val)
|
|
if (Number.isNaN(n)) return String(val)
|
|
return `${n.toLocaleString('zh-CN', { maximumFractionDigits: 2 })} ${unit}`
|
|
}
|
|
|
|
/** 地磅单阶段:作废 / 已完成 / 一次过磅 / 待过磅 */
|
|
export function weighingPhase(row) {
|
|
if (!row) return { text: '—', tag: 'muted' }
|
|
if (Number(row.isVoided) === 1) return { text: '已作废', tag: 'danger' }
|
|
const gross = Number(row.grossWeight) || 0
|
|
const tare = Number(row.tareWeight) || 0
|
|
if (gross > 0 && tare > 0) return { text: '已完成', tag: 'success' }
|
|
if (gross > 0) return { text: '一次过磅', tag: 'warning' }
|
|
return { text: '待过磅', tag: 'info' }
|
|
}
|
|
|
|
export function planStatusLabel(status) {
|
|
if (!status) return { text: '未开始', tag: 'muted' }
|
|
const s = String(status)
|
|
if (s.includes('已')) return { text: s, tag: 'success' }
|
|
if (s.includes('中')) return { text: s, tag: 'warning' }
|
|
if (s.includes('待')) return { text: s, tag: 'info' }
|
|
return { text: s, tag: 'muted' }
|
|
}
|
|
|
|
export function inventoryStatusLabel(status) {
|
|
if (!status) return { text: '—', tag: 'muted' }
|
|
const s = String(status)
|
|
if (s === '已完成') return { text: s, tag: 'success' }
|
|
if (s.includes('待')) return { text: s, tag: 'warning' }
|
|
return { text: s, tag: 'info' }
|
|
}
|
|
|
|
export function todayYmd() {
|
|
const d = new Date()
|
|
const m = `${d.getMonth() + 1}`.padStart(2, '0')
|
|
const day = `${d.getDate()}`.padStart(2, '0')
|
|
return `${d.getFullYear()}-${m}-${day}`
|
|
}
|
|
|
|
export function nowYmdHms() {
|
|
const d = new Date()
|
|
const pad = (n) => `${n}`.padStart(2, '0')
|
|
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`
|
|
}
|
|
|
|
/** 客户端关键词过滤(后端 list 多为全量) */
|
|
export function filterByKeyword(rows, keyword, fields) {
|
|
const kw = String(keyword || '')
|
|
.trim()
|
|
.toLowerCase()
|
|
if (!kw) return rows || []
|
|
return (rows || []).filter((row) =>
|
|
fields.some((f) => String(row[f] != null ? row[f] : '').toLowerCase().includes(kw))
|
|
)
|
|
}
|