Commit e25de2ce by 张立顺

fix: 对齐子表单多选PAD协议

1 parent 36794957
......@@ -439,6 +439,20 @@ function findStaticOption(field = {}, rawId) {
)
}
function resolveStaticMultipleSelectValue(field = {}, rawId, fallbackText = '') {
const matched = findStaticOption(field, rawId)
if (matched) {
return String(matched.value ?? matched.id ?? rawId)
}
if (fallbackText !== '') {
const matchedByText = findStaticOption(field, fallbackText)
if (matchedByText) {
return String(matchedByText.value ?? matchedByText.id ?? fallbackText)
}
}
return String(rawId)
}
function scalarToSelectObject(field = {}, rawValue) {
const scalar = coerceSelectValue(rawValue)
if (scalar === '' || scalar == null) {
......@@ -901,7 +915,19 @@ function buildNormalizedSubformDataEntry({ parentField, rowIndex, child, fieldVa
if (normalizedValue === undefined || normalizedValue === null || normalizedValue === '') {
return null
}
const serialized = serializeFieldValueForStorage(normalizedValue, storageType)
let storageValue = normalizedValue
if (child.type === 'multipleSelect' && Array.isArray(normalizedValue)) {
const ids = normalizedValue
.map(item => isPlainObject(item) ? item.id ?? item.value : item)
.filter(value => value != null && value !== '')
const names = normalizedValue
.map(item => isPlainObject(item) ? item.name ?? item.label ?? item.id : item)
.filter(value => value != null && value !== '')
storageValue = ids.length || names.length
? [{ id: ids.join('/'), name: names.join('/') }]
: undefined
}
const serialized = serializeFieldValueForStorage(storageValue, storageType)
if (serialized === '') return null
return {
parentFieldKey: parentField.key,
......@@ -1147,6 +1173,36 @@ export function rowFieldsToChildrenValueRow(groupKey, rowFields = []) {
return
}
const fk = field.key
if (field.type === 'multipleSelect') {
const rawValue = resolveAppRowFieldEngineValue(field)
const selected = coerceMultipleSelectValue(rawValue)
if (!Array.isArray(selected) || !selected.length) {
rowBag[groupKey][fk] = ''
return
}
const ids = []
const labels = []
selected.forEach(item => {
if (isPlainObject(item)) {
const id = resolveOptionId(item)
const name = resolveOptionName(item)
if (id !== '' || name !== '') {
ids.push(String(id || name))
labels.push(String(name || id))
}
return
}
const id = String(item)
const matched = findStaticOption(field, id)
ids.push(id)
labels.push(String(matched?.label ?? matched?.name ?? id))
})
rowBag[groupKey][fk] = {
text: labels.join('/'),
value: ids
}
return
}
if (isRemoteSelectField(field)) {
const pair = resolveRemoteSelectTextAndId(field)
if (pair) {
......@@ -1209,7 +1265,18 @@ export function childrenValueToRowFieldsList(section = {}) {
} else if (typeof val === 'string') {
item.value = val
} else if (typeof val === 'object') {
item.value = val.text
if (item.type === 'multipleSelect' && Array.isArray(val.value)) {
if (isRemoteMultipleSelectField(item)) {
item.value = val.text
} else {
const labels = splitMultipleSelectDisplayLabel(val.text)
item.value = val.value.map((rawId, index) =>
resolveStaticMultipleSelectValue(item, rawId, labels[index] ?? '')
)
}
} else {
item.value = val.text
}
if (val.value != null && val.value !== '') {
item[fk] = isPlainObject(val.value)
? extractSelectIdAndLabel(val.value, val.text).id ?? val.value
......
......@@ -7,6 +7,7 @@ import {
buildAppFieldDataListFromJsonContent,
buildAppSubformDataListFromJsonContent,
extractStorageValuesFromJsonContent,
getSectionRowFieldsList,
serializeFormListForAppJsonStorage,
buildAppJsonContent,
buildAppDailyReportSubmitPayload
......@@ -308,14 +309,16 @@ describe('App save lists from jsonContent', () => {
const payload = buildAppDailyReportSubmitPayload(formList)
const storedTags = JSON.parse(payload.jsonContent)[0]
.childrenValue[0]['F2-107']['F2-107-7']
assert.deepEqual(storedTags, ['已触客', '已拉群'])
assert.deepEqual(storedTags, {
text: '已触客/已拉群',
value: ['已触客', '已拉群']
})
const tagListItem = payload.subformDataList.find(item =>
item.parentFieldKey === 'F2-107' && item.columnFieldKey === 'F2-107-7'
)
assert.deepEqual(JSON.parse(tagListItem.fieldValue), [
{ id: '已触客', name: '已触客' },
{ id: '已拉群', name: '已拉群' }
{ id: '已触客/已拉群', name: '已触客/已拉群' }
])
})
......@@ -364,7 +367,7 @@ describe('App save lists from jsonContent', () => {
const payload = buildAppDailyReportSubmitPayload(formList)
assert.deepEqual(
JSON.parse(payload.jsonContent)[0].childrenValue[0]['F2-107']['F2-107-7'],
[{ id: 'tag-contacted', name: '已触客' }]
{ text: '已触客', value: ['tag-contacted'] }
)
const tagListItem = payload.subformDataList.find(item =>
item.parentFieldKey === 'F2-107' && item.columnFieldKey === 'F2-107-7'
......@@ -372,6 +375,11 @@ describe('App save lists from jsonContent', () => {
assert.deepEqual(JSON.parse(tagListItem.fieldValue), [
{ id: 'tag-contacted', name: '已触客' }
])
const savedSection = JSON.parse(payload.jsonContent)[0]
const echoedRow = getSectionRowFieldsList(savedSection)[0]
const echoedTags = echoedRow.find(field => field.key === 'F2-107-7')
assert.deepEqual(echoedTags.value, ['已触客'])
})
it('IT-APP-LISTS-F2107-005: object-array customer tags drive dependent childrenShowRules on save', () => {
......
......@@ -274,7 +274,7 @@ describe('Store V2.3 delivery-date context visibility', () => {
it('IT-V230-CONTEXT-011: static customer tags and uncontacted reason echo after save', () => {
const ctx = context(100101, [FIVE_REALM_ID])
const engine = createRowEngine(ctx, '交付端引流-售前', null)
engine.setGroupFieldValue('F2-107', 0, CUSTOMER_TAGS_KEY, ['已拉群'])
engine.setGroupFieldValue('F2-107', 0, CUSTOMER_TAGS_KEY, ['已拉群', '已触客'])
engine.setGroupFieldValue('F2-107', 0, 'F2-107-17', '客户暂未回复')
const payload = buildDynamicSavePayload({
......@@ -282,12 +282,54 @@ describe('Store V2.3 delivery-date context visibility', () => {
engine,
normalizedFieldDataList: true
})
const savedSection = JSON.parse(payload.jsonContent)
.find(field => field.key === 'F2-107')
const savedTags = savedSection.childrenValue[0]['F2-107'][CUSTOMER_TAGS_KEY]
assert.deepEqual(savedTags, {
text: '已拉群/已触客',
value: ['已拉群', '已触客']
})
const customerTagListItem = payload.subformDataList.find(item =>
item.parentFieldKey === 'F2-107' && item.columnFieldKey === CUSTOMER_TAGS_KEY
)
assert.deepEqual(JSON.parse(customerTagListItem.fieldValue), [
{ id: '已拉群/已触客', name: '已拉群/已触客' }
])
const initialValues = parseJsonContentDetailValues(payload.jsonContent, schema.list)
const reloaded = createFormEngine(structuredClone(schema))
reloaded.init(structuredClone(schema), { ...ctx, initialValues })
assert.deepEqual(reloaded.getValues()['F2-107'][0][CUSTOMER_TAGS_KEY], ['已拉群'])
assert.equal(reloaded.getValues()['F2-107'][0]['F2-107-17'], '客户暂未回复')
assert.ok(visibleRowKeys(reloaded).includes('F2-107-17'))
assert.deepEqual(reloaded.getValues()['F2-107'][0][CUSTOMER_TAGS_KEY], [
'已拉群', '已触客'
])
assert.equal(reloaded.getValues()['F2-107'][0]['F2-107-17'], undefined)
assert.ok(!visibleRowKeys(reloaded).includes('F2-107-17'))
})
it('IT-V230-CONTEXT-012: PAD dual-key customer tags echo as an internal array', () => {
const ctx = context(100101, [FIVE_REALM_ID])
const detailJson = JSON.stringify([{
key: 'F2-107',
label: '今日非成交客户',
type: 'subform',
origin_children: schema.list.find(field => field.key === 'F2-107').children[0],
childrenValue: [{
'F2-107': {
'F2-107-3': '交付端引流-售前',
[CUSTOMER_TAGS_KEY]: {
text: '已拉群/已触客',
value: ['已拉群', '已触客']
}
}
}]
}])
const initialValues = parseJsonContentDetailValues(detailJson, schema.list)
const engine = createFormEngine(structuredClone(schema))
engine.init(structuredClone(schema), { ...ctx, initialValues })
assert.deepEqual(engine.getValues()['F2-107'][0][CUSTOMER_TAGS_KEY], [
'已拉群', '已触客'
])
})
})
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!