Commit d4937187 by 张立顺

feat bug修复

1 parent 12afa6a3
...@@ -33,8 +33,11 @@ Component({ ...@@ -33,8 +33,11 @@ Component({
} }
}, },
apiType: Number, apiType: Number,
/** 仅新建精品工单传 1,用于客户档案列表查询低价单标记 */ /** 调用页显式传入时才下发,null 保持其他消费者原查询口径 */
lowPriceFlag: Number lowPriceFlag: {
type: null,
value: null
}
}, },
data: { data: {
......
...@@ -7,14 +7,14 @@ const DEFAULT_PAGE_SIZE = 20 ...@@ -7,14 +7,14 @@ const DEFAULT_PAGE_SIZE = 20
/** /**
* 构建按工单查询客户档案的分页参数。 * 构建按工单查询客户档案的分页参数。
* lowPriceFlag 仅在调用页显式传 1 时下发,避免改变共享组件其他消费者的查询口径。 * lowPriceFlag 仅在调用页显式传 0 或 1 时下发,避免改变共享组件其他消费者的查询口径。
* *
* @param {Object} options 查询上下文 * @param {Object} options 查询上下文
* @param {number|string} [options.merchantId] 组件传入的门店 ID * @param {number|string} [options.merchantId] 组件传入的门店 ID
* @param {number|string} [options.fallbackMerchantId] 当前登录用户的门店 ID * @param {number|string} [options.fallbackMerchantId] 当前登录用户的门店 ID
* @param {number} options.pageNum 当前页码 * @param {number} options.pageNum 当前页码
* @param {string} [options.keyword] 搜索关键字 * @param {string} [options.keyword] 搜索关键字
* @param {number|string} [options.lowPriceFlag] 低价工单查询标记 * @param {number|string|null} [options.lowPriceFlag] 低价工单查询标记;null/undefined 不下发
* @returns {Object} getWorkPackageGoodsList 请求参数 * @returns {Object} getWorkPackageGoodsList 请求参数
*/ */
function buildCustomerListRequestParams({ function buildCustomerListRequestParams({
...@@ -32,8 +32,8 @@ function buildCustomerListRequestParams({ ...@@ -32,8 +32,8 @@ function buildCustomerListRequestParams({
keyword keyword
} }
if (Number(lowPriceFlag) === 1) { if ([0, 1, '0', '1'].includes(lowPriceFlag)) {
params.lowPriceFlag = 1 params.lowPriceFlag = Number(lowPriceFlag)
} }
return params return params
......
...@@ -330,6 +330,9 @@ ...@@ -330,6 +330,9 @@
| `packageDynamicForm/api/storeDailyReport.js#fetchReportDetail` | `packageDynamicForm/pages/storeDailyReport/storeDailyReport.js` | — | | `packageDynamicForm/api/storeDailyReport.js#fetchReportDetail` | `packageDynamicForm/pages/storeDailyReport/storeDailyReport.js` | — |
| `packageDynamicForm/api/storeDailyReport.js#fetchSchema` | — | — | | `packageDynamicForm/api/storeDailyReport.js#fetchSchema` | — | — |
| `packageDynamicForm/api/storeDailyReport.js#fetchWeeklyList` | `packageDynamicForm/pages/storeDailyReport/storeDailyReport.js` | — | | `packageDynamicForm/api/storeDailyReport.js#fetchWeeklyList` | `packageDynamicForm/pages/storeDailyReport/storeDailyReport.js` | — |
| `packageDynamicForm/api/storeDailyReport.js#hasValidDetailSchemaSnapshot` | `packageDynamicForm/pages/storeDailyReport/storeDailyReport.js` | — |
| `packageDynamicForm/api/storeDailyReport.js#isValidStoreDailySchemaList` | — | — |
| `packageDynamicForm/api/storeDailyReport.js#isValidStoreDailySnapshotField` | — | — |
| `packageDynamicForm/api/storeDailyReport.js#logStoreSaveRequestDebug` | — | — | | `packageDynamicForm/api/storeDailyReport.js#logStoreSaveRequestDebug` | — | — |
| `packageDynamicForm/api/storeDailyReport.js#normalizeDetailJsonContent` | — | — | | `packageDynamicForm/api/storeDailyReport.js#normalizeDetailJsonContent` | — | — |
| `packageDynamicForm/api/storeDailyReport.js#normalizeDetailResponse` | — | — | | `packageDynamicForm/api/storeDailyReport.js#normalizeDetailResponse` | — | — |
......
...@@ -4,15 +4,15 @@ ...@@ -4,15 +4,15 @@
## 规模 ## 规模
- 节点:9908 - 节点:9911
- 关系:22772 - 关系:22780
- 未解析:151 - 未解析:151
## 节点类型 ## 节点类型
| 类型 | 数量 | | 类型 | 数量 |
| --- | --- | | --- | --- |
| apiOperation | 712 | | apiOperation | 715 |
| component | 266 | | component | 266 |
| document | 134 | | document | 134 |
| domain | 15 | | domain | 15 |
...@@ -29,14 +29,14 @@ ...@@ -29,14 +29,14 @@
| --- | --- | | --- | --- |
| bindsEvent | 2463 | | bindsEvent | 2463 |
| calls | 2511 | | calls | 2511 |
| callsApi | 774 | | callsApi | 775 |
| callsEndpoint | 491 | | callsEndpoint | 491 |
| contains | 1866 | | contains | 1866 |
| coveredBy | 413 | | coveredBy | 414 |
| declares | 7124 | | declares | 7124 |
| definesApi | 712 | | definesApi | 715 |
| documentedBy | 530 | | documentedBy | 530 |
| imports | 1981 | | imports | 1984 |
| navigatesTo | 240 | | navigatesTo | 240 |
| readsState | 2728 | | readsState | 2728 |
| usesComponent | 866 | | usesComponent | 866 |
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
| --- | --- | | --- | --- |
| page | 5 | | page | 5 |
| component | 18 | | component | 18 |
| apiOperation | 215 | | apiOperation | 218 |
| globalState | 1 | | globalState | 1 |
| test | 88 | | test | 88 |
| document | 25 | | document | 25 |
...@@ -205,6 +205,9 @@ ...@@ -205,6 +205,9 @@
| apiOperation | `packageDynamicForm/api/storeDailyReport.js#fetchReportDetail` | | apiOperation | `packageDynamicForm/api/storeDailyReport.js#fetchReportDetail` |
| apiOperation | `packageDynamicForm/api/storeDailyReport.js#fetchSchema` | | apiOperation | `packageDynamicForm/api/storeDailyReport.js#fetchSchema` |
| apiOperation | `packageDynamicForm/api/storeDailyReport.js#fetchWeeklyList` | | apiOperation | `packageDynamicForm/api/storeDailyReport.js#fetchWeeklyList` |
| apiOperation | `packageDynamicForm/api/storeDailyReport.js#hasValidDetailSchemaSnapshot` |
| apiOperation | `packageDynamicForm/api/storeDailyReport.js#isValidStoreDailySchemaList` |
| apiOperation | `packageDynamicForm/api/storeDailyReport.js#isValidStoreDailySnapshotField` |
| apiOperation | `packageDynamicForm/api/storeDailyReport.js#logStoreSaveRequestDebug` | | apiOperation | `packageDynamicForm/api/storeDailyReport.js#logStoreSaveRequestDebug` |
| apiOperation | `packageDynamicForm/api/storeDailyReport.js#normalizeDetailJsonContent` | | apiOperation | `packageDynamicForm/api/storeDailyReport.js#normalizeDetailJsonContent` |
| apiOperation | `packageDynamicForm/api/storeDailyReport.js#normalizeDetailResponse` | | apiOperation | `packageDynamicForm/api/storeDailyReport.js#normalizeDetailResponse` |
......
...@@ -26,7 +26,12 @@ import { ...@@ -26,7 +26,12 @@ import {
} from '../form-engine/app-subform-json.js' } from '../form-engine/app-subform-json.js'
const { buildDailyReportSaveRequest } = require('../form-engine/save-request.js') const { buildDailyReportSaveRequest } = require('../form-engine/save-request.js')
import { normalizeSchemaRoot } from '../form-engine/schema-normalizer.js' import { normalizeSchemaRoot } from '../form-engine/schema-normalizer.js'
import { listSubforms } from '../form-engine/field-types.js' import {
listSubforms,
getSubformRowTemplate,
getStaticGroupChildren
} from '../form-engine/field-types.js'
import { getFieldComponentMap } from '../form-engine/field-types/registry.js'
import { import {
resolveBaseSceneCode resolveBaseSceneCode
} from '../form-engine/page-context.js' } from '../form-engine/page-context.js'
...@@ -119,6 +124,63 @@ function normalizeDetailJsonContent(jsonContent) { ...@@ -119,6 +124,63 @@ function normalizeDetailJsonContent(jsonContent) {
return JSON.stringify(list) return JSON.stringify(list)
} }
const STORE_DAILY_SNAPSHOT_FIELD_TYPES = new Set([
...Object.keys(getFieldComponentMap()),
'group'
])
function isValidStoreDailySnapshotField(field, seenKeys) {
if (!field || typeof field !== 'object' || Array.isArray(field)) {
return false
}
if (typeof field.key !== 'string' || !field.key.trim() || seenKeys.has(field.key)) {
return false
}
if (
typeof field.type !== 'string' ||
!STORE_DAILY_SNAPSHOT_FIELD_TYPES.has(field.type)
) {
return false
}
seenKeys.add(field.key)
if (field.type === 'subform') {
const children = getSubformRowTemplate(field)
return (
children.length > 0 &&
children.every(child => isValidStoreDailySnapshotField(child, seenKeys))
)
}
if (field.type === 'group') {
const children = getStaticGroupChildren(field)
return (
children.length > 0 &&
children.every(child => isValidStoreDailySnapshotField(child, seenKeys))
)
}
return true
}
function isValidStoreDailySchemaList(list = []) {
if (!Array.isArray(list) || !list.length) {
return false
}
const seenKeys = new Set()
return (
list.some(field => field?.type !== 'divider') &&
list.every(field => isValidStoreDailySnapshotField(field, seenKeys))
)
}
/**
* 判断门店日报详情是否包含可独立渲染的完整 schema 快照。
* @param {Object} [detail={}] 日报详情(含 jsonContent)
* @returns {boolean} 可直接使用历史快照时返回 true
*/
function hasValidDetailSchemaSnapshot(detail = {}) {
return isValidStoreDailySchemaList(normalizeJsonContentList(detail.jsonContent))
}
/** /**
* 规范化用户信息,补齐 merchantId、staffUuid 等日报所需字段 * 规范化用户信息,补齐 merchantId、staffUuid 等日报所需字段
* @param {Object} [userInfo={}] 原始用户信息 * @param {Object} [userInfo={}] 原始用户信息
...@@ -399,6 +461,29 @@ async function fetchSchema({ ...@@ -399,6 +461,29 @@ async function fetchSchema({
detail, detail,
detailValues = {} detailValues = {}
} = {}) { } = {}) {
const detailSchemaList = normalizeJsonContentList(detail?.jsonContent)
const hasValidDetailSchema = isValidStoreDailySchemaList(detailSchemaList)
if (hasValidDetailSchema) {
// 详情 jsonContent 是保存时的完整模板快照,历史记录不能受当前模板变更影响。
const normalizedDetailRoot = normalizeSchemaRoot(
{ list: detailSchemaList },
SCHEMA_OPTIONS_MAP
)
const initialValues = mergeTemplateDefaultsIntoInitialValues(
normalizedDetailRoot.list,
parseJsonContentDetailValues(detail.jsonContent, normalizedDetailRoot.list)
)
warnIfDetailSubformEchoEmpty(detail, initialValues, normalizedDetailRoot.list)
return {
code: 0,
message: 'ok',
data: stripValuesFromSchemaRoot(
mergeAppJsonIntoSchema(normalizedDetailRoot, detail)
),
initialValues
}
}
const result = await fetchSchemaRootAdapter({ const result = await fetchSchemaRootAdapter({
reportTemplateId, reportTemplateId,
baseSceneCode, baseSceneCode,
...@@ -415,20 +500,15 @@ async function fetchSchema({ ...@@ -415,20 +500,15 @@ async function fetchSchema({
return { code: -1, message: '加载表单模板失败', data: null } return { code: -1, message: '加载表单模板失败', data: null }
} }
const normalizedRoot = normalizeSchemaRoot(data, SCHEMA_OPTIONS_MAP) const normalizedRoot = normalizeSchemaRoot(data, SCHEMA_OPTIONS_MAP)
let schema = normalizedRoot
if (detail?.jsonContent) {
schema = mergeAppJsonIntoSchema(normalizedRoot, detail)
}
const initialValues = mergeTemplateDefaultsIntoInitialValues( const initialValues = mergeTemplateDefaultsIntoInitialValues(
normalizedRoot.list, normalizedRoot.list,
resolveSchemaDetailValues(detail, normalizedRoot.list, detailValues) resolveSchemaDetailValues(detail, normalizedRoot.list, detailValues)
) )
warnIfDetailSubformEchoEmpty(detail, initialValues, normalizedRoot.list) warnIfDetailSubformEchoEmpty(detail, initialValues, normalizedRoot.list)
schema = stripValuesFromSchemaRoot(schema)
return { return {
code: 0, code: 0,
message: 'ok', message: 'ok',
data: schema, data: stripValuesFromSchemaRoot(normalizedRoot),
initialValues initialValues
} }
} }
...@@ -670,12 +750,14 @@ async function fetchMonthlyPendingCount({ merchantId, reportDate, sceneType } = ...@@ -670,12 +750,14 @@ async function fetchMonthlyPendingCount({ merchantId, reportDate, sceneType } =
* @param {Object} [options.userContext] 用户上下文(merchantId、staffUuid 等) * @param {Object} [options.userContext] 用户上下文(merchantId、staffUuid 等)
* @param {string} [options.baseSceneCode] 门店场景编码 * @param {string} [options.baseSceneCode] 门店场景编码
* @param {number|string} [options.reportTemplateId] 模板 ID * @param {number|string} [options.reportTemplateId] 模板 ID
* @param {boolean} [options.skipSchema=false] 历史详情使用 jsonContent 快照时不刷新当前模板
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async function revalidateCachedMetadata({ async function revalidateCachedMetadata({
userContext = {}, userContext = {},
baseSceneCode, baseSceneCode,
reportTemplateId reportTemplateId,
skipSchema = false
} = {}) { } = {}) {
if ( if (
isStoreMockMode('brand') && isStoreMockMode('brand') &&
...@@ -689,17 +771,20 @@ async function revalidateCachedMetadata({ ...@@ -689,17 +771,20 @@ async function revalidateCachedMetadata({
return return
} }
const refreshOptions = { skipCacheRead: true } const refreshOptions = { skipCacheRead: true }
await Promise.allSettled([ const refreshTasks = [
fetchBrandAdapter({ merchantId }, refreshOptions), fetchBrandAdapter({ merchantId }, refreshOptions),
fetchSceneAdapter( fetchSceneAdapter(
{ merchantId, shopMerchantId, staffUuid, phone, sceneType }, { merchantId, shopMerchantId, staffUuid, phone, sceneType },
refreshOptions refreshOptions
), )
fetchSchemaRootAdapter( ]
if (!skipSchema) {
refreshTasks.push(fetchSchemaRootAdapter(
{ reportTemplateId, baseSceneCode, merchantId }, { reportTemplateId, baseSceneCode, merchantId },
refreshOptions refreshOptions
) ))
]) }
await Promise.allSettled(refreshTasks)
} }
module.exports = { module.exports = {
...@@ -715,6 +800,7 @@ module.exports = { ...@@ -715,6 +800,7 @@ module.exports = {
saveDraftForm, saveDraftForm,
pushReportData, pushReportData,
normalizeDetailResponse, normalizeDetailResponse,
hasValidDetailSchemaSnapshot,
buildPageContextFromSources, buildPageContextFromSources,
normalizeUserInfo, normalizeUserInfo,
revalidateCachedMetadata revalidateCachedMetadata
......
...@@ -96,6 +96,8 @@ ...@@ -96,6 +96,8 @@
与驻店相同结构,使用 `loadStoreDailyForm` + `storeDailyReport.js`。 与驻店相同结构,使用 `loadStoreDailyForm` + `storeDailyReport.js`。
`buildFormRequestContext` 额外透传 `sceneType` 给字段选项接口。 `buildFormRequestContext` 额外透传 `sceneType` 给字段选项接口。
已有详情且 `jsonContent` 是合法、非空字段快照时,门店日报直接使用该快照的字段结构与值回显,前台加载和后台缓存刷新均不请求或混入当前配置中心模板;无详情或快照结构无效时才加载当前模板。历史字段(如 V2.3.0 之前的 `F2-58`)因此不会因模板升级而丢失。
`loadFormData` 在 `engine.init` + `applyEngineView` 之后解析当前可见的本月待邀约字段(V2.3 **`F2-102`**,兼容旧模板 **`F2-24`**,异常共存时优先新字段)。仅当 **当天**(`isTodayReport`)且字段 **无值** 时初始化:每月首日直接写 `0`,不调用接口;非首日调用 `fetchMonthlyPendingCount`(`dj.api.smartcarlife.dailyReport.monthly.pending.get` POST,`merchantId` 为 4S 店、`reportDate` 为选中日),把最近一次提交数值写回当前字段。历史日期或已有回显/填写不请求、不覆盖。开关:`STORE_DAILY_API_SWITCH.monthlyPendingCount`。 `loadFormData` 在 `engine.init` + `applyEngineView` 之后解析当前可见的本月待邀约字段(V2.3 **`F2-102`**,兼容旧模板 **`F2-24`**,异常共存时优先新字段)。仅当 **当天**(`isTodayReport`)且字段 **无值** 时初始化:每月首日直接写 `0`,不调用接口;非首日调用 `fetchMonthlyPendingCount`(`dj.api.smartcarlife.dailyReport.monthly.pending.get` POST,`merchantId` 为 4S 店、`reportDate` 为选中日),把最近一次提交数值写回当前字段。历史日期或已有回显/填写不请求、不覆盖。开关:`STORE_DAILY_API_SWITCH.monthlyPendingCount`。
若当天可编辑且 **`F2-1` 今日驻店人员**可见(如经营品牌含岚图),加载后及每次改选 F2-1 时,**`F2-2` 今日驻店人数**自动同步为选中人员数量(等价于 schema `completeFun.result: "(list.length)"`,不 eval 表达式);F2-1 不可见时不改动 F2-2。**F2-1 已选至少 1 人时 F2-2 只读**(未选人时可手动改人数)。见 [`store-staff-count.js`](../utils/store-staff-count.js)、[store-template-features.md](./store-template-features.md)。 若当天可编辑且 **`F2-1` 今日驻店人员**可见(如经营品牌含岚图),加载后及每次改选 F2-1 时,**`F2-2` 今日驻店人数**自动同步为选中人员数量(等价于 schema `completeFun.result: "(list.length)"`,不 eval 表达式);F2-1 不可见时不改动 F2-2。**F2-1 已选至少 1 人时 F2-2 只读**(未选人时可手动改人数)。见 [`store-staff-count.js`](../utils/store-staff-count.js)、[store-template-features.md](./store-template-features.md)。
...@@ -147,6 +149,9 @@ ...@@ -147,6 +149,9 @@
- `IT-STORE-LOADER-*` — loader - `IT-STORE-LOADER-*` — loader
- `IT-STORE-DETAIL-GET-001` — detail.get templateType=2 - `IT-STORE-DETAIL-GET-001` — detail.get templateType=2
- `IT-STORE-DETAIL-007` — 老模板详情直接使用 jsonContent schema 快照回显
- `IT-STORE-DETAIL-008`~`009` — 损坏快照回退当前模板、历史详情跳过后台 schema 刷新
- `IT-STORE-DAILY-PAGE-004a` — 页面把历史快照状态传给后台缓存刷新
- `IT-STORE-BRAND-CACHE-001` — brand 缓存 - `IT-STORE-BRAND-CACHE-001` — brand 缓存
- `IT-FIELD-OPT-004` ~ `006` — fieldOptions - `IT-FIELD-OPT-004` ~ `006` — fieldOptions
- `IT-STORE-ENG-*` — 门店 schema 显隐 - `IT-STORE-ENG-*` — 门店 schema 显隐
......
...@@ -103,6 +103,8 @@ App 草稿 `saveReport` 仅做 childrenValue 序列化、**不产** fieldDataLis ...@@ -103,6 +103,8 @@ App 草稿 `saveReport` 仅做 childrenValue 序列化、**不产** fieldDataLis
**无记录成功**:接口 `code` 为 `0` / `"0"` 且 `data: null`(或空)视为成功,与 App 一致;[`fetchReportDetail`](../api/staffDailyReport.js) 经 [`resolveDetailGetResponse`](../utils/api-response.js) 映射为 `buildEmptyDetail`(`dailyReportRecordId: null`、`values: {}`),正常加载空白表单。 **无记录成功**:接口 `code` 为 `0` / `"0"` 且 `data: null`(或空)视为成功,与 App 一致;[`fetchReportDetail`](../api/staffDailyReport.js) 经 [`resolveDetailGetResponse`](../utils/api-response.js) 映射为 `buildEmptyDetail`(`dailyReportRecordId: null`、`values: {}`),正常加载空白表单。
**门店日报历史模板兼容**:详情存在合法、非空的 `jsonContent` 时,其中的字段列表同时作为保存时的 schema 快照和值来源,直接用于回显,前台加载和后台缓存刷新均不请求、也不混入当前配置中心模板。这样旧模板字段即使已从新模板删除,仍能按保存时的 `label`、`type`、`origin_children` 与 `childrenValue` 展示。快照会校验字段类型、全局 key 唯一性以及 subform/group 子字段结构;仅在无详情或快照结构无效时,才加载当前门店模板作为新建/异常兜底。驻店日报和洽谈明细的加载策略不在此规则范围内。
| 步骤 | 函数 | 说明 | | 步骤 | 函数 | 说明 |
|------|------|------| |------|------|------|
| 解析 jsonContent | [`normalizeJsonContentList`](../form-engine/app-subform-json.js) | 兼容 string / array / `{ list: [] }` | | 解析 jsonContent | [`normalizeJsonContentList`](../form-engine/app-subform-json.js) | 兼容 string / array / `{ list: [] }` |
......
...@@ -662,7 +662,9 @@ Page({ ...@@ -662,7 +662,9 @@ Page({
{ {
userContext, userContext,
baseSceneCode: pageContext.baseSceneCode, baseSceneCode: pageContext.baseSceneCode,
reportTemplateId: this.reportTemplateId reportTemplateId: this.reportTemplateId,
skipSchema:
storeDailyApi.hasValidDetailSchemaSnapshot?.(detail) === true
}, },
seq seq
) )
......
import { describe, it } from 'node:test' import { describe, it } from 'node:test'
import assert from 'node:assert/strict' import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { createRequire } from 'node:module' import { createRequire } from 'node:module'
const require = createRequire(import.meta.url) const require = createRequire(import.meta.url)
...@@ -15,6 +16,37 @@ const { ...@@ -15,6 +16,37 @@ const {
const { DEFAULT_REPORT_TEMPLATE_ID } = require('../api/mockStoreDynamicDetail.js') const { DEFAULT_REPORT_TEMPLATE_ID } = require('../api/mockStoreDynamicDetail.js')
const { loadSchemaFixture } = await import('./schemaFixture.mjs') const { loadSchemaFixture } = await import('./schemaFixture.mjs')
const storeDailyApiUrl = new URL('../api/storeDailyReport.js', import.meta.url)
function loadStoreDailyApi(overrides = {}) {
const apiRequire = createRequire(storeDailyApiUrl)
const actualAdapters = apiRequire('./storeDailyReportAdapters.js')
const requireForApi = specifier => {
if (specifier === '~/config.js') {
return { envIndex: 0 }
}
if (specifier === './dynamicDailyReport.js') {
return { dynamicDailyReportSave: async () => ({ code: 0, data: {} }) }
}
if (specifier === './storeDailyReportAdapters.js') {
return { ...actualAdapters, ...overrides }
}
return apiRequire(specifier)
}
const source = readFileSync(storeDailyApiUrl, 'utf8').replace(
/import\s*\{([\s\S]*?)\}\s*from\s*['"]([^'"]+)['"]/g,
(_match, imports, specifier) => `const {${imports}} = require('${specifier}')`
)
const module = { exports: {} }
new Function('require', 'module', 'exports', 'wx', source)(
requireForApi,
module,
module.exports,
{}
)
return module.exports
}
function selectValueMapId(value) { function selectValueMapId(value) {
if (value != null && typeof value === 'object' && !Array.isArray(value)) { if (value != null && typeof value === 'object' && !Array.isArray(value)) {
return value.id ?? value.value return value.id ?? value.value
...@@ -34,6 +66,135 @@ function normalizeDetailFixture(detail = {}, reportTemplateId) { ...@@ -34,6 +66,135 @@ function normalizeDetailFixture(detail = {}, reportTemplateId) {
} }
describe('storeDailyReport detail response', () => { describe('storeDailyReport detail response', () => {
it('IT-STORE-DETAIL-007: valid detail jsonContent is the schema snapshot without loading the current template', async () => {
let currentTemplateCalls = 0
const api = loadStoreDailyApi({
fetchSchemaRootAdapter: async () => {
currentTemplateCalls += 1
return {
code: 0,
message: 'ok',
data: {
list: [
{ key: 'F2-101', label: '新模板字段', type: 'numberInput' }
]
}
}
}
})
const historicalList = [
{
label: '其他品牌售后部数据 (轻改)',
key: 'F2-58',
type: 'subform',
rules: { maxRows: 20 },
origin_children: [
{
label: 'SA',
key: 'F2-58-1',
type: 'select',
optionsKey: '4sStaffList'
},
{ label: '今日谈客数', key: 'F2-58-2', type: 'numberInput' },
{ label: '今日成交数', key: 'F2-58-3', type: 'numberInput' },
{ label: '今日成交金额', key: 'F2-58-4', type: 'numberInput' }
],
childrenValue: [
{
'F2-58': {
'F2-58-1': {
text: '测试1230622',
value: '1a1ba1477f684b7886be8aa01440a260'
},
'F2-58-2': 2,
'F2-58-3': 3,
'F2-58-4': 15
}
}
]
}
]
const result = await api.fetchSchema({
reportTemplateId: 10002,
baseSceneCode: 100101,
merchantId: 'm-old-template',
detail: { jsonContent: JSON.stringify(historicalList) }
})
assert.equal(currentTemplateCalls, 0)
assert.equal(result.code, 0)
assert.deepEqual(result.data.list.map(field => field.key), ['F2-58'])
assert.equal(result.data.list[0].label, '其他品牌售后部数据 (轻改)')
assert.equal(
result.initialValues['F2-58'][0]['F2-58-1'].id,
'1a1ba1477f684b7886be8aa01440a260'
)
assert.equal(result.initialValues['F2-58'][0]['F2-58-2'], 2)
assert.equal(result.initialValues['F2-58'][0]['F2-58-3'], 3)
assert.equal(result.initialValues['F2-58'][0]['F2-58-4'], 15)
})
it('IT-STORE-DETAIL-008: incomplete detail schema falls back to the current template', async () => {
let currentTemplateCalls = 0
const api = loadStoreDailyApi({
fetchSchemaRootAdapter: async () => {
currentTemplateCalls += 1
return {
code: 0,
message: 'ok',
data: {
list: [
{ key: 'F2-101', label: '当前模板字段', type: 'numberInput' }
]
}
}
}
})
const result = await api.fetchSchema({
reportTemplateId: 10002,
baseSceneCode: 100101,
merchantId: 'm-invalid-snapshot',
detail: {
jsonContent: JSON.stringify([
{ key: 'F2-58', label: '损坏的历史子表单', type: 'subform' }
])
}
})
assert.equal(currentTemplateCalls, 1)
assert.equal(result.code, 0)
assert.deepEqual(result.data.list.map(field => field.key), ['F2-101'])
})
it('IT-STORE-DETAIL-009: detail snapshot revalidation skips only the current schema refresh', async () => {
const calls = { brand: 0, scene: 0, schema: 0 }
const api = loadStoreDailyApi({
fetchBrandAdapter: async () => {
calls.brand += 1
return { code: 0, data: [] }
},
fetchSceneAdapter: async () => {
calls.scene += 1
return { code: 0, data: [] }
},
fetchSchemaRootAdapter: async () => {
calls.schema += 1
return { code: 0, data: { list: [] } }
}
})
await api.revalidateCachedMetadata({
userContext: { merchantId: 'm-old-template', staffUuid: 's1' },
baseSceneCode: 100101,
reportTemplateId: 10002,
skipSchema: true
})
assert.deepEqual(calls, { brand: 1, scene: 1, schema: 0 })
})
it('IT-STORE-DETAIL-001: normalizeDetailResponse maps reportStatus', () => { it('IT-STORE-DETAIL-001: normalizeDetailResponse maps reportStatus', () => {
const data = normalizeDetailFixture( const data = normalizeDetailFixture(
{ {
......
...@@ -480,6 +480,58 @@ describe('storeDailyReport page contract', () => { ...@@ -480,6 +480,58 @@ describe('storeDailyReport page contract', () => {
assert.match(loadSource, /finally\s*{[\s\S]*setData\(\{ loading: false \}\)[\s\S]*applyStoreDailyViewState\(\{ loading: false \}\)/) assert.match(loadSource, /finally\s*{[\s\S]*setData\(\{ loading: false \}\)[\s\S]*applyStoreDailyViewState\(\{ loading: false \}\)/)
}) })
it('IT-STORE-DAILY-PAGE-004a: historical detail skips background schema revalidation', async () => {
let scheduledParams = null
const detail = {
reportTemplateId: 10002,
dailyReportRecordId: 9001,
jsonContent: JSON.stringify([
{ key: 'F2-58', label: '历史模板字段', type: 'numberInput', value: 2 }
])
}
const storeDailyApi = createFallbackModule({
hasValidDetailSchemaSnapshot: candidate => candidate === detail
})
const { page } = createStorePageHarness({
modules: {
'../../api/storeDailyReport.js': storeDailyApi,
'../../services/storeDailyFormLoader.js': {
loadStoreDailyForm: async () => ({
code: 0,
data: {
pageContext: { baseSceneCode: 100101 },
schema: { list: [] },
initialValues: {},
detail
}
})
},
'../../utils/api-response.js': require('../utils/api-response.js')
}
})
Object.assign(page.data, {
reportDate: '2026-08-20',
timeBean: {},
loading: false
})
page.getRequestContext = () => ({ merchantId: 'm-old-template', staffUuid: 's1' })
page.getEngineKey = value => value
page.isStaleLoad = () => false
page.applyStoreDailyDetailState = () => {}
page.ensureEngine = () => ({ init: () => ({ values: {}, visibleList: [] }) })
page.applyEngineView = () => {}
page.scheduleMetadataCacheRevalidate = (_api, params) => {
scheduledParams = params
}
page.applyMonthlyPendingCountIfNeeded = async () => {}
page.applyStoreStaffCountIfNeeded = async () => {}
page.applyStoreDailyViewState = () => {}
await page.loadFormData()
assert.equal(scheduledParams.skipSchema, true)
})
it('IT-STORE-DAILY-PAGE-005: freezes write contexts and ignores stale async responses', () => { it('IT-STORE-DAILY-PAGE-005: freezes write contexts and ignores stale async responses', () => {
const saveSource = js.slice(js.indexOf('async onSave()'), js.indexOf('\n\t/** @deprecated', js.indexOf('async onSave()'))) const saveSource = js.slice(js.indexOf('async onSave()'), js.indexOf('\n\t/** @deprecated', js.indexOf('async onSave()')))
const pushSource = js.slice(js.indexOf('async pushReport()'), js.indexOf('\n\t/** @deprecated', js.indexOf('async pushReport()'))) const pushSource = js.slice(js.indexOf('async pushReport()'), js.indexOf('\n\t/** @deprecated', js.indexOf('async pushReport()')))
......
...@@ -908,7 +908,7 @@ value="{{ orderObj.remark }}" ...@@ -908,7 +908,7 @@ value="{{ orderObj.remark }}"
></sku-goods> ></sku-goods>
<customerInfo <customerInfo
show="{{ customerInfoBox }}" show="{{ customerInfoBox }}"
lowPriceFlag="{{ 1 }}" lowPriceFlag="{{ 0 }}"
bindconfirm="chooseCustomerInfo" bindconfirm="chooseCustomerInfo"
bindcancel="onCustomerInfoCancel" bindcancel="onCustomerInfoCancel"
/> />
......
...@@ -20,13 +20,21 @@ describe('customerInfo.pagination', () => { ...@@ -20,13 +20,21 @@ describe('customerInfo.pagination', () => {
assert.equal(canLoadMorePage(0, 1), false) assert.equal(canLoadMorePage(0, 1), false)
}) })
it('buildCustomerListRequestParams forwards lowPriceFlag only when explicitly enabled', () => { it('buildCustomerListRequestParams forwards explicit numeric flags', () => {
const cases = [
{ input: 0, expected: 0 },
{ input: '0', expected: 0 },
{ input: 1, expected: 1 },
{ input: '1', expected: 1 }
]
cases.forEach(({ input, expected }) => {
const params = buildCustomerListRequestParams({ const params = buildCustomerListRequestParams({
merchantId: '', merchantId: '',
fallbackMerchantId: 1001, fallbackMerchantId: 1001,
pageNum: 2, pageNum: 2,
keyword: '张三', keyword: '张三',
lowPriceFlag: '1' lowPriceFlag: input
}) })
assert.deepEqual(params, { assert.deepEqual(params, {
...@@ -35,15 +43,23 @@ describe('customerInfo.pagination', () => { ...@@ -35,15 +43,23 @@ describe('customerInfo.pagination', () => {
pageSize: DEFAULT_PAGE_SIZE, pageSize: DEFAULT_PAGE_SIZE,
statusList: [1], statusList: [1],
keyword: '张三', keyword: '张三',
lowPriceFlag: 1 lowPriceFlag: expected
})
})
}) })
const defaultParams = buildCustomerListRequestParams({ it('buildCustomerListRequestParams omits absent or null lowPriceFlag', () => {
const cases = [{}, { lowPriceFlag: null }]
cases.forEach((extraOptions) => {
const params = buildCustomerListRequestParams({
merchantId: 1002, merchantId: 1002,
fallbackMerchantId: 1001, fallbackMerchantId: 1001,
pageNum: 1 pageNum: 1,
...extraOptions
})
assert.equal(Object.hasOwn(params, 'lowPriceFlag'), false)
}) })
assert.equal(Object.hasOwn(defaultParams, 'lowPriceFlag'), false)
}) })
it('mapCustomerListWithCarType builds carType from customer fields', () => { it('mapCustomerListWithCarType builds carType from customer fields', () => {
......
...@@ -38,7 +38,7 @@ describe('work order low-price edit guard', () => { ...@@ -38,7 +38,7 @@ describe('work order low-price edit guard', () => {
assert.equal(LOW_PRICE_ORDER_EDIT_MESSAGE, '低价单不可以编辑') assert.equal(LOW_PRICE_ORDER_EDIT_MESSAGE, '低价单不可以编辑')
}) })
it('wires lowPriceFlag=1 only from the create-order customer archive popup', () => { it('wires lowPriceFlag=0 from the create-order customer archive popup', () => {
const createOrderWxml = read( const createOrderWxml = read(
'../tabWorkOrder/pages/createOrder/createOrder.wxml' '../tabWorkOrder/pages/createOrder/createOrder.wxml'
) )
...@@ -46,7 +46,7 @@ describe('work order low-price edit guard', () => { ...@@ -46,7 +46,7 @@ describe('work order low-price edit guard', () => {
assert.match( assert.match(
createOrderWxml, createOrderWxml,
/<customerInfo[\s\S]*?lowPriceFlag="\{\{ 1 \}\}"[\s\S]*?\/>/ /<customerInfo[\s\S]*?lowPriceFlag="\{\{ 0 \}\}"[\s\S]*?\/>/
) )
assert.match(customerInfoJs, /buildCustomerListRequestParams/) assert.match(customerInfoJs, /buildCustomerListRequestParams/)
}) })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!