|
|
@@ -1,7 +1,7 @@
|
|
|
/** 协议样本及运输:对齐 Web sample-transport-form-section 的纯函数 */
|
|
|
|
|
|
import { moneyInputText } from '../oa/money-field-model.js'
|
|
|
-import { compareMoney, normalizeMoney } from './money.js'
|
|
|
+import { compareMoney, formatMoney, normalizeMoney } from './money.js'
|
|
|
|
|
|
export const SAMPLE_STATUS_OPTIONS = Object.freeze([
|
|
|
{ label: '已采集', value: 'ycj' },
|
|
|
@@ -96,23 +96,37 @@ export function partitionFreightConfigSamples(samples) {
|
|
|
return { configurable, skipped }
|
|
|
}
|
|
|
|
|
|
-export function buildFreightDraft({ transportMode, freightAmount, clientKey } = {}) {
|
|
|
+export function buildFreightDraft({ transportMode, freightAmount, waybillNo, clientKey } = {}) {
|
|
|
+ const mode = String(transportMode || '').trim()
|
|
|
+ const sfExpress = mode === 'sfkd'
|
|
|
return {
|
|
|
clientKey: clientKey || `fd_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
|
|
|
- transportMode: String(transportMode || '').trim(),
|
|
|
- freightAmount: normalizeConstrainedMoney(freightAmount)
|
|
|
+ transportMode: mode,
|
|
|
+ freightAmount: sfExpress ? null : normalizeConstrainedMoney(freightAmount),
|
|
|
+ waybillNo: sfExpress ? String(waybillNo || '').trim() : ''
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-export function buildFreightCreatePayload({ transportMode, freightAmount, items } = {}) {
|
|
|
- const draft = buildFreightDraft({ transportMode, freightAmount })
|
|
|
+export function buildFreightCreatePayload({ transportMode, freightAmount, waybillNo, items } = {}) {
|
|
|
+ const draft = buildFreightDraft({ transportMode, freightAmount, waybillNo })
|
|
|
return {
|
|
|
transportMode: draft.transportMode,
|
|
|
freightAmount: draft.freightAmount,
|
|
|
+ waybillNo: draft.waybillNo,
|
|
|
items: Array.isArray(items) ? items : []
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/** 运费关联只提交样本身份;协议与样本编码由服务端派生 */
|
|
|
+export function buildFreightItemBodies(rows, sampleSource) {
|
|
|
+ return (rows || [])
|
|
|
+ .map((row) => ({
|
|
|
+ sampleSource: String(row?.sampleSource || sampleSource || '').trim(),
|
|
|
+ sampleId: String(row?.sampleId || row?.id || '').trim()
|
|
|
+ }))
|
|
|
+ .filter((item) => item.sampleSource && item.sampleId)
|
|
|
+}
|
|
|
+
|
|
|
function freightTargetKey(row) {
|
|
|
return String(row?.id || row?._key || '').trim()
|
|
|
}
|
|
|
@@ -132,8 +146,15 @@ export function applyFreightAssignments(samples, assignments) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-export function validateFreightForm({ transportMode, freightAmount } = {}) {
|
|
|
- if (!String(transportMode || '').trim()) return '请选择运输方式'
|
|
|
+export function validateFreightForm({ transportMode, freightAmount, waybillNo } = {}) {
|
|
|
+ const mode = String(transportMode || '').trim()
|
|
|
+ if (!mode) return '请选择运输方式'
|
|
|
+ if (mode === 'sfkd') {
|
|
|
+ const waybill = String(waybillNo || '').trim()
|
|
|
+ if (!waybill) return '请填写顺丰单号'
|
|
|
+ if (waybill.length > 64) return '顺丰单号不能超过 64 个字符'
|
|
|
+ return ''
|
|
|
+ }
|
|
|
const rawAmount = freightAmount == null ? '' : String(freightAmount).trim()
|
|
|
const amount = normalizeConstrainedMoney(rawAmount)
|
|
|
if (amount == null) {
|
|
|
@@ -142,9 +163,17 @@ export function validateFreightForm({ transportMode, freightAmount } = {}) {
|
|
|
return ''
|
|
|
}
|
|
|
|
|
|
+function freightAmountLabel(mode, amount) {
|
|
|
+ if (mode === 'sfkd' && (amount == null || amount === '')) return '月结'
|
|
|
+ if (amount == null || amount === '') return formatMoney(amount)
|
|
|
+ const formatted = formatMoney(amount)
|
|
|
+ return formatted && formatted !== '—' ? formatted : String(amount)
|
|
|
+}
|
|
|
+
|
|
|
export function freightDisplay(sample) {
|
|
|
const freight = sample?.freight || {}
|
|
|
const draft = sample?.freightDraft
|
|
|
+ const mode = String(freight.transportMode || draft?.transportMode || '').trim()
|
|
|
const modeLabel =
|
|
|
freight.transportModeLabel ||
|
|
|
freight.transportMode ||
|
|
|
@@ -158,7 +187,13 @@ export function freightDisplay(sample) {
|
|
|
: null
|
|
|
const linked = Number(freight.linkedSampleCount || 0)
|
|
|
const shared = linked > 1
|
|
|
- return { modeLabel, amount, shared, linkedSampleCount: linked }
|
|
|
+ return {
|
|
|
+ modeLabel,
|
|
|
+ amount,
|
|
|
+ amountLabel: freightAmountLabel(mode, amount),
|
|
|
+ shared,
|
|
|
+ linkedSampleCount: linked
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/** 「关联已有」列表:去重样本编码,超过 max 个时截断为「前 max 个等 N 个」 */
|
|
|
@@ -268,10 +303,13 @@ export function serializeSamplesForSave(samples) {
|
|
|
const freightId = String(row.freightId || row.freight?.id || '').trim()
|
|
|
if (freightId) next.freightId = freightId
|
|
|
if (row.freightDraft && typeof row.freightDraft === 'object' && !freightId) {
|
|
|
+ const draftMode = String(row.freightDraft.transportMode || '').trim()
|
|
|
+ const sfExpress = draftMode === 'sfkd'
|
|
|
next.freightDraft = {
|
|
|
clientKey: row.freightDraft.clientKey,
|
|
|
transportMode: row.freightDraft.transportMode,
|
|
|
- freightAmount: normalizeConstrainedMoney(row.freightDraft.freightAmount)
|
|
|
+ freightAmount: sfExpress ? null : normalizeConstrainedMoney(row.freightDraft.freightAmount),
|
|
|
+ waybillNo: sfExpress ? String(row.freightDraft.waybillNo || '').trim() : ''
|
|
|
}
|
|
|
}
|
|
|
return next
|