subform-child-validation-value.js 1.25 KB
/** subform 单元格校验取值(App 双 key / carBrand 优先 meta) */
import { resolveCarBrandValueForValidation } from './car-brand-value.js'
import {
	getFieldTypeStrategy,
	resolveSubformChildValidationValue
} from './field-types/registry.js'
import {
	hasPlanImportDateMarker
} from './plan-import-date-value.js'

function hasMeaningfulRowValue(value) {
	return value !== undefined && value !== null && value !== ''
}

export function resolveSubformChildValue(child, row, rowField) {
	if (child?.type === 'carBrandSelect') {
		return resolveCarBrandValueForValidation(rowField, child.key, row?.[child.key])
	}
	if (getFieldTypeStrategy(child?.type)?.resolveValidationValue) {
		return resolveSubformChildValidationValue(child, rowField, row?.[child.key])
	}
	const isDateField = child?.type === 'date' || child?.type === 'datetime'
	if (isDateField) {
		if (rowField && hasPlanImportDateMarker(rowField.value)) {
			return rowField.value
		}
		const rowMapVal = row?.[child.key]
		if (hasPlanImportDateMarker(rowMapVal)) {
			return rowMapVal
		}
		const metaVal = rowField?.[child.key]
		if (hasPlanImportDateMarker(metaVal)) {
			return metaVal
		}
	}
	if (rowField && hasMeaningfulRowValue(rowField.value)) {
		return rowField.value
	}
	return row?.[child.key]
}