Commit 2328de0f by 张立顺

fix: 对齐门店日报App枚举与场景保存

1 parent 473fe958
# Store V2.3.0 Enum Mapping and Boutique Save Filter Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Make customer tags and customer source use PAD/App numeric IDs without changing their Chinese UI values, and prevent hidden negotiation product categories from being saved for an active boutique scene.
**Architecture:** Keep Chinese `option.value` as the mini-program engine value so existing `childrenShowRules` remain compatible, add numeric `option.id` as the PAD/App persistence value, and decode numeric IDs back to canonical Chinese values during detail echo. Apply child structural visibility again at the final subform save boundary, using the active `pageContext.baseSceneCode` instead of the merchant's full `sceneList` for persistence.
**Tech Stack:** WeChat Mini Program JavaScript, ESM form-engine modules, Node.js `node:test`, generated V2.3.0 JS/JSON fixtures.
## Global Constraints
- Customer tag IDs are exactly `1=已触客`, `2=已拉群`, `3=已交付引荐`, `4=首保维保客户`, `5=事故车客户`.
- Customer source IDs are `0=销售端引流-售前` in boutique scenes, `0=门店引流-售前` in warranty/equity scenes, `1=门店引流-售后`, and `3=交付端引流-售前`.
- `2=自然到店` must not be added to the template or App compatibility path.
- Preserve historical Chinese detail echo and the existing Chinese `childrenShowRules` expressions.
- When active `baseSceneCode` is `100101`, `100102`, or `100103`, `F2-107-12` must be absent from both `jsonContent` and `subformDataList`.
- Do not modify or include unrelated staged user changes.
---
### Task 1: Lock the V2.3.0 enumeration contract
**Files:**
- Modify: `packageDynamicForm/tests/store-v230-template-schema.test.mjs`
- Modify: `packageDynamicForm/fixtures/schema-store-daily-v2.3.0.js`
- Modify: `packageDynamicForm/fixtures/schema-store-daily-v2.3.0.json`
- Modify: `packageDynamicForm/fixtures/schema-store-daily-v2.3.0.prod.js`
- Modify: `packageDynamicForm/fixtures/schema-store-daily-v2.3.0.prod.json`
**Interfaces:**
- Consumes: existing V2.3.0 option-level `baseSceneCode`, `brandId`, `filterBrandId`, and `matchEffect` metadata.
- Produces: static options with Chinese `value`/`label` and numeric string `id`.
- [x] Add failing schema assertions for the exact tag/source `{id,value,label}` mappings, source scene metadata, and absence of natural-arrival ID `2`.
- [x] Run `node --test packageDynamicForm/tests/store-v230-template-schema.test.mjs` and verify the assertions fail because IDs are missing.
- [x] Add the mappings to all four V2.3.0 fixtures while preserving environment-specific brand IDs.
- [x] Run the schema test and verify JS fixtures remain parseable and identical to JSON fixture lists.
### Task 2: Persist numeric IDs and restore Chinese engine values
**Files:**
- Modify: `packageDynamicForm/tests/store-v230-context-visibility.test.mjs`
- Modify: `packageDynamicForm/form-engine/field-submit-value.js`
- Modify: `packageDynamicForm/form-engine/app-subform-json.js`
**Interfaces:**
- Consumes: static option `{id,label,value}` records and PAD wrappers `{text,value}`.
- Produces: tag `childrenValue={text:'已拉群/已触客',value:['2','1']}`, tag list value `[{id:'2/1',name:'已拉群/已触客'}]`, and source wrapper `{text:'...',value:'0'|'1'|'3'}`.
- [x] Add failing save/echo tests for numeric customer-tag IDs, duplicate source ID `0`, historical Chinese echo, and new PAD numeric echo.
- [x] Run the focused context test and verify it fails on Chinese persisted IDs.
- [x] Make static option lookup accept ID, canonical value, and display label, and make submit conversion prefer `option.id` while retaining `option.label` as the name.
- [x] Serialize ID-bearing static subform selects with PAD `{text,value}` and disambiguate duplicate IDs with the saved text/current canonical value.
- [x] Run focused App/PAD and V2.3.0 echo tests.
### Task 3: Filter structurally hidden subform cells at save time
**Files:**
- Modify: `packageDynamicForm/tests/store-v230-context-visibility.test.mjs`
- Modify: `packageDynamicForm/form-engine/app-subform-json.js`
**Interfaces:**
- Consumes: each child field's `baseSceneCode` and `pageContext.baseSceneCode`.
- Produces: row fields limited by both structural visibility and `childrenShowRules` before lists/JSON serialization.
- [x] Add a failing integration test with active boutique `baseSceneCode`, mixed merchant `sceneList`, and a stale `F2-107-12` value; assert both save representations omit it.
- [x] Add the warranty/equity control case and assert the value remains persistable there.
- [x] Run the test and verify the boutique assertion fails before implementation.
- [x] Add a generic active-scene structural save check before row-level `childrenShowRules` evaluation.
- [x] Re-run the focused test and the existing hidden-value persistence suite.
### Task 4: Verify and commit
**Files:**
- Test: `packageDynamicForm/tests/store-v230-template-schema.test.mjs`
- Test: `packageDynamicForm/tests/store-v230-context-visibility.test.mjs`
- Test: `packageDynamicForm/tests/app-save-lists-from-json.test.mjs`
- Test: `packageDynamicForm/tests/form-engine.test.mjs`
**Interfaces:**
- Consumes: completed template and codec changes.
- Produces: a focused commit containing only this feature's files.
- [x] Run the four focused test files and fix any behavioral regression.
- [x] Run `npm run test:dynamicForm` and inspect the final failure count.
- [x] Review `git diff` and confirm unrelated staged user files are excluded.
- [x] Commit only the V2.3.0 mapping/save-filter files with a scoped Chinese commit message.
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
const { fetchFieldOptions } = require('../../api/fieldOptionsService.js') const { fetchFieldOptions } = require('../../api/fieldOptionsService.js')
const { normalizeOptionRecord } = require('../../form-engine/field-submit-value.js') const { normalizeOptionRecord } = require('../../form-engine/field-submit-value.js')
const { getVisibleFieldOptions } = require('../../form-engine/option-visibility.js')
const { resolveSelectFieldState } = require('../form-picker-popup/select-display.js') const { resolveSelectFieldState } = require('../form-picker-popup/select-display.js')
const { const {
resolveOrderListSaleDate, resolveOrderListSaleDate,
...@@ -141,7 +142,18 @@ Component({ ...@@ -141,7 +142,18 @@ Component({
}, },
getStaticOptions() { getStaticOptions() {
return this.data.field?.options?.length ? this.data.field.options : [] const requestContext = this.data.requestContext || {}
const activeSceneCode = requestContext.baseSceneCode
const optionContext = activeSceneCode == null || activeSceneCode === ''
? requestContext
: {
...requestContext,
sceneList: [{ baseSceneCode: activeSceneCode }]
}
return getVisibleFieldOptions(
this.data.field || {},
optionContext
)
}, },
/** storeStaffList / 4sStaffList 弹框启用服务端姓名搜索(门店驻店人员、洽谈驻店人员、销售/交付专员) */ /** storeStaffList / 4sStaffList 弹框启用服务端姓名搜索(门店驻店人员、洽谈驻店人员、销售/交付专员) */
......
...@@ -43,10 +43,22 @@ function resolveSelectFieldState(field = {}, value, options = []) { ...@@ -43,10 +43,22 @@ function resolveSelectFieldState(field = {}, value, options = []) {
optionId = resolveValueId(value) optionId = resolveValueId(value)
} }
const matched = const valueId = resolveValueId(value)
optionId && options.length const matchedByValue = valueId && options.length
? options.find(item => String(item.value) === String(optionId)) ? options.find(item => [item.value, item.label, item.name]
: null .some(alias => alias != null && alias !== '' && String(alias) === String(valueId)))
: null
const matchedById = optionId && options.length
? options.find(item => [item.value, item.id]
.some(alias => alias != null && alias !== '' && String(alias) === String(optionId)))
: null
const isStaticEnumeration = !field?.optionsKey || field.optionsKey === 'options'
const matched = isStaticEnumeration
? matchedByValue || matchedById
: matchedById || matchedByValue
if (matchedByValue && (isStaticEnumeration || !matchedById)) {
optionId = matchedByValue.value ?? matchedByValue.id ?? optionId
}
let displayLabel = '' let displayLabel = ''
......
...@@ -250,20 +250,28 @@ ...@@ -250,20 +250,28 @@
baseSceneCode: [], baseSceneCode: [],
options: [ options: [
{ {
id: '0',
label: '销售端引流-售前', label: '销售端引流-售前',
value: '销售端引流-售前' value: '销售端引流-售前',
baseSceneCode: [100101, 100102, 100103]
}, },
{ {
id: '3',
label: '交付端引流-售前', label: '交付端引流-售前',
value: '交付端引流-售前' value: '交付端引流-售前',
baseSceneCode: [100101, 100102, 100103]
}, },
{ {
id: '0',
label: '门店引流-售前', label: '门店引流-售前',
value: '门店引流-售前' value: '门店引流-售前',
baseSceneCode: [110101, 110102, 110201, 110202]
}, },
{ {
id: '1',
label: '门店引流-售后', label: '门店引流-售后',
value: '门店引流-售后' value: '门店引流-售后',
baseSceneCode: [110101, 110102, 110201, 110202]
} }
], ],
rules: {}, rules: {},
...@@ -328,16 +336,19 @@ ...@@ -328,16 +336,19 @@
baseSceneCode: [], baseSceneCode: [],
options: [ options: [
{ {
id: '1',
label: '已触客', label: '已触客',
value: '已触客' value: '已触客'
}, },
{ {
id: '2',
label: '已拉群', label: '已拉群',
value: '已拉群', value: '已拉群',
baseSceneCode: [100101, 100102, 100103], baseSceneCode: [100101, 100102, 100103],
brandId: [3454, 3503, 3458, 3574, 3502] brandId: [3454, 3503, 3458, 3574, 3502]
}, },
{ {
id: '3',
label: '已交付引荐', label: '已交付引荐',
value: '已交付引荐', value: '已交付引荐',
baseSceneCode: [100101, 100102, 100103], baseSceneCode: [100101, 100102, 100103],
...@@ -345,12 +356,14 @@ ...@@ -345,12 +356,14 @@
matchEffect: 'exclude' matchEffect: 'exclude'
}, },
{ {
id: '4',
label: '首保维保客户', label: '首保维保客户',
value: '首保维保客户', value: '首保维保客户',
baseSceneCode: [100101, 100102, 100103], baseSceneCode: [100101, 100102, 100103],
brandId: [3454, 3503, 3458, 3574, 3502] brandId: [3454, 3503, 3458, 3574, 3502]
}, },
{ {
id: '5',
label: '事故车客户', label: '事故车客户',
value: '事故车客户', value: '事故车客户',
baseSceneCode: [100101, 100102, 100103], baseSceneCode: [100101, 100102, 100103],
......
...@@ -186,20 +186,28 @@ ...@@ -186,20 +186,28 @@
"rules": {}, "rules": {},
"options": [ "options": [
{ {
"id": "0",
"label": "销售端引流-售前", "label": "销售端引流-售前",
"value": "销售端引流-售前" "value": "销售端引流-售前",
"baseSceneCode": [100101, 100102, 100103]
}, },
{ {
"id": "3",
"label": "交付端引流-售前", "label": "交付端引流-售前",
"value": "交付端引流-售前" "value": "交付端引流-售前",
"baseSceneCode": [100101, 100102, 100103]
}, },
{ {
"id": "0",
"label": "门店引流-售前", "label": "门店引流-售前",
"value": "门店引流-售前" "value": "门店引流-售前",
"baseSceneCode": [110101, 110102, 110201, 110202]
}, },
{ {
"id": "1",
"label": "门店引流-售后", "label": "门店引流-售后",
"value": "门店引流-售后" "value": "门店引流-售后",
"baseSceneCode": [110101, 110102, 110201, 110202]
} }
] ]
}, },
...@@ -263,10 +271,12 @@ ...@@ -263,10 +271,12 @@
"rules": {}, "rules": {},
"options": [ "options": [
{ {
"id": "1",
"label": "已触客", "label": "已触客",
"value": "已触客" "value": "已触客"
}, },
{ {
"id": "2",
"label": "已拉群", "label": "已拉群",
"value": "已拉群", "value": "已拉群",
"baseSceneCode": [ "baseSceneCode": [
...@@ -283,6 +293,7 @@ ...@@ -283,6 +293,7 @@
] ]
}, },
{ {
"id": "3",
"label": "已交付引荐", "label": "已交付引荐",
"value": "已交付引荐", "value": "已交付引荐",
"baseSceneCode": [ "baseSceneCode": [
...@@ -300,6 +311,7 @@ ...@@ -300,6 +311,7 @@
"matchEffect": "exclude" "matchEffect": "exclude"
}, },
{ {
"id": "4",
"label": "首保维保客户", "label": "首保维保客户",
"value": "首保维保客户", "value": "首保维保客户",
"baseSceneCode": [ "baseSceneCode": [
...@@ -316,6 +328,7 @@ ...@@ -316,6 +328,7 @@
] ]
}, },
{ {
"id": "5",
"label": "事故车客户", "label": "事故车客户",
"value": "事故车客户", "value": "事故车客户",
"baseSceneCode": [ "baseSceneCode": [
......
...@@ -250,20 +250,28 @@ ...@@ -250,20 +250,28 @@
baseSceneCode: [], baseSceneCode: [],
options: [ options: [
{ {
id: '0',
label: '销售端引流-售前', label: '销售端引流-售前',
value: '销售端引流-售前' value: '销售端引流-售前',
baseSceneCode: [100101, 100102, 100103]
}, },
{ {
id: '3',
label: '交付端引流-售前', label: '交付端引流-售前',
value: '交付端引流-售前' value: '交付端引流-售前',
baseSceneCode: [100101, 100102, 100103]
}, },
{ {
id: '0',
label: '门店引流-售前', label: '门店引流-售前',
value: '门店引流-售前' value: '门店引流-售前',
baseSceneCode: [110101, 110102, 110201, 110202]
}, },
{ {
id: '1',
label: '门店引流-售后', label: '门店引流-售后',
value: '门店引流-售后' value: '门店引流-售后',
baseSceneCode: [110101, 110102, 110201, 110202]
} }
], ],
rules: {}, rules: {},
...@@ -328,16 +336,19 @@ ...@@ -328,16 +336,19 @@
baseSceneCode: [], baseSceneCode: [],
options: [ options: [
{ {
id: '1',
label: '已触客', label: '已触客',
value: '已触客' value: '已触客'
}, },
{ {
id: '2',
label: '已拉群', label: '已拉群',
value: '已拉群', value: '已拉群',
baseSceneCode: [100101, 100102, 100103], baseSceneCode: [100101, 100102, 100103],
brandId: [2695, 2741, 2698, 2797, 2740] brandId: [2695, 2741, 2698, 2797, 2740]
}, },
{ {
id: '3',
label: '已交付引荐', label: '已交付引荐',
value: '已交付引荐', value: '已交付引荐',
baseSceneCode: [100101, 100102, 100103], baseSceneCode: [100101, 100102, 100103],
...@@ -345,12 +356,14 @@ ...@@ -345,12 +356,14 @@
matchEffect: 'exclude' matchEffect: 'exclude'
}, },
{ {
id: '4',
label: '首保维保客户', label: '首保维保客户',
value: '首保维保客户', value: '首保维保客户',
baseSceneCode: [100101, 100102, 100103], baseSceneCode: [100101, 100102, 100103],
brandId: [2695, 2741, 2698, 2797, 2740] brandId: [2695, 2741, 2698, 2797, 2740]
}, },
{ {
id: '5',
label: '事故车客户', label: '事故车客户',
value: '事故车客户', value: '事故车客户',
baseSceneCode: [100101, 100102, 100103], baseSceneCode: [100101, 100102, 100103],
......
...@@ -186,20 +186,28 @@ ...@@ -186,20 +186,28 @@
"rules": {}, "rules": {},
"options": [ "options": [
{ {
"id": "0",
"label": "销售端引流-售前", "label": "销售端引流-售前",
"value": "销售端引流-售前" "value": "销售端引流-售前",
"baseSceneCode": [100101, 100102, 100103]
}, },
{ {
"id": "3",
"label": "交付端引流-售前", "label": "交付端引流-售前",
"value": "交付端引流-售前" "value": "交付端引流-售前",
"baseSceneCode": [100101, 100102, 100103]
}, },
{ {
"id": "0",
"label": "门店引流-售前", "label": "门店引流-售前",
"value": "门店引流-售前" "value": "门店引流-售前",
"baseSceneCode": [110101, 110102, 110201, 110202]
}, },
{ {
"id": "1",
"label": "门店引流-售后", "label": "门店引流-售后",
"value": "门店引流-售后" "value": "门店引流-售后",
"baseSceneCode": [110101, 110102, 110201, 110202]
} }
] ]
}, },
...@@ -263,10 +271,12 @@ ...@@ -263,10 +271,12 @@
"rules": {}, "rules": {},
"options": [ "options": [
{ {
"id": "1",
"label": "已触客", "label": "已触客",
"value": "已触客" "value": "已触客"
}, },
{ {
"id": "2",
"label": "已拉群", "label": "已拉群",
"value": "已拉群", "value": "已拉群",
"baseSceneCode": [ "baseSceneCode": [
...@@ -283,6 +293,7 @@ ...@@ -283,6 +293,7 @@
] ]
}, },
{ {
"id": "3",
"label": "已交付引荐", "label": "已交付引荐",
"value": "已交付引荐", "value": "已交付引荐",
"baseSceneCode": [ "baseSceneCode": [
...@@ -300,6 +311,7 @@ ...@@ -300,6 +311,7 @@
"matchEffect": "exclude" "matchEffect": "exclude"
}, },
{ {
"id": "4",
"label": "首保维保客户", "label": "首保维保客户",
"value": "首保维保客户", "value": "首保维保客户",
"baseSceneCode": [ "baseSceneCode": [
...@@ -316,6 +328,7 @@ ...@@ -316,6 +328,7 @@
] ]
}, },
{ {
"id": "5",
"label": "事故车客户", "label": "事故车客户",
"value": "事故车客户", "value": "事故车客户",
"baseSceneCode": [ "baseSceneCode": [
......
...@@ -432,24 +432,30 @@ function normalizeOptionRecord(option = {}) { ...@@ -432,24 +432,30 @@ function normalizeOptionRecord(option = {}) {
return next return next
} }
function findStaticOption(field = {}, rawId) { function staticOptionMatches(option = {}, rawValue) {
const str = String(rawId) if (rawValue == null || rawValue === '') return false
return (field.options || []).find( const str = String(rawValue)
option => String(option.value) === str || String(option.id) === str return [option.value, option.id, option.label, option.name]
) .some(alias => alias != null && alias !== '' && String(alias) === str)
}
function findStaticOption(field = {}, rawId, fallbackText = '') {
const options = field.options || []
if (fallbackText !== '') {
const matchedByText = options.find(option =>
[option.value, option.label, option.name]
.some(alias => alias != null && alias !== '' && String(alias) === String(fallbackText))
)
if (matchedByText) return matchedByText
}
return options.find(option => staticOptionMatches(option, rawId))
} }
function resolveStaticMultipleSelectValue(field = {}, rawId, fallbackText = '') { function resolveStaticMultipleSelectValue(field = {}, rawId, fallbackText = '') {
const matched = findStaticOption(field, rawId) const matched = findStaticOption(field, rawId, fallbackText)
if (matched) { if (matched) {
return String(matched.value ?? matched.id ?? rawId) 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) return String(rawId)
} }
...@@ -460,8 +466,8 @@ function scalarToSelectObject(field = {}, rawValue) { ...@@ -460,8 +466,8 @@ function scalarToSelectObject(field = {}, rawValue) {
} }
const matched = findStaticOption(field, scalar) const matched = findStaticOption(field, scalar)
return { return {
id: String(scalar), id: String(matched?.id ?? matched?.value ?? scalar),
name: matched?.label ?? matched?.name ?? String(scalar) name: matched?.label ?? matched?.name ?? matched?.value ?? String(scalar)
} }
} }
...@@ -729,7 +735,16 @@ function buildSelectSubmitValue(field = {}, rawValue) { ...@@ -729,7 +735,16 @@ function buildSelectSubmitValue(field = {}, rawValue) {
function itemToSelectObject(field = {}, item) { function itemToSelectObject(field = {}, item) {
if (isPlainObject(item)) { if (isPlainObject(item)) {
return normalizeOptionRecord(item) const normalized = normalizeOptionRecord(item)
if (!normalized) return null
if (isRemoteMultipleSelectField(field) || isRemoteSelectField(field)) return normalized
const matched = findStaticOption(field, normalized.id, normalized.name)
if (!matched) return normalized
return {
...normalized,
id: String(matched.id ?? matched.value ?? normalized.id),
name: String(matched.label ?? matched.name ?? matched.value ?? normalized.name)
}
} }
return scalarToSelectObject(field, item) return scalarToSelectObject(field, item)
} }
...@@ -1184,16 +1199,22 @@ export function rowFieldsToChildrenValueRow(groupKey, rowFields = []) { ...@@ -1184,16 +1199,22 @@ export function rowFieldsToChildrenValueRow(groupKey, rowFields = []) {
const labels = [] const labels = []
selected.forEach(item => { selected.forEach(item => {
if (isPlainObject(item)) { if (isPlainObject(item)) {
const id = resolveOptionId(item) const rawId = resolveOptionId(item)
const name = resolveOptionName(item) const rawName = resolveOptionName(item)
const matched = isRemoteMultipleSelectField(field)
? null
: findStaticOption(field, rawId, rawName)
const id = matched?.id ?? matched?.value ?? rawId
const name = matched?.label ?? matched?.name ?? matched?.value ?? rawName
if (id !== '' || name !== '') { if (id !== '' || name !== '') {
ids.push(String(id || name)) ids.push(String(id || name))
labels.push(String(name || id)) labels.push(String(name || id))
} }
return return
} }
const id = String(item) const rawValue = String(item)
const matched = findStaticOption(field, id) const matched = findStaticOption(field, rawValue)
const id = String(matched?.id ?? matched?.value ?? rawValue)
ids.push(id) ids.push(id)
labels.push(String(matched?.label ?? matched?.name ?? id)) labels.push(String(matched?.label ?? matched?.name ?? id))
}) })
...@@ -1203,6 +1224,18 @@ export function rowFieldsToChildrenValueRow(groupKey, rowFields = []) { ...@@ -1203,6 +1224,18 @@ export function rowFieldsToChildrenValueRow(groupKey, rowFields = []) {
} }
return return
} }
if (field.type === 'select' && !isRemoteSelectField(field)) {
const text = field.value ?? ''
const rawId = field[fk] ?? resolveAppRowFieldEngineValue(field)
const matched = findStaticOption(field, rawId, text)
if (matched?.id != null && matched.id !== '') {
rowBag[groupKey][fk] = {
text: String(text || matched.label || matched.name || matched.value || matched.id),
value: String(matched.id)
}
return
}
}
if (isRemoteSelectField(field)) { if (isRemoteSelectField(field)) {
const pair = resolveRemoteSelectTextAndId(field) const pair = resolveRemoteSelectTextAndId(field)
if (pair) { if (pair) {
...@@ -1954,6 +1987,18 @@ function filterVisibleRowFieldsForJson( ...@@ -1954,6 +1987,18 @@ function filterVisibleRowFieldsForJson(
) )
} }
function isFieldVisibleForActiveSaveScene(field = {}, pageContext = {}) {
const configured = Array.isArray(field.baseSceneCode)
? field.baseSceneCode
: field.baseSceneCode == null || field.baseSceneCode === ''
? []
: [field.baseSceneCode]
if (!configured.length) return true
const activeSceneCode = pageContext.baseSceneCode
if (activeSceneCode == null || activeSceneCode === '') return true
return configured.some(code => String(code) === String(activeSceneCode))
}
/** 从 engine 组装 App 形态 jsonContent(subform.children) */ /** 从 engine 组装 App 形态 jsonContent(subform.children) */
export function buildAppJsonContent(visibleList = [], groupRowsCache = {}, pageContext = {}) { export function buildAppJsonContent(visibleList = [], groupRowsCache = {}, pageContext = {}) {
const sections = [] const sections = []
...@@ -1968,7 +2013,10 @@ export function buildAppJsonContent(visibleList = [], groupRowsCache = {}, pageC ...@@ -1968,7 +2013,10 @@ export function buildAppJsonContent(visibleList = [], groupRowsCache = {}, pageC
delete section.value delete section.value
const children = cloneRowFieldsList(rowFieldsList).map(row => { const children = cloneRowFieldsList(rowFieldsList).map(row => {
const optionFilteredRow = row.map(cell => const structurallyVisibleRow = row.filter(cell =>
isFieldVisibleForActiveSaveScene(cell, pageContext)
)
const optionFilteredRow = structurallyVisibleRow.map(cell =>
filterAppFieldValueByOptionVisibility(cell, pageContext) filterAppFieldValueByOptionVisibility(cell, pageContext)
) )
const rowMap = rowFieldsToStorageValueMap(optionFilteredRow) const rowMap = rowFieldsToStorageValueMap(optionFilteredRow)
...@@ -1983,9 +2031,15 @@ export function buildAppJsonContent(visibleList = [], groupRowsCache = {}, pageC ...@@ -1983,9 +2031,15 @@ export function buildAppJsonContent(visibleList = [], groupRowsCache = {}, pageC
section.children = children section.children = children
if (Array.isArray(field.origin_children) && field.origin_children.length) { if (Array.isArray(field.origin_children) && field.origin_children.length) {
section.origin_children = sanitizeOriginChildrenColumn(field.origin_children) section.origin_children = sanitizeOriginChildrenColumn(
field.origin_children.filter(child =>
isFieldVisibleForActiveSaveScene(child, pageContext)
)
)
} else { } else {
const columnTemplate = getSubformRowTemplateForAdd(field) const columnTemplate = getSubformRowTemplateForAdd(field).filter(child =>
isFieldVisibleForActiveSaveScene(child, pageContext)
)
if (columnTemplate.length) { if (columnTemplate.length) {
section.origin_children = sanitizeOriginChildrenColumn(columnTemplate) section.origin_children = sanitizeOriginChildrenColumn(columnTemplate)
} }
......
...@@ -47,7 +47,11 @@ export function normalizeOptionRecord(option = {}) { ...@@ -47,7 +47,11 @@ export function normalizeOptionRecord(option = {}) {
function findStaticOption(field = {}, rawId) { function findStaticOption(field = {}, rawId) {
const str = String(rawId) const str = String(rawId)
return (field.options || []).find( return (field.options || []).find(
option => String(option.value) === str || String(option.id) === str option =>
String(option.value) === str ||
String(option.id) === str ||
String(option.label) === str ||
String(option.name) === str
) )
} }
...@@ -58,8 +62,8 @@ function scalarToSelectObject(field = {}, rawValue) { ...@@ -58,8 +62,8 @@ function scalarToSelectObject(field = {}, rawValue) {
} }
const matched = findStaticOption(field, scalar) const matched = findStaticOption(field, scalar)
return { return {
id: String(scalar), id: String(matched?.id ?? matched?.value ?? scalar),
name: matched?.label ?? matched?.name ?? String(scalar) name: matched?.label ?? matched?.name ?? matched?.value ?? String(scalar)
} }
} }
...@@ -152,7 +156,17 @@ export function buildSelectSubmitValue(field = {}, rawValue) { ...@@ -152,7 +156,17 @@ export function buildSelectSubmitValue(field = {}, rawValue) {
function itemToSelectObject(field = {}, item) { function itemToSelectObject(field = {}, item) {
if (isPlainObject(item)) { if (isPlainObject(item)) {
return normalizeOptionRecord(item) const normalized = normalizeOptionRecord(item)
if (!normalized) return null
if (field.optionsKey && field.optionsKey !== 'options') return normalized
const matched = findStaticOption(field, normalized.name) ||
findStaticOption(field, normalized.id)
if (!matched) return normalized
return {
...normalized,
id: String(matched.id ?? matched.value ?? normalized.id),
name: String(matched.label ?? matched.name ?? matched.value ?? normalized.name)
}
} }
return scalarToSelectObject(field, item) return scalarToSelectObject(field, item)
} }
......
...@@ -67,6 +67,7 @@ describe('app-subform-json', async () => { ...@@ -67,6 +67,7 @@ describe('app-subform-json', async () => {
formatFieldForAppJsonContent, formatFieldForAppJsonContent,
buildAppCarBrandDisplayString, buildAppCarBrandDisplayString,
buildAppJsonContent, buildAppJsonContent,
rowFieldsToChildrenValueRow,
mergeAppJsonIntoSchema, mergeAppJsonIntoSchema,
getEchoSubformKeysFromJsonContent getEchoSubformKeysFromJsonContent
} = await import('../form-engine/app-subform-json.js') } = await import('../form-engine/app-subform-json.js')
...@@ -143,6 +144,23 @@ describe('app-subform-json', async () => { ...@@ -143,6 +144,23 @@ describe('app-subform-json', async () => {
assert.deepEqual(formatted['F2-1'], ['staff-001', 'staff-002']) assert.deepEqual(formatted['F2-1'], ['staff-001', 'staff-002'])
}) })
it('IT-APP-003c: childrenValue keeps authoritative ids for remote same-name staff', () => {
const row = rowFieldsToChildrenValueRow('F2-1', [{
key: 'F2-1-1',
type: 'multipleSelect',
optionsKey: 'storeStaffList',
options: [
{ id: 'u-1', name: '张三', value: 'u-1', label: '张三' },
{ id: 'u-2', name: '张三', value: 'u-2', label: '张三' }
],
value: [{ id: 'u-2', name: '张三' }]
}])
assert.deepEqual(row['F2-1']['F2-1-1'], {
text: '张三',
value: ['u-2']
})
})
it('IT-APP-004: parseJsonContentDetailValues from App children', () => { it('IT-APP-004: parseJsonContentDetailValues from App children', () => {
const values = parseJsonContentDetailValues( const values = parseJsonContentDetailValues(
JSON.stringify([ JSON.stringify([
......
...@@ -46,6 +46,20 @@ describe('field-submit-value', async () => { ...@@ -46,6 +46,20 @@ describe('field-submit-value', async () => {
assert.deepEqual(buildMultipleSelectSubmitValue(field, value), value) assert.deepEqual(buildMultipleSelectSubmitValue(field, value), value)
}) })
it('IT-SUBMIT-003b: remote same-name staff keeps each selected id', () => {
const field = {
type: 'multipleSelect',
optionsKey: 'storeStaffList',
options: [
{ id: 'u-1', name: '张三', value: 'u-1', label: '张三' },
{ id: 'u-2', name: '张三', value: 'u-2', label: '张三' }
]
}
assert.deepEqual(buildMultipleSelectSubmitValue(field, [
{ id: 'u-2', name: '张三' }
]), [{ id: 'u-2', name: '张三' }])
})
it('IT-SUBMIT-004: carBrand serializes to 4-level cascade array', () => { it('IT-SUBMIT-004: carBrand serializes to 4-level cascade array', () => {
assert.deepEqual(buildCarBrandSubmitValue(carInfo), [ assert.deepEqual(buildCarBrandSubmitValue(carInfo), [
{ id: 'lantu', name: '岚图' }, { id: 'lantu', name: '岚图' },
......
...@@ -32,4 +32,30 @@ describe('form-field-select display (App dual-key)', () => { ...@@ -32,4 +32,30 @@ describe('form-field-select display (App dual-key)', () => {
assert.equal(state.displayLabel, '交付专员甲') assert.equal(state.displayLabel, '交付专员甲')
assert.equal(state.optionId, 'u-1') assert.equal(state.optionId, 'u-1')
}) })
it('IT-SELECT-DISP-004: duplicate ids use the Chinese value to resolve the correct label', () => {
const sourceOptions = [
{ id: '0', label: '销售端引流-售前', value: '销售端引流-售前' },
{ id: '0', label: '门店引流-售前', value: '门店引流-售前' }
]
const field = { key: 'F2-107-3', 'F2-107-3': '0' }
const state = resolveSelectFieldState(field, '门店引流-售前', sourceOptions)
assert.equal(state.displayLabel, '门店引流-售前')
assert.equal(state.optionId, '门店引流-售前')
})
it('IT-SELECT-DISP-005: remote same-name staff keeps the authoritative meta id', () => {
const staffOptions = [
{ id: 'u-1', label: '张三', value: 'u-1', name: '张三' },
{ id: 'u-2', label: '张三', value: 'u-2', name: '张三' }
]
const field = {
key: 'F2-9-1',
optionsKey: '4sStaffList',
'F2-9-1': { id: 'u-2', name: '张三' }
}
const state = resolveSelectFieldState(field, '张三', staffOptions)
assert.equal(state.displayLabel, '张三')
assert.equal(state.optionId, 'u-2')
})
}) })
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { describe, it } from 'node:test'
import vm from 'node:vm'
import { getVisibleFieldOptions } from '../form-engine/option-visibility.js'
function loadComponentDefinition() {
const source = readFileSync(
new URL('../components/form-field-select/form-field-select.js', import.meta.url),
'utf8'
)
let definition
const stubs = {
'../../api/fieldOptionsService.js': { fetchFieldOptions: async () => ({ code: 0, data: [] }) },
'../../form-engine/field-submit-value.js': { normalizeOptionRecord: option => option },
'../form-picker-popup/select-display.js': {
resolveSelectFieldState: (_field, value) => ({
displayLabel: value == null ? '' : String(value),
optionId: value == null ? '' : String(value)
})
},
'../../form-engine/option-visibility.js': { getVisibleFieldOptions },
'../../utils/order-list-params.js': {
resolveOrderListSaleDate: () => '',
isDealDateMissingForOrderList: () => false,
isOrderListField: () => false,
resolveCarBrandTypeFlagFromField: () => ''
},
'../../utils/field-options-popup.js': {
shouldRefreshOptionsOnPopup: () => false,
isEmployeeListPickerSearchable: () => false
},
'../../utils/upgrade-icon-url.js': {
buildUpgradeIconUrl: value => value,
FORM_FIELD_ARROW_ICON: 'arrow'
}
}
vm.runInNewContext(source, {
Component(value) { definition = value },
require(id) {
if (!stubs[id]) throw new Error(`missing test stub: ${id}`)
return stubs[id]
},
console,
wx: {}
}, { filename: 'form-field-select.js' })
return definition
}
function createInstance(definition, field, requestContext) {
const instance = {
data: {
...structuredClone(definition.data),
field,
requestContext,
value: ''
},
properties: { rowValues: {}, groupBrandIds: [], groupKey: '', rowIndex: -1 },
setData(patch) { Object.assign(this.data, patch) }
}
Object.entries(definition.methods).forEach(([key, method]) => {
instance[key] = method.bind(instance)
})
return instance
}
const field = {
key: 'F2-107-3',
type: 'select',
options: [
{ id: '0', label: '销售端引流-售前', value: '销售端引流-售前', baseSceneCode: [100101] },
{ id: '3', label: '交付端引流-售前', value: '交付端引流-售前', baseSceneCode: [100101] },
{ id: '0', label: '门店引流-售前', value: '门店引流-售前', baseSceneCode: [110201] },
{ id: '1', label: '门店引流-售后', value: '门店引流-售后', baseSceneCode: [110201] }
]
}
describe('form-field-select option visibility', () => {
it('IT-COMPONENT-SELECT-OPTION-VIS-001: static source options follow scene context', () => {
const definition = loadComponentDefinition()
const boutique = createInstance(definition, field, {
sceneList: [{ baseSceneCode: 100101 }]
})
const warranty = createInstance(definition, field, {
sceneList: [{ baseSceneCode: 110201 }]
})
assert.deepEqual(
Array.from(boutique.getStaticOptions(), option => option.value),
['销售端引流-售前', '交付端引流-售前']
)
assert.deepEqual(
Array.from(warranty.getStaticOptions(), option => option.value),
['门店引流-售前', '门店引流-售后']
)
})
it('IT-COMPONENT-SELECT-OPTION-VIS-002: active baseSceneCode wins over merchant multi-scene list', () => {
const definition = loadComponentDefinition()
const instance = createInstance(definition, field, {
baseSceneCode: 100101,
sceneList: [{ baseSceneCode: 100101 }, { baseSceneCode: 110201 }]
})
assert.deepEqual(
Array.from(instance.getStaticOptions(), option => option.value),
['销售端引流-售前', '交付端引流-售前']
)
})
})
...@@ -287,13 +287,13 @@ describe('Store V2.3 delivery-date context visibility', () => { ...@@ -287,13 +287,13 @@ describe('Store V2.3 delivery-date context visibility', () => {
const savedTags = savedSection.childrenValue[0]['F2-107'][CUSTOMER_TAGS_KEY] const savedTags = savedSection.childrenValue[0]['F2-107'][CUSTOMER_TAGS_KEY]
assert.deepEqual(savedTags, { assert.deepEqual(savedTags, {
text: '已拉群/已触客', text: '已拉群/已触客',
value: ['已拉群', '已触客'] value: ['2', '1']
}) })
const customerTagListItem = payload.subformDataList.find(item => const customerTagListItem = payload.subformDataList.find(item =>
item.parentFieldKey === 'F2-107' && item.columnFieldKey === CUSTOMER_TAGS_KEY item.parentFieldKey === 'F2-107' && item.columnFieldKey === CUSTOMER_TAGS_KEY
) )
assert.deepEqual(JSON.parse(customerTagListItem.fieldValue), [ assert.deepEqual(JSON.parse(customerTagListItem.fieldValue), [
{ id: '已拉群/已触客', name: '已拉群/已触客' } { id: '2/1', name: '已拉群/已触客' }
]) ])
const initialValues = parseJsonContentDetailValues(payload.jsonContent, schema.list) const initialValues = parseJsonContentDetailValues(payload.jsonContent, schema.list)
...@@ -319,7 +319,7 @@ describe('Store V2.3 delivery-date context visibility', () => { ...@@ -319,7 +319,7 @@ describe('Store V2.3 delivery-date context visibility', () => {
'F2-107-3': '交付端引流-售前', 'F2-107-3': '交付端引流-售前',
[CUSTOMER_TAGS_KEY]: { [CUSTOMER_TAGS_KEY]: {
text: '已拉群/已触客', text: '已拉群/已触客',
value: ['已拉群', '已触客'] value: ['2', '1']
} }
} }
}] }]
...@@ -332,4 +332,150 @@ describe('Store V2.3 delivery-date context visibility', () => { ...@@ -332,4 +332,150 @@ describe('Store V2.3 delivery-date context visibility', () => {
'已拉群', '已触客' '已拉群', '已触客'
]) ])
}) })
it('IT-V230-CONTEXT-012b: historical Chinese PAD tag ids still echo after numeric mapping', () => {
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': {
[CUSTOMER_TAGS_KEY]: {
text: '已拉群/已触客',
value: ['已拉群', '已触客']
}
}
}]
}])
const initialValues = parseJsonContentDetailValues(detailJson, schema.list)
assert.deepEqual(initialValues['F2-107'][0][CUSTOMER_TAGS_KEY], [
'已拉群', '已触客'
])
})
it('IT-V230-CONTEXT-012c: historical tag objects save with numeric PAD ids', () => {
const ctx = context(100101, [FIVE_REALM_ID])
const engine = createRowEngine(ctx, '交付端引流-售前', null)
engine.setGroupFieldValue('F2-107', 0, CUSTOMER_TAGS_KEY, [
{ id: '已拉群', name: '已拉群' },
{ id: '已触客', name: '已触客' }
])
const payload = buildDynamicSavePayload({
reportTemplateId: 10002,
engine,
normalizedFieldDataList: true
})
const savedSection = JSON.parse(payload.jsonContent)
.find(field => field.key === 'F2-107')
assert.deepEqual(savedSection.childrenValue[0]['F2-107'][CUSTOMER_TAGS_KEY], {
text: '已拉群/已触客',
value: ['2', '1']
})
const listItem = payload.subformDataList.find(item =>
item.parentFieldKey === 'F2-107' && item.columnFieldKey === CUSTOMER_TAGS_KEY
)
assert.deepEqual(JSON.parse(listItem.fieldValue), [
{ id: '2/1', name: '已拉群/已触客' }
])
})
it('IT-V230-CONTEXT-013: customer source saves PAD id and restores duplicate id by text', () => {
for (const [ctx, source, id] of [
[context(100101, [FIVE_REALM_ID]), '销售端引流-售前', '0'],
[context(100101, [FIVE_REALM_ID]), '交付端引流-售前', '3'],
[context(110201, [OTHER_BRAND_ID]), '门店引流-售前', '0'],
[context(110201, [OTHER_BRAND_ID]), '门店引流-售后', '1']
]) {
const engine = createRowEngine(ctx, source, null)
engine.setAppGroupFieldValue('F2-107', 0, SOURCE_KEY, {
id: source,
displayLabel: source
})
const payload = buildDynamicSavePayload({
reportTemplateId: 10002,
engine,
normalizedFieldDataList: true
})
const savedSection = JSON.parse(payload.jsonContent)
.find(field => field.key === 'F2-107')
assert.deepEqual(savedSection.childrenValue[0]['F2-107'][SOURCE_KEY], {
text: source,
value: id
})
const sourceListItem = payload.subformDataList.find(item =>
item.parentFieldKey === 'F2-107' && item.columnFieldKey === SOURCE_KEY
)
assert.deepEqual(JSON.parse(sourceListItem.fieldValue), { id, name: source })
const initialValues = parseJsonContentDetailValues(payload.jsonContent, schema.list)
assert.equal(initialValues['F2-107'][0][SOURCE_KEY], source)
}
})
it('IT-V230-CONTEXT-013b: customer source options follow the active report scene', () => {
const sourceField = schema.list
.find(field => field.key === 'F2-107')
.children[0]
.find(field => field.key === SOURCE_KEY)
const values = ctx => getVisibleFieldOptions(sourceField, ctx).map(option => option.value)
assert.deepEqual(values(context(100101, [FIVE_REALM_ID])), [
'销售端引流-售前', '交付端引流-售前'
])
assert.deepEqual(values(context(110201, [OTHER_BRAND_ID])), [
'门店引流-售前', '门店引流-售后'
])
})
it('IT-V230-CONTEXT-014: boutique save drops stale product category from every App payload shape', () => {
const boutiqueContext = {
...context([100101, 110201], [OTHER_BRAND_ID]),
baseSceneCode: 100101
}
const engine = createRowEngine(boutiqueContext, '销售端引流-售前', null)
engine.setGroupFieldValue('F2-107', 0, CUSTOMER_TAGS_KEY, ['已触客'])
engine.setGroupFieldValue('F2-107', 0, PRODUCT_CATEGORY_KEY, ['原厂延保'])
const payload = buildDynamicSavePayload({
reportTemplateId: 10002,
engine,
normalizedFieldDataList: true
})
const savedSection = JSON.parse(payload.jsonContent)
.find(field => field.key === 'F2-107')
const savedRow = savedSection.childrenValue[0]['F2-107']
assert.equal(Object.hasOwn(savedRow, PRODUCT_CATEGORY_KEY), false)
assert.ok(!savedSection.origin_children.some(field => field.key === PRODUCT_CATEGORY_KEY))
assert.ok(!payload.subformDataList.some(item =>
item.parentFieldKey === 'F2-107' && item.columnFieldKey === PRODUCT_CATEGORY_KEY
))
})
it('IT-V230-CONTEXT-015: warranty save retains eligible product category', () => {
const engine = createRowEngine(context(110201, [OTHER_BRAND_ID]), '门店引流-售前', null)
engine.setGroupFieldValue('F2-107', 0, CUSTOMER_TAGS_KEY, ['已触客'])
engine.setGroupFieldValue('F2-107', 0, PRODUCT_CATEGORY_KEY, ['原厂延保'])
const payload = buildDynamicSavePayload({
reportTemplateId: 10002,
engine,
normalizedFieldDataList: true
})
const savedSection = JSON.parse(payload.jsonContent)
.find(field => field.key === 'F2-107')
assert.deepEqual(savedSection.childrenValue[0]['F2-107'][PRODUCT_CATEGORY_KEY], {
text: '原厂延保',
value: ['原厂延保']
})
assert.ok(savedSection.origin_children.some(field => field.key === PRODUCT_CATEGORY_KEY))
assert.ok(payload.subformDataList.some(item =>
item.parentFieldKey === 'F2-107' && item.columnFieldKey === PRODUCT_CATEGORY_KEY
))
})
}) })
...@@ -104,9 +104,19 @@ describe('store daily template V2.3.0 schema', () => { ...@@ -104,9 +104,19 @@ describe('store daily template V2.3.0 schema', () => {
assert.equal(dailyTags?.optionsKey, 'options') assert.equal(dailyTags?.optionsKey, 'options')
assert.equal(productionTags?.optionsKey, 'options') assert.equal(productionTags?.optionsKey, 'options')
assert.deepEqual(findOption(dailyTags, '已触客'), { label: '已触客', value: '已触客' }) assert.deepEqual(findOption(dailyTags, '已触客'), {
id: '1',
label: '已触客',
value: '已触客'
})
for (const value of ['已拉群', '首保维保客户', '事故车客户']) { for (const value of ['已拉群', '首保维保客户', '事故车客户']) {
const tagIds = {
'已拉群': '2',
'首保维保客户': '4',
'事故车客户': '5'
}
assert.deepEqual(findOption(dailyTags, value), { assert.deepEqual(findOption(dailyTags, value), {
id: tagIds[value],
label: value, label: value,
value, value,
baseSceneCode: lightScenes, baseSceneCode: lightScenes,
...@@ -115,6 +125,7 @@ describe('store daily template V2.3.0 schema', () => { ...@@ -115,6 +125,7 @@ describe('store daily template V2.3.0 schema', () => {
assert.deepEqual(findOption(productionTags, value)?.brandId, productionBrands) assert.deepEqual(findOption(productionTags, value)?.brandId, productionBrands)
} }
assert.deepEqual(findOption(dailyTags, '已交付引荐'), { assert.deepEqual(findOption(dailyTags, '已交付引荐'), {
id: '3',
label: '已交付引荐', label: '已交付引荐',
value: '已交付引荐', value: '已交付引荐',
baseSceneCode: lightScenes, baseSceneCode: lightScenes,
...@@ -130,6 +141,40 @@ describe('store daily template V2.3.0 schema', () => { ...@@ -130,6 +141,40 @@ describe('store daily template V2.3.0 schema', () => {
assert.equal(Object.hasOwn(dailyTags, 'optionShowRules'), false) assert.equal(Object.hasOwn(dailyTags, 'optionShowRules'), false)
}) })
it('IT-V230-003c: customer source keeps Chinese values and uses PAD numeric ids', () => {
const boutiqueScenes = [100101, 100102, 100103]
const warrantyAndEquityScenes = [110101, 110102, 110201, 110202]
const expected = [
{
id: '0',
label: '销售端引流-售前',
value: '销售端引流-售前',
baseSceneCode: boutiqueScenes
},
{
id: '3',
label: '交付端引流-售前',
value: '交付端引流-售前',
baseSceneCode: boutiqueScenes
},
{
id: '0',
label: '门店引流-售前',
value: '门店引流-售前',
baseSceneCode: warrantyAndEquityScenes
},
{
id: '1',
label: '门店引流-售后',
value: '门店引流-售后',
baseSceneCode: warrantyAndEquityScenes
}
]
assert.deepEqual(findDeep(daily.list, 'F2-107-3')?.options, expected)
assert.deepEqual(findDeep(production.list, 'F2-107-3')?.options, expected)
assert.ok(!expected.some(option => option.id === '2'))
})
it('IT-V230-004: subform childrenShowRules retain every Excel dependency', () => { it('IT-V230-004: subform childrenShowRules retain every Excel dependency', () => {
const subform = findDeep(daily.list, 'F2-107') const subform = findDeep(daily.list, 'F2-107')
const rules = subform?.childrenShowRules const rules = subform?.childrenShowRules
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!