Commit a4427e5a by 张立顺

docs: plan low-price order import filters

1 parent dc39af40
# Low-Price Order Customer Import and Catalog 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 low-price customer-profile selection import only customer data and hide catalog entries that have not enabled minimum-price validation.
**Architecture:** Add one pure helper beside the existing customer-profile effects to build an order that changes only its customer object, and add one pure catalog filter before the existing catalog classifier. The page selects these paths only when `Number(orderObj.lowPriceFlag) === 1`; normal-order routing and catalog behavior remain unchanged.
**Tech Stack:** WeChat Mini Program JavaScript, ES modules, Node.js 24 built-in test runner.
## Global Constraints
- Do not modify `config.js` or `yarn.lock`; they contain pre-existing user changes.
- Do not change APIs, dependencies, layouts, existing low-price price comparison, or submission validation.
- Treat minimum-price validation as enabled only when `validMinSellPrice === 'Y'`.
- Low-price packages require a non-empty child list and every child enabled.
- Low-price multi-spec goods retain only enabled SKUs and disappear when no SKU remains.
- Normal orders retain their existing customer-profile and full-catalog behavior.
---
### Task 1: Import only the customer domain for low-price orders
**Files:**
- Modify: `tabWorkOrder/pages/createOrder/services/customerProfileEffects.js`
- Modify: `tabWorkOrder/pages/createOrder/createOrder.js`
- Test: `tabWorkOrder/pages/createOrder/tests/customerProfileEffects.test.mjs`
- Test: `tabWorkOrder/pages/createOrder/tests/customerProfileOnlyImport.integration.test.mjs`
**Interfaces:**
- Produces: `buildCustomerOnlyOrder(currentOrder: object, selectedRecord: object): object`.
- Consumes: existing `echoCustomerProfileIfNeeded(detail)` and `closePagePopupPatch('customerInfoBox')` page behavior.
- [ ] **Step 1: Write the failing pure-function test**
Add an import for `buildCustomerOnlyOrder` and this behavior to `customerProfileEffects.test.mjs`:
```js
it('buildCustomerOnlyOrder replaces customer without importing historical order fields', () => {
const current = {
lowPriceFlag: 1,
merchantId: 100,
selectPayType: 3,
payeeType: 1,
subOrderList: [{ goodsCode: 'CURRENT' }],
customer: { customerId: 1, customerName: '旧客户' }
}
const selected = {
selectPayType: 5,
payeeType: 0,
subOrderList: [{ goodsCode: 'HISTORY' }],
packageGoodsList: [{ packageCode: 'HISTORY-PKG' }],
customer: {
customerId: 2,
customerName: '新客户',
customerPhone: '13800000000',
standNo: 'VIN-NEW'
}
}
const result = buildCustomerOnlyOrder(current, selected)
assert.notEqual(result, current)
assert.notEqual(result.customer, selected.customer)
assert.deepEqual(result.customer, selected.customer)
assert.equal(result.selectPayType, 3)
assert.equal(result.payeeType, 1)
assert.deepEqual(result.subOrderList, [{ goodsCode: 'CURRENT' }])
assert.equal(result.packageGoodsList, undefined)
assert.deepEqual(current.customer, { customerId: 1, customerName: '旧客户' })
})
```
- [ ] **Step 2: Run the pure-function test and verify RED**
Run: `node scripts/run-node-tests.mjs tabWorkOrder/pages/createOrder/tests/customerProfileEffects.test.mjs`
Expected: FAIL because `buildCustomerOnlyOrder` is not exported.
- [ ] **Step 3: Add the minimal pure helper**
Add to `customerProfileEffects.js`:
```js
export function buildCustomerOnlyOrder(currentOrder, selectedRecord) {
return {
...(currentOrder || {}),
customer: { ...(selectedRecord?.customer || {}) }
}
}
```
- [ ] **Step 4: Run the pure-function test and verify GREEN**
Run: `node scripts/run-node-tests.mjs tabWorkOrder/pages/createOrder/tests/customerProfileEffects.test.mjs`
Expected: PASS.
- [ ] **Step 5: Write the failing page integration test**
Create `customerProfileOnlyImport.integration.test.mjs` using the established page-loader setup from `selectedMerchantContext.integration.test.mjs`. Load the real page config, create a page with current low-price goods and payment state, invoke `pageConfig.chooseCustomerInfo.call(page, { detail: selectedRecord })`, and assert these literal outcomes:
```js
assert.equal(page.data.orderObj.customer.customerId, 2)
assert.equal(page.data.orderObj.customer.customerName, '新客户')
assert.equal(page.data.orderObj.selectPayType, 3)
assert.equal(page.data.orderObj.payeeType, 1)
assert.deepEqual(page.data.orderObj.subOrderList, [{ goodsCode: 'CURRENT' }])
assert.deepEqual(page.data.goodsList, [{ goodsCode: 'CURRENT' }])
assert.equal(page.data.customerInfoBox, false)
assert.equal(profileEchoCustomerId, 2)
```
The page double must keep `setData` behavior real for top-level patches and replace only the external profile fetch path with a local `echoCustomerProfileIfNeeded` observer.
- [ ] **Step 6: Run the integration test and verify RED**
Run: `node scripts/run-node-tests.mjs tabWorkOrder/pages/createOrder/tests/customerProfileOnlyImport.integration.test.mjs`
Expected: FAIL because the existing method routes the entire selected historical order and overwrites current state.
- [ ] **Step 7: Wire the low-price-only branch**
Import `buildCustomerOnlyOrder` in `createOrder.js`. At the start of `chooseCustomerInfo`, branch on `Number(this.data.orderObj?.lowPriceFlag) === 1`:
```js
if (Number(this.data.orderObj?.lowPriceFlag) === 1) {
const orderObj = buildCustomerOnlyOrder(this.data.orderObj, detail)
this.setData({ orderObj })
await this.echoCustomerProfileIfNeeded({ customer: orderObj.customer })
this.setData(closePagePopupPatch('customerInfoBox'))
return
}
```
Leave the existing non-low-price `onRoute` and `settingPayType` path intact.
- [ ] **Step 8: Run customer tests and verify GREEN**
Run: `node scripts/run-node-tests.mjs tabWorkOrder/pages/createOrder/tests/customerProfileEffects.test.mjs tabWorkOrder/pages/createOrder/tests/customerProfileOnlyImport.integration.test.mjs tabWorkOrder/pages/createOrder/tests/selectedMerchantContext.integration.test.mjs`
Expected: PASS.
- [ ] **Step 9: Commit Task 1**
```powershell
git add -- tabWorkOrder/pages/createOrder/services/customerProfileEffects.js tabWorkOrder/pages/createOrder/createOrder.js tabWorkOrder/pages/createOrder/tests/customerProfileEffects.test.mjs tabWorkOrder/pages/createOrder/tests/customerProfileOnlyImport.integration.test.mjs
git commit -m "fix: limit low-price customer profile import"
```
### Task 2: Filter the low-price selectable catalog
**Files:**
- Create: `tabWorkOrder/pages/createOrder/services/lowPriceCatalogFilter.helpers.js`
- Modify: `tabWorkOrder/pages/createOrder/createOrder.js`
- Test: `tabWorkOrder/pages/createOrder/tests/lowPriceCatalogFilter.helpers.test.mjs`
- Test: `tabWorkOrder/pages/createOrder/tests/lowPriceCatalogFilter.integration.test.mjs`
**Interfaces:**
- Produces: `filterLowPriceSelectOrderCatalog(items: Array<object>, lowPriceFlag: number|string): Array<object>`.
- Consumes: `SELECT_ORDER_GOODS_FLAG` and the existing `classifySelectOrderCatalog(filteredItems, context)` interface.
- [ ] **Step 1: Write failing catalog filter tests**
Create table-driven tests with literal fixtures for these observable results:
```js
assert.deepEqual(
filterLowPriceSelectOrderCatalog([enabledSingle, disabledSingle], 1),
[enabledSingle]
)
const [filteredMulti] = filterLowPriceSelectOrderCatalog([multiSpec], '1')
assert.deepEqual(
filteredMulti.multipleSpecificationsGoods.skuGoodsList.map(item => item.id),
['sku-enabled']
)
assert.equal(multiSpec.multipleSpecificationsGoods.skuGoodsList.length, 2)
assert.deepEqual(filterLowPriceSelectOrderCatalog([allDisabledMulti], 1), [])
assert.deepEqual(filterLowPriceSelectOrderCatalog([allEnabledPackage], 1), [allEnabledPackage])
assert.deepEqual(filterLowPriceSelectOrderCatalog([mixedPackage], 1), [])
assert.deepEqual(filterLowPriceSelectOrderCatalog([emptyPackage], 1), [])
assert.equal(filterLowPriceSelectOrderCatalog(fullCatalog, 0), fullCatalog)
assert.deepEqual(filterLowPriceSelectOrderCatalog(null, 1), [])
```
- [ ] **Step 2: Run helper tests and verify RED**
Run: `node scripts/run-node-tests.mjs tabWorkOrder/pages/createOrder/tests/lowPriceCatalogFilter.helpers.test.mjs`
Expected: FAIL because the helper module does not exist.
- [ ] **Step 3: Implement the minimal immutable filter**
Create `lowPriceCatalogFilter.helpers.js`:
```js
import { SELECT_ORDER_GOODS_FLAG } from './selectOrderCatalogClassification.js'
function hasMinPriceValidation(goods) {
return goods?.validMinSellPrice === 'Y'
}
export function filterLowPriceSelectOrderCatalog(items, lowPriceFlag) {
const list = Array.isArray(items) ? items : []
if (Number(lowPriceFlag) !== 1) return list
return list.reduce((result, item) => {
if (item?.goodsFlag == SELECT_ORDER_GOODS_FLAG.SINGLE) {
if (hasMinPriceValidation(item.goods)) result.push(item)
return result
}
if (item?.goodsFlag == SELECT_ORDER_GOODS_FLAG.MULTI_SPEC) {
const root = item.multipleSpecificationsGoods
const skuGoodsList = Array.isArray(root?.skuGoodsList)
? root.skuGoodsList.filter(hasMinPriceValidation)
: []
if (skuGoodsList.length) {
result.push({
...item,
multipleSpecificationsGoods: { ...root, skuGoodsList }
})
}
return result
}
if (item?.goodsFlag == SELECT_ORDER_GOODS_FLAG.PACKAGE) {
const goodsList = item.packageGoods?.goodsList
if (
Array.isArray(goodsList) &&
goodsList.length > 0 &&
goodsList.every(hasMinPriceValidation)
) {
result.push(item)
}
}
return result
}, [])
}
```
- [ ] **Step 4: Run helper tests and verify GREEN**
Run: `node scripts/run-node-tests.mjs tabWorkOrder/pages/createOrder/tests/lowPriceCatalogFilter.helpers.test.mjs`
Expected: PASS.
- [ ] **Step 5: Write the failing catalog integration test**
Create `lowPriceCatalogFilter.integration.test.mjs` with the real page config and a fake `api.getSelectOrderGoodsList` response containing one enabled single, one disabled single, one mixed-SKU multi-spec item, and one mixed package. Invoke the real `getSelectOrderGoodsList`, wait for its promise chain, and assert:
```js
assert.deepEqual(page.data.goodsData.map(item => item.testId), [
'enabled-single',
'mixed-multi'
])
assert.deepEqual(
page.data.goodsData[1].multipleSpecificationsGoods.skuGoodsList.map(item => item.id),
['sku-enabled']
)
assert.equal(page.data.packageList.length, 0)
assert.equal(page.data.otherProduct.length, 1)
```
Add a normal-order case proving all four catalog entries remain visible.
- [ ] **Step 6: Run the integration test and verify RED**
Run: `node scripts/run-node-tests.mjs tabWorkOrder/pages/createOrder/tests/lowPriceCatalogFilter.integration.test.mjs`
Expected: FAIL because `getSelectOrderGoodsList` stores and classifies the unfiltered response.
- [ ] **Step 7: Wire filtering before classification**
Import `filterLowPriceSelectOrderCatalog` in `createOrder.js`. After normalization and preprocessing, derive:
```js
const catalogData = filterLowPriceSelectOrderCatalog(
data,
orderObj?.lowPriceFlag
)
const classified = classifySelectOrderCatalog(catalogData, { subOrderList })
```
Use `catalogData` for both `goodsData` and `copyGoodsData` in the page patch.
- [ ] **Step 8: Run catalog tests and verify GREEN**
Run: `node scripts/run-node-tests.mjs tabWorkOrder/pages/createOrder/tests/lowPriceCatalogFilter.helpers.test.mjs tabWorkOrder/pages/createOrder/tests/lowPriceCatalogFilter.integration.test.mjs tabWorkOrder/pages/createOrder/tests/selectOrderCatalogClassification.test.mjs tabWorkOrder/pages/createOrder/tests/selectOrderCatalogPreprocess.test.mjs`
Expected: PASS.
- [ ] **Step 9: Commit Task 2**
```powershell
git add -- tabWorkOrder/pages/createOrder/services/lowPriceCatalogFilter.helpers.js tabWorkOrder/pages/createOrder/createOrder.js tabWorkOrder/pages/createOrder/tests/lowPriceCatalogFilter.helpers.test.mjs tabWorkOrder/pages/createOrder/tests/lowPriceCatalogFilter.integration.test.mjs
git commit -m "feat: filter low-price selectable goods"
```
### Task 3: Verify the complete feature
**Files:**
- Modify only if verification exposes an in-scope regression.
**Interfaces:**
- Consumes the completed customer-import and catalog-filter behavior.
- Produces fresh verification evidence for handoff.
- [ ] **Step 1: Run the complete create-order test suite**
Run: `npm run test:createOrder`
Expected: PASS with zero failures.
- [ ] **Step 2: Run work-order migration tests**
Run: `npm run test:workOrderMigration`
Expected: PASS with zero failures.
- [ ] **Step 3: Run the closure check**
Run: `npm run check:workOrderClosure`
Expected: PASS.
- [ ] **Step 4: Check formatting and scope**
Run: `git diff --check HEAD~2..HEAD` and `git status --short`.
Expected: no whitespace errors; only the pre-existing `config.js` and `yarn.lock` remain uncommitted.
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!