Commit 50d7c8c2 by 张立顺

feat: filter low-price selectable goods

1 parent 3543ff79
......@@ -74,6 +74,7 @@ import {
POSITION_BUCKET_DATA_KEYS
} from './services/selectOrderCatalogClassification'
import { preprocessSelectOrderCatalogItem } from './services/selectOrderCatalogPreprocess'
import { filterLowPriceSelectOrderCatalog } from './services/lowPriceCatalogFilter.helpers.js'
import {
mergeSubOrderListForEcho,
findCatalogSingleGoodsItem,
......@@ -568,7 +569,10 @@ Page({
let { detail } = e
if (Number(this.data.orderObj?.lowPriceFlag) === 1) {
const orderObj = buildCustomerOnlyOrder(this.data.orderObj, detail)
this.setData({ orderObj })
this.setData({
orderObj,
currentWordNumber: orderObj.remark.length
})
await this.echoCustomerProfileIfNeeded({ customer: orderObj.customer })
this.setData(closePagePopupPatch('customerInfoBox'))
return
......@@ -2049,10 +2053,16 @@ Page({
normalizeMarketingMetaOnItem(val)
preprocessSelectOrderCatalogItem(val)
})
const classified = classifySelectOrderCatalog(data, { subOrderList })
const catalogData = filterLowPriceSelectOrderCatalog(
data,
orderObj?.lowPriceFlag
)
const classified = classifySelectOrderCatalog(catalogData, {
subOrderList
})
const patch = {
goodsData: data,
copyGoodsData: data,
goodsData: catalogData,
copyGoodsData: catalogData,
packageList: classified.packageList,
frontGearArr: classified.frontGearArr,
sideBeforeRearGearArr: classified.sideBeforeRearGearArr,
......
......@@ -12,10 +12,14 @@
* @returns {Object}
*/
export function buildCustomerOnlyOrder(currentOrder, selectedRecord) {
const customer = { ...(selectedRecord?.customer || {}) }
if (!customer.customerSex) customer.customerSex = 1
if (!customer.experienceFlag) customer.experienceFlag = 'N'
if (!customer.salesType) customer.salesType = 0
return {
...(currentOrder || {}),
remark: selectedRecord?.remark ?? '',
customer: { ...(selectedRecord?.customer || {}) }
customer
}
}
......
/**
* @file 低价单可选商品目录过滤。
*/
import { SELECT_ORDER_GOODS_FLAG } from './selectOrderCatalogClassification.js'
function hasMinPriceValidation(goods) {
return goods?.validMinSellPrice === 'Y'
}
/**
* 低价单只展示已开启最低价格校验的商品。
* @param {Array<object>} items
* @param {number|string} lowPriceFlag
* @returns {Array<object>}
*/
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
}, [])
}
......@@ -40,7 +40,12 @@ describe('customerProfileEffects', () => {
assert.notEqual(result, current)
assert.notEqual(result.customer, selected.customer)
assert.deepEqual(result.customer, selected.customer)
assert.deepEqual(result.customer, {
...selected.customer,
customerSex: 1,
experienceFlag: 'N',
salesType: 0
})
assert.equal(result.selectPayType, 3)
assert.equal(result.payeeType, 1)
assert.equal(result.remark, '新客户备注')
......
......@@ -96,7 +96,11 @@ describe('createOrder customer profile import', () => {
assert.equal(context.page.data.orderObj.customer.customerId, 2)
assert.equal(context.page.data.orderObj.customer.customerName, '新客户')
assert.equal(context.page.data.orderObj.customer.customerSex, 1)
assert.equal(context.page.data.orderObj.customer.experienceFlag, 'N')
assert.equal(context.page.data.orderObj.customer.salesType, 0)
assert.equal(context.page.data.orderObj.remark, '新客户备注')
assert.equal(context.page.data.currentWordNumber, 5)
assert.equal(context.page.data.orderObj.selectPayType, 3)
assert.equal(context.page.data.orderObj.payeeType, 1)
assert.deepEqual(context.page.data.orderObj.subOrderList, [
......
import assert from 'node:assert/strict'
import { describe, it } from 'node:test'
import { filterLowPriceSelectOrderCatalog } from '../services/lowPriceCatalogFilter.helpers.js'
function single(testId, validMinSellPrice) {
return {
testId,
goodsFlag: 1,
goods: { validMinSellPrice }
}
}
function multi(testId, skuGoodsList) {
return {
testId,
goodsFlag: 2,
multipleSpecificationsGoods: { skuGoodsList }
}
}
function packageItem(testId, goodsList) {
return {
testId,
goodsFlag: 3,
packageGoods: { goodsList }
}
}
describe('filterLowPriceSelectOrderCatalog', () => {
it('keeps only single goods with minimum-price validation enabled', () => {
const enabled = single('enabled', 'Y')
const disabled = single('disabled', 'N')
const missing = single('missing')
assert.deepEqual(
filterLowPriceSelectOrderCatalog([enabled, disabled, missing], 1),
[enabled]
)
})
it('keeps only enabled SKUs without mutating the original multi-spec item', () => {
const enabledSku = { id: 'sku-enabled', validMinSellPrice: 'Y' }
const disabledSku = { id: 'sku-disabled', validMinSellPrice: 'N' }
const item = multi('mixed-multi', [enabledSku, disabledSku])
const [filtered] = filterLowPriceSelectOrderCatalog([item], '1')
assert.notEqual(filtered, item)
assert.notEqual(
filtered.multipleSpecificationsGoods,
item.multipleSpecificationsGoods
)
assert.deepEqual(
filtered.multipleSpecificationsGoods.skuGoodsList.map(sku => sku.id),
['sku-enabled']
)
assert.equal(item.multipleSpecificationsGoods.skuGoodsList.length, 2)
})
it('hides a multi-spec item when no enabled SKU remains', () => {
const item = multi('disabled-multi', [
{ id: 'sku-disabled', validMinSellPrice: 'N' },
{ id: 'sku-missing' }
])
assert.deepEqual(filterLowPriceSelectOrderCatalog([item], 1), [])
})
it('keeps a package only when its non-empty child list is fully enabled', () => {
const allEnabled = packageItem('enabled-package', [
{ validMinSellPrice: 'Y' },
{ validMinSellPrice: 'Y' }
])
const mixed = packageItem('mixed-package', [
{ validMinSellPrice: 'Y' },
{ validMinSellPrice: 'N' }
])
const missing = packageItem('missing-package', [
{ validMinSellPrice: 'Y' },
{}
])
const empty = packageItem('empty-package', [])
assert.deepEqual(
filterLowPriceSelectOrderCatalog(
[allEnabled, mixed, missing, empty],
1
),
[allEnabled]
)
})
it('keeps the complete original catalog for normal orders', () => {
const fullCatalog = [
single('disabled-single', 'N'),
multi('disabled-multi', [{ validMinSellPrice: 'N' }]),
packageItem('mixed-package', [
{ validMinSellPrice: 'Y' },
{ validMinSellPrice: 'N' }
]),
{ testId: 'unknown', goodsFlag: 99 }
]
assert.equal(filterLowPriceSelectOrderCatalog(fullCatalog, 0), fullCatalog)
})
it('treats invalid low-price input and unknown goods types as hidden', () => {
assert.deepEqual(filterLowPriceSelectOrderCatalog(null, 1), [])
assert.deepEqual(
filterLowPriceSelectOrderCatalog([{ goodsFlag: 99 }], 1),
[]
)
})
})
import assert from 'node:assert/strict'
import { register } from 'node:module'
import { describe, it } from 'node:test'
register(
'../../../../tests/work-order-migration/shims/create-order-context-loader.mjs',
import.meta.url
)
async function loadPageConfig() {
let pageConfig
globalThis.getApp = () => ({
globalData: { positionTypeList: [], configInfo: {} }
})
globalThis.Page = config => {
pageConfig = config
}
globalThis.wx = {
getAccountInfoSync: () => ({
miniProgram: { appId: 'test-app-id', envVersion: 'develop' }
}),
getSystemInfoSync: () => ({ platform: 'devtools' }),
getStorageSync: () => '',
hideLoading: () => {},
$util: { getUserInfo: () => ({}) }
}
await import(`../createOrder.js?catalog-filter=${Date.now()}-${Math.random()}`)
return pageConfig
}
function createCatalog() {
return [
{
testId: 'enabled-single',
goodsFlag: 1,
goods: {
merchantGoodsId: 'single-enabled',
merchantGoodsPosition: 1,
validMinSellPrice: 'Y',
sellPrice: 80
}
},
{
testId: 'disabled-single',
goodsFlag: 1,
goods: {
merchantGoodsId: 'single-disabled',
merchantGoodsPosition: 2,
validMinSellPrice: 'N',
sellPrice: 90
}
},
{
testId: 'mixed-multi',
goodsFlag: 2,
multipleSpecificationsGoods: {
specificationList: [],
skuGoodsList: [
{
id: 'sku-enabled',
validMinSellPrice: 'Y',
sellPrice: 100
},
{
id: 'sku-disabled',
validMinSellPrice: 'N',
sellPrice: 110
}
]
}
},
{
testId: 'mixed-package',
goodsFlag: 3,
packageGoods: {
goodsList: [
{ validMinSellPrice: 'Y', sellPrice: 50 },
{ validMinSellPrice: 'N', sellPrice: 60 }
]
}
}
]
}
function createPage(pageConfig, lowPriceFlag) {
return {
data: {
...pageConfig.data,
first: false,
orderObj: {
...pageConfig.data.orderObj,
lowPriceFlag,
merchantId: 100,
sceneType: 1,
subOrderList: []
}
},
setData(patch, callback) {
Object.assign(this.data, patch)
callback?.()
},
async syncCreateOrderMarketingFlags() {},
getChooseList() {}
}
}
async function loadCatalog(pageConfig, lowPriceFlag) {
globalThis.__WORK_ORDER_MOCK_API__ = {
getSelectOrderGoodsList: () => ({ code: 0, data: createCatalog() })
}
const page = createPage(pageConfig, lowPriceFlag)
await pageConfig.getSelectOrderGoodsList.call(page, 100, 1)
await new Promise(resolve => setImmediate(resolve))
return page
}
describe('createOrder low-price catalog filtering', () => {
it('filters low-price catalog before page classification', async () => {
const pageConfig = await loadPageConfig()
const page = await loadCatalog(pageConfig, 1)
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.frontGearArr.length, 1)
assert.equal(page.data.otherProduct.length, 1)
assert.equal(page.data.packageList.length, 0)
})
it('keeps the full catalog for normal orders', async () => {
const pageConfig = await loadPageConfig()
const page = await loadCatalog(pageConfig, 0)
assert.deepEqual(page.data.goodsData.map(item => item.testId), [
'enabled-single',
'disabled-single',
'mixed-multi',
'mixed-package'
])
assert.deepEqual(
page.data.goodsData[2].multipleSpecificationsGoods.skuGoodsList.map(
item => item.id
),
['sku-enabled', 'sku-disabled']
)
assert.equal(page.data.packageList.length, 1)
})
})
......@@ -24,5 +24,11 @@ export default {
code: 0,
data: { yqPhoneConfig: '[]' }
})
},
getSelectOrderGoodsList(data) {
return configuredResponse('getSelectOrderGoodsList', data, {
code: 0,
data: []
})
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!