Commit ef1179f9 by 张立顺

feat 功能自测

1 parent 03038b9a
Showing 28 changed files with 950 additions and 69 deletions
......@@ -23,7 +23,7 @@ const accountInfo = wx.getAccountInfoSync();
const systemInfo = wx.getSystemInfoSync();
const envName = accountInfo.miniProgram.envVersion;
//手动控制体验版环境的请求 true就依据下面index false就默认2
const manual = true;
const manual = false;
const release = false;
// 判断小程序环境
......
......@@ -10,7 +10,7 @@
6. 订单收款方式步骤使用响应式高度,标题和按钮固定,超出可用高度的选项可以纵向滚动。
7. 新建工单页底部只显示“直接下单”,不显示“建档”按钮。
8. 低价单商品行回显最低价;未开启最低价时明确显示“未开启”。
9. 商品确认时仅回显最低价,不弹提醒;用户改价后,如未开启最低价或录入价未严格低于最低价,立即提示“价格未触发最低价,其他正常单请到生意助手侧录单”。
9. 商品确认和改价时只回显最低价,不执行最低价资格校验;提交时如整单没有商品严格低于最低价,提示“价格未触发最低价,其他正常单请到生意助手侧录单”。
## 数据行为
......@@ -21,7 +21,7 @@
5. 固定用户保持现状,sessionId 沿用系统原登录态且不会被固定用户模拟覆盖。
6. 工作台不查询订单待审核或异常数量;退款审核和招聘待处理统计保持原逻辑。
7. 下单页销售顾问直接将已选 4S 店作为唯一合作门店,不依赖第二次关联门店查询;非低价单仍使用原查询与用户上下文。
8. 普通商品、多规格 SKU 和套餐每个子商品都必须 `validMinSellPrice='Y'`,且基础单价严格小于 `minSellPrice`;提交前整单复核,任一不满足都不调用下单接口。
8. 普通商品、多规格 SKU 和套餐子商品均参与整单复核;任一商品满足 `validMinSellPrice='Y'` 且基础单价严格小于 `minSellPrice` 即可进入审批确认,全部不满足时不调用下单接口。
9. 上述反向最低价规则仅适用于 `lowPriceFlag=1`,普通工单原有最低价校验保持不变。
## 自动验证
......
......@@ -37,11 +37,9 @@
`yqMerchantId` 和下单字段 `sellerMerchantId`;这些值会继续传入待补录查询、普通下单和
补录下单,不再从临时固定用户的默认门店推导。
低价单选中的每个普通商品、多规格 SKU 和套餐子商品都必须开启最低价
(`validMinSellPrice='Y'`),且录入基础单价必须严格小于 `minSellPrice`。选品后商品行显示
“最低价:¥金额”;未开启时显示“最低价:未开启”。商品确认时仅静默同步回显和校验状态,
不弹提醒;价格输入时实时校验,提交前再整单复核。未满足时提示“价格未触发最低价,其他正常单请到生意助手侧录单”并阻止下单。该规则
只在 `lowPriceFlag=1` 时启用,不改变普通工单原有最低价校验。
低价单的普通商品、多规格 SKU 和套餐子商品中,只要任一项开启最低价
(`validMinSellPrice='Y'`),且录入基础单价严格小于 `minSellPrice`,整单即可继续。选品后商品行显示
“最低价:¥金额”;未开启时显示“最低价:未开启”。输入和失焦不执行最低价资格校验,提交时再整单复核;未满足时只提示“价格未触发最低价,其他正常单请到生意助手侧录单”并阻止下单。满足后展示审批确认弹层,确认成功后返回低价单“待审批”页签。该规则只在 `lowPriceFlag=1` 时启用,不改变普通工单原有最低价校验。
进入下单页选择销售顾问或交付专员时,低价单直接回显前一步选定的 4S 店作为唯一合作
门店,并按该店加载员工;不再依赖“园区关联 4S 店”接口再次返回该门店。非低价单继续使用
......
......@@ -113,8 +113,7 @@ flowchart LR
低价提单按实际提交叶子商品校验:普通商品读取 `goods`,多规格读取已选 SKU,套餐逐项读取
`packageGoods.goodsList`。当前价优先取改价后的 `basePrice`,再取 `sellPrice/price`,不使用
折扣后的 `finalPrice`。商品确认时仅静默同步回显和错误状态,价格输入时才实时提示,提交前整单复核;未开启最低价、最低价
缺失、价格为空、等于或高于最低价都提示“价格未触发最低价,其他正常单请到生意助手侧录单”。
折扣后的 `finalPrice`。输入和失焦不执行最低价资格判断,仅在提交时整单复核;任一商品开启最低价且当前价严格低于 `minSellPrice` 即可继续。全部未触发时只提示“价格未触发最低价,其他正常单请到生意助手侧录单”。
商品行仅在低价模式展示“最低价:¥金额/未开启”。
- `goodsFlag=1`:普通单商品,可按前挡、侧后挡、天窗等部位分桶。
......@@ -211,9 +210,9 @@ flowchart TD
- 战败单删除备注、车牌/VIN/品牌等字段,设置 `customer.experienceFlag = Y`。
- 所有分支固定写入 `filmOrder = 0`。
### 6.2 低价审批现状
### 6.2 低价审批
`minPriceApproval.js` 仍可计算普通商品、规格商品和套餐子项的旧商品级低价审批列表,状态字典也包含 `14=审批中`;但 [`shouldUseMinPriceApprovalFlow`](../../tabWorkOrder/pages/createOrder/services/orderMerchantConfig.js) 当前固定返回 `false`,因此创建页不展示旧审批确认弹层。当前 `lowPriceFlag=1` 链路使用 [`lowPriceGoodsValidation.helpers.js`](../../tabWorkOrder/pages/createOrder/services/lowPriceGoodsValidation.helpers.js) 做下单资格校验:商品必须开启最低价且当前基础单价严格低于 `minSellPrice`。列表仍使用区域订单查询和审批状态统计,创建时由用户显式选择下单 4S 店并传递低价标记;旧审批弹层与新资格校验不能混作同一功能。
`lowPriceFlag=1` 链路使用 [`lowPriceGoodsValidation.helpers.js`](../../tabWorkOrder/pages/createOrder/services/lowPriceGoodsValidation.helpers.js) 做整单资格校验,并用 `minPriceApproval.js` 按同一 `minSellPrice` 口径构建审批商品列表。校验通过后先展示审批确认弹层,用户确认后才请求下单接口;成功后返回低价单“待审批”页签。低价单订单类型固定为正常订单,商品价格小于 `0` 或大于 `100000` 元时阻止提交。
## 7. 支付确认
......
......@@ -16,7 +16,7 @@
|---|---|---|---|---|
| GAP-01 | 撤销按钮过滤微信、POS、支付宝(`selectPayType` 1/3/4),并在确认前后两次检查退款步骤;门店、嘀加、转账、其他收款可能进入撤销分支。 | 11 月评审完成稿描述为“除待跟进工单外,仅门店收款订单可撤销;线上支付走退款”。 | 支付类型 5/6/7 的撤销与退款口径可能不一致。 | 产品、支付后端、订单前端 |
| GAP-02 | 出库页要求出库数量大于 0。 | 2026 年 5 月施工单出入库 PRD 允许虚拟/手工库存场景填 0。 | 虚拟商品无法按目标规则提交。 | 产品、库存后端、施工单前端 |
| GAP-03 | 低价审批入口当前由 `shouldUseMinPriceApprovalFlow` 固定关闭,现有单测明确验证“回退后禁用”。 | 2026 年 6 月 PRD 描述活动商品低价审批及审批中状态。 | PRD 目标态与当前发布分支不一致;状态 14 已存在于状态字典但入口未启用。 | 产品、订单后端、订单前端 |
| GAP-03(已关闭) | 低价单提交资格满足后展示审批确认弹层,确认提交成功后返回“待审批”列表。 | 2026 年 6 月 PRD 描述活动商品低价审批及审批中状态。 | 前端入口偏差已补齐;后端审批状态与消息通知仍需联调验证。 | 订单后端、消息中心 |
| GAP-04 | 技师编辑、商品/服务项目编辑分别受 `SHIGONGQUEREN` 与 `CHUANGJIANSHIGONGDAN` 权限控制,页面不直接按“是否技师”硬编码。 | 施工单 PRD 表述为技师不可修改商品和服务项目。 | 若角色权限配置不严,角色语义与页面能力可能偏离。 | 权限平台、产品、施工单前端 |
| GAP-05 | 标记错误前会查询退款步骤和施工汇总;存在未完成施工单时弹警告后仍可进入纠错流程。 | 10 月 PRD 表述错误订单不能继续施工,已有施工数据应清理。 | 清理动作依赖后端,前端无法证明最终数据一致性。 | 订单后端、施工后端 |
......
......@@ -282,7 +282,7 @@ def render_markdown(
"|---|---|---|---|---|",
"| GAP-01 | 撤销按钮过滤微信、POS、支付宝(`selectPayType` 1/3/4),并在确认前后两次检查退款步骤;门店、嘀加、转账、其他收款可能进入撤销分支。 | 11 月评审完成稿描述为“除待跟进工单外,仅门店收款订单可撤销;线上支付走退款”。 | 支付类型 5/6/7 的撤销与退款口径可能不一致。 | 产品、支付后端、订单前端 |",
"| GAP-02 | 出库页要求出库数量大于 0。 | 2026 年 5 月施工单出入库 PRD 允许虚拟/手工库存场景填 0。 | 虚拟商品无法按目标规则提交。 | 产品、库存后端、施工单前端 |",
"| GAP-03 | 低价审批入口当前由 `shouldUseMinPriceApprovalFlow` 固定关闭,现有单测明确验证“回退后禁用”。 | 2026 年 6 月 PRD 描述活动商品低价审批及审批中状态。 | PRD 目标态与当前发布分支不一致;状态 14 已存在于状态字典但入口未启用。 | 产品、订单后端、订单前端 |",
"| GAP-03(已关闭) | 低价单提交资格满足后展示审批确认弹层,确认提交成功后返回“待审批”列表。 | 2026 年 6 月 PRD 描述活动商品低价审批及审批中状态。 | 前端入口偏差已补齐;后端审批状态与消息通知仍需联调验证。 | 订单后端、消息中心 |",
"| GAP-04 | 技师编辑、商品/服务项目编辑分别受 `SHIGONGQUEREN` 与 `CHUANGJIANSHIGONGDAN` 权限控制,页面不直接按“是否技师”硬编码。 | 施工单 PRD 表述为技师不可修改商品和服务项目。 | 若角色权限配置不严,角色语义与页面能力可能偏离。 | 权限平台、产品、施工单前端 |",
"| GAP-05 | 标记错误前会查询退款步骤和施工汇总;存在未完成施工单时弹警告后仍可进入纠错流程。 | 10 月 PRD 表述错误订单不能继续施工,已有施工数据应清理。 | 清理动作依赖后端,前端无法证明最终数据一致性。 | 订单后端、施工后端 |",
"",
......
# Low-Price Order Approval Completion Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Complete the low-price order flow by restricting it to normal orders, requiring approval confirmation, returning successful submissions to the pending list, and rejecting invalid price boundaries.
**Architecture:** Reuse the existing low-price approval sheet and pure approval-list builder. Add low-price-aware order-type helpers, a pure price-boundary helper consumed by both input and submit paths, and a small success-navigation helper so ordinary orders retain their current flow.
**Tech Stack:** WeChat Mini Program JavaScript, ES modules, Node.js built-in test runner.
## Global Constraints
- Preserve the user's existing `config.js` and `yarn.lock` changes.
- Use only `价格未触发最低价,其他正常单请到生意助手侧录单` when no goods triggers the minimum price.
- A low-price order is eligible when any submitted goods entry has `validMinSellPrice === 'Y'` and a current base price strictly below numeric `minSellPrice`.
- Low-price orders allow only order type `1` (`正常订单`).
- Reject prices below `0` with `商品价格不能小于0元` and prices above `100000` with `商品价格不能大于100000元`.
- Do not add dependencies, APIs, or `import.meta` to mini-program runtime files.
---
### Task 1: Restrict low-price order type
**Files:**
- Modify: `tabWorkOrder/pages/createOrder/services/orderMerchantConfig.js`
- Modify: `tabWorkOrder/pages/createOrder/createOrder.js`
- Test: `tabWorkOrder/pages/createOrder/tests/orderMerchantConfig.test.mjs`
**Interfaces:**
- Produces: `buildOrderTypePickerList(orderTypeList, createAllGoodsFlag, lowPriceFlag)`.
- Produces: `isAllowedLimitedOrderType(djOrderType, lowPriceFlag)`.
- [x] Change tests to require only normal order for `lowPriceFlag=1`, while normal restricted scenes retain normal and internal settlement.
- [x] Run `node scripts/run-node-tests.mjs tabWorkOrder/pages/createOrder/tests/orderMerchantConfig.test.mjs` and verify the new assertions fail under the two-type implementation.
- [x] Add the optional `lowPriceFlag` argument and pass `orderObj.lowPriceFlag` from `applyOrderTypeConfig`; normalize low-price order data to type `1`.
- [x] Re-run the focused test and verify it passes.
### Task 2: Restore the approval confirmation gate
**Files:**
- Modify: `tabWorkOrder/pages/createOrder/submitStrategy.js`
- Modify: `tabWorkOrder/pages/createOrder/services/minPriceApproval.js`
- Test: `tabWorkOrder/pages/createOrder/tests/minPriceApproval.test.mjs`
- Create: `tabWorkOrder/pages/createOrder/tests/lowPriceSubmitFlow.integration.test.mjs`
**Interfaces:**
- Consumes: `buildMinPriceApprovalList(goodsList): ApprovalItem[]`.
- Calls: `page.openMinPriceApprovalSheet(items, save)` on the first valid low-price submission.
- Calls: `finishSubmit(save, true)` only after `onConfirmMinPriceApprovalSubmit`.
- [x] Add tests proving approval comparison uses `minSellPrice` and first submit opens the sheet without requesting the API.
- [x] Run the two focused tests and verify failures show the missing gate and old `upgradeShopMinPrice` preference.
- [x] Import and invoke `buildMinPriceApprovalList` in `finishSubmit`; when low-price items exist and `skipApprovalSheet` is false, open the sheet and return.
- [x] Keep confirmation using `executeAfterApproval` so the API is invoked exactly once.
- [x] Re-run the focused tests and verify they pass.
### Task 3: Return successful low-price submissions to pending
**Files:**
- Create: `tabWorkOrder/pages/createOrder/services/lowPriceSubmitNavigation.helpers.js`
- Modify: `tabWorkOrder/pages/createOrder/submitStrategy.js`
- Modify: `pages/tabWorkOrder/pages/index/index.js`
- Test: `tabWorkOrder/pages/createOrder/tests/lowPriceSubmitNavigation.helpers.test.mjs`
- Test: `tabWorkOrder/pages/createOrder/tests/lowPriceSubmitFlow.integration.test.mjs`
- Test: `tests/work-order-migration/low-price-order-flow.test.mjs`
**Interfaces:**
- Produces: `buildPendingLowPriceListPatch(): { activeIndex: 1, tabIndex: 1, keyword: '', searchObj: {} }`.
- Produces: `isLowPriceSubmit(orderObj): boolean`.
- Low-price success: refresh and patch the source low-price list page before navigating back; `onShow` performs the refreshed search. If the previous page is not that list, fall back to `/pages/tabWorkOrder/pages/index/index?activeIndex=1`.
- [x] Add tests for low-price versus ordinary success navigation and route-option tab synchronization.
- [x] Run focused tests and verify current `confirmOrder` redirect fails the expectations.
- [x] Implement the pure patch helper, update list `onRoute` to synchronize both tab indexes, and branch successful submission by `lowPriceFlag`.
- [x] Re-run focused tests and verify low-price and ordinary paths pass.
### Task 4: Reject negative and over-limit prices
**Files:**
- Create: `tabWorkOrder/pages/createOrder/services/goodsPriceBoundary.helpers.js`
- Modify: `tabWorkOrder/pages/createOrder/createOrder.js`
- Modify: `tabWorkOrder/pages/createOrder/submitStrategy.js`
- Test: `tabWorkOrder/pages/createOrder/tests/goodsPriceBoundary.helpers.test.mjs`
- Test: `tabWorkOrder/pages/createOrder/tests/goodsPriceBoundary.integration.test.mjs`
**Interfaces:**
- Produces: `validateGoodsPriceInput(rawValue): { valid, value, message }`.
- Produces: `findGoodsPriceBoundaryError(goodsList): string`.
- Stores invalid input metadata on the affected goods object as `priceBoundaryError` without changing the last valid price.
- [x] Add pure tests for `-1`, `100000.01`, `0`, `100000`, and two-decimal normalization.
- [x] Add page tests proving invalid values show the exact message, do not update price, and block submission until corrected.
- [x] Run focused tests and verify failures under the current sanitizing/clamping behavior.
- [x] Implement the helper, use it in low-price `changePrice` and `changeMealPrice`, and recheck the stored values during low-price goods submission validation.
- [x] Re-run focused tests and verify they pass.
### Task 5: Update living documentation and verify
**Files:**
- Modify: `docs/tabWorkOrder/createOrder.md`
- Modify: `docs/order-lifecycle/README.md`
- Modify only if an in-scope regression is found elsewhere.
- [x] Update approval-flow and low-price order-type documentation; remove statements saying the approval entry is disabled.
- [x] Run `npm run test:createOrder`.
- [x] Run `npm run test:workOrder`.
- [x] Run `git diff --check`.
- [x] Scan mini-program runtime JavaScript for new `import.meta` and verify no new occurrence exists under the modified runtime files.
- [x] Inspect `git diff --stat` and `git status --short`; preserve unrelated `config.js` and `yarn.lock` modifications.
# 低价单审批链路与金额边界补全设计
## 目标
补全低价单创建链路的四项行为:低价单只能创建正常订单;满足最低价触发条件后先展示审批确认弹层;确认提交成功后返回低价单列表的“待审批”页签;负数和超过 `100000` 元的商品价格必须明确拒绝,不能静默去符号或截断。
最低价未触发时只使用文案:`价格未触发最低价,其他正常单请到生意助手侧录单`。旧文案“订单中必须有个商品价格低于商品最低价才能提单”不再使用。
## 方案选择
采用复用现有能力的最小改动方案:继续使用创建页已经存在的 `minPriceApprovalSheet` 和 `buildMinPriceApprovalList`,在提交策略中恢复接线;订单成功后返回来源低价单列表并切换页签;金额边界使用独立纯函数校验并由输入和提交两个阶段共同消费。
没有新建第二套审批组件,因为现有底部弹层已经具备商品、套餐子项、取消和确认提交交互。也不把低价单成功页改造成新的中转页,避免扩大页面栈和路由维护范围。
## 订单类型
- 仅当 `Number(orderObj.lowPriceFlag) === 1` 时,订单类型选择器只保留 `{ text: '正常订单', value: 1 }`。
- 低价单初始化和门店配置刷新时都强制把 `djOrderType` 归一为 `1`,防止路由或历史数据带入内部结算。
- 普通精品升级订单仍保持原有“正常订单 + 内部结算”范围,不扩大本次改动影响。
## 最低价审批确认
低价资格仍按当前已确认规则判断:实际提交的普通商品、选中 SKU、套餐子商品中,只要有一个商品满足 `validMinSellPrice === 'Y'` 且当前基础单价严格小于 `minSellPrice`,整单即可继续。
提交链路如下:
1. 先执行必填项、商品、总价和金额边界校验。
2. 资格不满足时弹出唯一文案 `价格未触发最低价,其他正常单请到生意助手侧录单`,不请求下单接口。
3. 资格满足时根据相同的 `minSellPrice` 口径构建审批商品列表,并打开现有底部审批确认弹层。
4. 点击“取消”只关闭弹层,不请求接口。
5. 点击“确认提交”关闭弹层并跳过二次弹层,调用一次原下单接口。
审批列表只展示实际低于各自 `minSellPrice` 的商品。旧 helper 中优先使用 `upgradeShopMinPrice` 的规则改为只使用 `minSellPrice`,避免资格校验与弹层内容不一致。
## 提交成功返回
低价单下单接口成功后,不进入 `confirmOrder`:
- 刷新全局工单数据;
- 返回来源低价单列表页;
- 同时设置 `activeIndex=1`、`tabIndex=1`,清空关键词并重新查询;
- 列表请求因此携带待审批状态 `[1, 2]`。
普通订单继续进入 `confirmOrder`,保存建档和预录流程保持不变。如果来源页实例不可用,则使用低价单列表路由作为兜底,避免停留在创建页。
## 金额边界
现有金额上限沿用 `100000` 元,新增明确规则:
- 输入值小于 `0`:提示 `商品价格不能小于0元`;
- 输入值大于 `100000`:提示 `商品价格不能大于100000元`;
- 非法值不写入商品基础价,不再把 `-1` 变为 `1`,也不再把 `100000.01` 截为 `100000`;
- 商品记录保留当前金额错误状态,提交时再次拦截;用户录入合法值后清除错误状态;
- `100000` 本身合法;三位及以上小数继续按现有规则规范为两位,不在本次范围内改为报错。
金额范围校验不是最低价资格校验,因此允许在输入时立即提示;最低价是否触发仍然只在提交时判断。
## 兼容和错误处理
- 只改变 `lowPriceFlag=1` 的订单类型、审批确认和成功跳转。
- 金额边界保护覆盖普通商品、选中 SKU 和套餐子商品,但不改变活动商品已有的不可改价限制。
- 下单接口失败继续使用接口返回文案,弹层确认后可重新提交。
- 不新增接口、不新增依赖、不使用 `import.meta`,保持微信小程序脚本兼容。
## 测试设计
1. 订单类型纯函数:低价单只保留正常订单,普通限制场景仍保留正常订单和内部结算。
2. 审批提交集成:首次提交只打开弹层、不调用 API;确认后只调用一次 API;审批商品列表和最低价资格使用同一 `minSellPrice` 口径。
3. 成功跳转:低价单成功返回并把列表切到待审批;普通订单仍进入 `confirmOrder`。
4. 金额纯函数及页面集成:负数和超上限明确失败且不截断,合法边界通过,错误未修正时提交被拦截。
5. 回归:运行创建页测试、工单迁移测试、生命周期测试、闭包检查和小程序源码兼容扫描。
## 非目标
- 不修改“整单任一商品满足即可提交”的已确认规则。
- 不恢复输入或失焦时的最低价资格校验。
- 不修改商品目录展示全部商品和客户档案仅导入客户信息的逻辑。
- 不实现后端审批状态、企微通知和 H5 审批端能力。
......@@ -79,7 +79,7 @@ flowchart TD
## 5. 定价与营销
- [`productStrategy.js`](../../tabWorkOrder/pages/createOrder/productStrategy.js):`getProductStrategy` → Normal / MultiSpec / Package
- [`minPriceApproval.js`](../../tabWorkOrder/pages/createOrder/services/minPriceApproval.js):保留低价审批商品计算 helper;当前 [`shouldUseMinPriceApprovalFlow`](../../tabWorkOrder/pages/createOrder/services/orderMerchantConfig.js) 固定返回 `false`,发布分支未启用审批入口
- [`minPriceApproval.js`](../../tabWorkOrder/pages/createOrder/services/minPriceApproval.js):按 `minSellPrice` 计算低价审批商品;低价单提交校验通过后打开审批确认弹层
- `~/utils/marketingFlag`、`orderSubOrderExtras`:活动价、子单营销字段
订单类型 `djOrderType`:打折 / 买赠 / 组合等影响 `order-goods-row` 展示与 `checkGoods` 规则。
......@@ -87,11 +87,12 @@ flowchart TD
`lowPriceFlag=1` 时额外启用
[`lowPriceGoodsValidation.helpers.js`](../../tabWorkOrder/pages/createOrder/services/lowPriceGoodsValidation.helpers.js):
- 普通商品、选中的多规格 SKU、套餐内每个子商品都必须 `validMinSellPrice='Y'`;
- 当前基础单价按 `basePrice -> sellPrice -> price` 读取,必须严格小于 `minSellPrice`;
- 普通商品、选中的多规格 SKU、套餐子商品中任一项满足即可继续;
- 单项满足条件为 `validMinSellPrice='Y'`,且按 `basePrice -> sellPrice -> price` 读取的基础单价严格小于 `minSellPrice`;
- 等于/高于最低价、未开启、缺少最低价或价格为空都统一提示“价格未触发最低价,其他正常单请到生意助手侧录单”;
- 商品行回显“最低价:¥金额”,未开启时显示“最低价:未开启”;
- 商品确认时仅静默回显并同步校验状态,不弹提醒;输入时实时提示,失焦时静默同步,提交前复核,普通工单原最低价逻辑不变。
- 输入和失焦不执行最低价资格校验;提交时复核并展示审批确认弹层,确认成功后返回低价单“待审批”列表;
- 商品价格小于 `0` 或大于 `100000` 元时明确拒绝,普通工单原最低价逻辑不变。
---
......
......@@ -814,10 +814,14 @@ Page({
onRoute(options) {
// console.log('activeIndex' in options);
if ('activeIndex' in options) {
const activeIndex = Number(options.activeIndex) || 0
// let { searchObj } = this.data
// delete searchObj.inviteStatus
this.setData({
activeIndex: options.activeIndex
activeIndex,
tabIndex: activeIndex,
keyword: '',
searchObj: {}
// searchObj.inviteStatusList
})
}
......@@ -860,6 +864,7 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.onRoute(options || {})
this.syncUserContext()
},
......
......@@ -87,6 +87,10 @@ import {
validateLowPriceGoodsList
} from './services/lowPriceGoodsValidation.helpers.js'
import {
findGoodsPriceBoundaryError,
validateGoodsPriceInput
} from './services/goodsPriceBoundary.helpers.js'
import {
ensureCatalogUpgradePrice,
seedCatalogSellPriceFromCatalog,
seedMarketingActivitySellPrice,
......@@ -1048,17 +1052,30 @@ Page({
) {
return
}
if (value.length > 1 && value.startsWith('0') && value[1] !== '.') {
value = value.replace(/^0+/, '')
if (value === '') {
value = '0'
} else if (value.startsWith('.')) {
value = '0' + value
const strategy = getProductStrategy(goodsList[index])
const subItem = strategy?.getSubItemData?.(gindex)
let number
if (this.isLowPriceOrder()) {
const priceValidation = validateGoodsPriceInput(value)
if (!priceValidation.valid) {
if (subItem) subItem.priceBoundaryError = priceValidation.message
this.setData({ goodsList })
wx.$util.showToast(priceValidation.message)
return subItem?.basePrice ?? subItem?.sellPrice
}
if (subItem) subItem.priceBoundaryError = ''
number = priceValidation.value
} else {
if (value.length > 1 && value.startsWith('0') && value[1] !== '.') {
value = value.replace(/^0+/, '')
if (value === '') {
value = '0'
} else if (value.startsWith('.')) {
value = '0' + value
}
}
number = wx.$util.removeLeadingZerosAndEnsureNonNegative(value)
}
let number = wx.$util.removeLeadingZerosAndEnsureNonNegative(value)
const strategy = getProductStrategy(goodsList[index])
// 策略模式应用:
// 获取对应的策略实例(此处预期为 PackageProductStrategy)。
// 利用策略类封装的 updateSubItemPrice 方法更新子商品价格,
......@@ -1114,10 +1131,22 @@ Page({
return
}
let number = wx.$util.removeLeadingZerosAndEnsureNonNegative(value)
if (strategy) {
const data = strategy.getData()
let number
if (this.isLowPriceOrder()) {
const priceValidation = validateGoodsPriceInput(value)
if (!priceValidation.valid) {
data.priceBoundaryError = priceValidation.message
this.setData({ goodsList })
wx.$util.showToast(priceValidation.message)
return strategy.getBasePrice()
}
data.priceBoundaryError = ''
number = priceValidation.value
} else {
number = wx.$util.removeLeadingZerosAndEnsureNonNegative(value)
}
// 再次编辑:输入框展示总价,改价需换算为单价
if (data?.resetOrder) {
const count = strategy.getCount() || 1
......@@ -1146,8 +1175,8 @@ Page({
strategy.setBasePrice(number)
}
this.setGoodsTotal(goodsList)
return number
}
return number
},
/**
* 单价低于最低价时展示审批说明(仅失焦触发,不阻断改价)
......@@ -1337,6 +1366,8 @@ Page({
checkGoods(save, subOrderList, priceDisabled, goodsList, orderObj) {
if (save) return false
if (Number(orderObj?.lowPriceFlag) === 1) {
const priceBoundaryError = findGoodsPriceBoundaryError(goodsList)
if (priceBoundaryError) return priceBoundaryError
const lowPriceValidation = validateLowPriceGoodsList(goodsList)
if (!lowPriceValidation.valid) {
return LOW_PRICE_NOT_TRIGGERED_MESSAGE
......@@ -2879,7 +2910,7 @@ Page({
})
},
/**
* 按门店配置与业务场景同步订单类型 picker(限制场景:正常订单 + 内部结算)
* 按门店配置与业务场景同步订单类型 picker;低价单仅允许正常订单。
* @param {0|1} createAllGoodsFlag
* @param {{ preserveOrderType?: boolean }} [options]
*/
......@@ -2887,20 +2918,25 @@ Page({
const { orderTypeList, orderObj } = this.data
const orderTypePickerList = buildOrderTypePickerList(
orderTypeList,
createAllGoodsFlag
createAllGoodsFlag,
orderObj?.lowPriceFlag
)
const patch = { createAllGoodsFlag, orderTypePickerList }
const lowPriceFlag = orderObj?.lowPriceFlag
const isExistingOrder = orderObj && !!orderObj.id
const isDisallowedType =
orderObj &&
orderObj.djOrderType &&
!isAllowedLimitedOrderType(orderObj.djOrderType)
!isAllowedLimitedOrderType(orderObj.djOrderType, lowPriceFlag)
if (
if (Number(lowPriceFlag) === 1) {
patch.orderTypeName = '正常订单'
patch['orderObj.djOrderType'] = ORDER_TYPE.NORMAL
} else if (
createAllGoodsFlag === 0 &&
!options.preserveOrderType &&
!(isExistingOrder && isDisallowedType) &&
!isAllowedLimitedOrderType(orderObj?.djOrderType)
!isAllowedLimitedOrderType(orderObj?.djOrderType, lowPriceFlag)
) {
patch.orderTypeName = '正常订单'
patch['orderObj.djOrderType'] = ORDER_TYPE.NORMAL
......
/**
* @file 创建订单商品金额边界规则。
*/
import { resolveLowPriceGoodsEntries } from './lowPriceGoodsValidation.helpers.js'
export const GOODS_PRICE_MAX = 100000
export const GOODS_PRICE_NEGATIVE_MESSAGE = '商品价格不能小于0元'
export const GOODS_PRICE_OVER_LIMIT_MESSAGE = '商品价格不能大于100000元'
/**
* 校验并按现有金额精度规则规范输入值,不静默修正越界金额。
* @param {*} rawValue
* @returns {{valid:boolean,value:string|null,message:string}}
*/
export function validateGoodsPriceInput(rawValue) {
const raw = String(rawValue ?? '').trim()
if (raw.includes('-')) {
return {
valid: false,
value: null,
message: GOODS_PRICE_NEGATIVE_MESSAGE
}
}
const filtered = raw.replace(/[^0-9.]/g, '')
const numericValue = Number.parseFloat(filtered || '0')
if (Number.isFinite(numericValue) && numericValue > GOODS_PRICE_MAX) {
return {
valid: false,
value: null,
message: GOODS_PRICE_OVER_LIMIT_MESSAGE
}
}
let normalized = filtered.replace(/^0+(?=\d)|^0+(?=\.)/, '')
if (!normalized) normalized = '0'
if (normalized === '.') normalized = '0.'
if (normalized.startsWith('.')) normalized = `0${normalized}`
let [integerPart, decimalPart] = normalized.split('.')
if (decimalPart !== undefined) {
decimalPart = decimalPart.substring(0, 2)
normalized = `${integerPart}.${decimalPart}`
}
const normalizedNumber = Number.parseFloat(normalized)
if (!Number.isFinite(normalizedNumber)) normalized = '0'
return { valid: true, value: normalized, message: '' }
}
/**
* @param {Array<object>} goodsList
* @returns {string}
*/
export function findGoodsPriceBoundaryError(goodsList = []) {
const entries = resolveLowPriceGoodsEntries(goodsList)
for (const goods of entries) {
if (goods?.priceBoundaryError) return goods.priceBoundaryError
const rawPrice =
goods?.basePrice !== undefined && goods.basePrice !== ''
? goods.basePrice
: goods?.sellPrice !== undefined && goods.sellPrice !== ''
? goods.sellPrice
: goods?.price
if (rawPrice === '' || rawPrice === null || rawPrice === undefined) continue
const numericPrice = Number(rawPrice)
if (Number.isFinite(numericPrice) && numericPrice < 0) {
return GOODS_PRICE_NEGATIVE_MESSAGE
}
if (Number.isFinite(numericPrice) && numericPrice > GOODS_PRICE_MAX) {
return GOODS_PRICE_OVER_LIMIT_MESSAGE
}
}
return ''
}
......@@ -10,7 +10,7 @@ const LOW_PRICE_CONTEXT_FIELDS = [
export function buildLowPriceOrderPatch(source = {}) {
if (Number(source.lowPriceFlag) !== 1) return {}
const patch = { lowPriceFlag: 1 }
const patch = { lowPriceFlag: 1, djOrderType: 1 }
LOW_PRICE_CONTEXT_FIELDS.forEach(key => {
if (source[key] !== undefined && source[key] !== null && source[key] !== '') {
patch[key] = source[key]
......@@ -31,4 +31,3 @@ export function mergeLowPriceOrderContext(orderObj = {}, source = {}) {
...buildLowPriceOrderPatch(source)
}
}
/**
* @file 低价单提交成功后的列表目标状态。
*/
export function isLowPriceSubmit(orderObj = {}) {
return Number(orderObj?.lowPriceFlag) === 1
}
export function isLowPriceListPage(pageInstance) {
const route = pageInstance?.route || pageInstance?.__route__ || ''
return route === 'pages/tabWorkOrder/pages/index/index'
}
export function buildPendingLowPriceListPatch() {
return {
activeIndex: 1,
tabIndex: 1,
keyword: '',
searchObj: {}
}
}
......@@ -25,17 +25,12 @@ export function resolveApprovalCheckPrice(goods = {}) {
}
/**
* 审批比价用的最低售价:再次编辑时 minSellPrice 可能被回显逻辑压低,优先用目录最低价
* 审批比价用的最低售价,与低价单提交资格统一只读取 minSellPrice。
* @param {object} goods
* @returns {number}
*/
export function resolveApprovalMinSellPrice(goods = {}) {
return Number(
goods.upgradeShopMinPrice ??
goods.catalogMinSellPrice ??
goods.minSellPrice ??
0
)
return Number(goods.minSellPrice || 0)
}
/**
......
......@@ -45,27 +45,37 @@ export function resolveCreateAllGoodsFlag(raw, sceneType) {
* @param {number|string|undefined} djOrderType
* @returns {boolean}
*/
export function isAllowedLimitedOrderType(djOrderType) {
export function isAllowedLimitedOrderType(djOrderType, lowPriceFlag) {
if (Number(lowPriceFlag) === 1) {
return djOrderType == ORDER_TYPE_NORMAL
}
return LIMITED_ORDER_TYPE_VALUES.some(value => value == djOrderType)
}
/**
* 是否走低价总部审批流程(失焦提示 + 提交审批弹层)
* 已回退:不再启用审批弹框,统一走提交拦截
* @param {number|string|undefined} _djOrderType
* 是否走低价总部审批确认流程。
* @param {number|string|undefined} lowPriceFlag
* @returns {boolean}
*/
export function shouldUseMinPriceApprovalFlow(_djOrderType) {
return false
export function shouldUseMinPriceApprovalFlow(lowPriceFlag) {
return Number(lowPriceFlag) === 1
}
/**
* 订单类型 picker 列:限制场景仅正常订单 + 内部结算
* @param {Array<{text:string,value:number}>} orderTypeList
* @param {0|1} createAllGoodsFlag
* @param {number|string|undefined} [lowPriceFlag]
* @returns {Array<{text:string,value:number}>}
*/
export function buildOrderTypePickerList(orderTypeList = [], createAllGoodsFlag) {
export function buildOrderTypePickerList(
orderTypeList = [],
createAllGoodsFlag,
lowPriceFlag
) {
if (Number(lowPriceFlag) === 1) {
return orderTypeList.filter(item => item.value == ORDER_TYPE_NORMAL)
}
if (createAllGoodsFlag === 0) {
return orderTypeList.filter(item =>
LIMITED_ORDER_TYPE_VALUES.some(value => value == item.value)
......
......@@ -2,6 +2,13 @@ import api from '../../api'
import NP from 'number-precision'
import { buildSubmitGoodsSnapshot } from './services/submitGoodsSnapshot'
import { prepareSubmitPayload } from './services/submitPayload.helpers.js'
import { buildMinPriceApprovalList } from './services/minPriceApproval.js'
import { shouldUseMinPriceApprovalFlow } from './services/orderMerchantConfig.js'
import {
buildPendingLowPriceListPatch,
isLowPriceListPage,
isLowPriceSubmit
} from './services/lowPriceSubmitNavigation.helpers.js'
// ----------------------------------------------------------------------
// 辅助构造函数:校验结果
......@@ -242,11 +249,22 @@ SubmitContext.prototype.finishSubmit = async function (
save,
skipApprovalSheet
) {
const approvalItems = buildMinPriceApprovalList(this.page.data.goodsList)
console.log(
'[createOrder submit goods]',
buildSubmitGoodsSnapshot(this.page.data)
buildSubmitGoodsSnapshot(this.page.data, { approvalItems })
)
if (
!save &&
!skipApprovalSheet &&
shouldUseMinPriceApprovalFlow(this.page.data.orderObj?.lowPriceFlag) &&
approvalItems.length
) {
this.page.openMinPriceApprovalSheet(approvalItems, save)
return
}
const preparedData = this.prepareSubmitData(save)
const submitObj = preparedData.submitObj
const apiName = preparedData.apiName
......@@ -312,7 +330,20 @@ SubmitContext.prototype.doSubmit = async function (submitObj, apiName, save) {
// 状态更新 需刷新工单列表和预约管理列表
wx.$util.refreshPageData()
if (isErrorOrder) resData.isErrorOrder = true
wx.$router.redirectTo('confirmOrder', resData)
if (isLowPriceSubmit(data.orderObj)) {
const listPatch = buildPendingLowPriceListPatch()
const previousPage = wx.$router.getPageInstance?.(2)
if (isLowPriceListPage(previousPage) && previousPage?.setData) {
previousPage.setData(listPatch)
wx.$router.back()
} else {
wx.$router.go(
'/pages/tabWorkOrder/pages/index/index?activeIndex=1'
)
}
} else {
wx.$router.redirectTo('confirmOrder', resData)
}
}
} else {
wx.showModal({
......
import assert from 'node:assert/strict'
import { describe, it } from 'node:test'
import {
findGoodsPriceBoundaryError,
validateGoodsPriceInput
} from '../services/goodsPriceBoundary.helpers.js'
describe('goods price boundary validation', () => {
it('rejects negative prices without converting them to positive values', () => {
assert.deepEqual(validateGoodsPriceInput('-1'), {
valid: false,
value: null,
message: '商品价格不能小于0元'
})
})
it('rejects values over 100000 without clamping', () => {
assert.deepEqual(validateGoodsPriceInput('100000.01'), {
valid: false,
value: null,
message: '商品价格不能大于100000元'
})
})
it('accepts both boundaries and normalizes to two decimals', () => {
assert.deepEqual(validateGoodsPriceInput('0'), {
valid: true,
value: '0',
message: ''
})
assert.deepEqual(validateGoodsPriceInput('100000'), {
valid: true,
value: '100000',
message: ''
})
assert.deepEqual(validateGoodsPriceInput('12.345'), {
valid: true,
value: '12.34',
message: ''
})
})
it('finds invalid single, selected SKU and package child prices', () => {
assert.equal(
findGoodsPriceBoundaryError([
{ goodsFlag: 1, goods: { priceBoundaryError: '' } },
{
goodsFlag: 3,
packageGoods: {
goodsList: [
{ priceBoundaryError: '' },
{ priceBoundaryError: '商品价格不能大于100000元' }
]
}
}
]),
'商品价格不能大于100000元'
)
})
it('rejects invalid prices already present in route or echo data', () => {
assert.equal(
findGoodsPriceBoundaryError([
{ goodsFlag: 1, goods: { basePrice: -1, sellPrice: -1 } }
]),
'商品价格不能小于0元'
)
assert.equal(
findGoodsPriceBoundaryError([
{
goodsFlag: 2,
multipleSpecificationsGoods: { goods: { sellPrice: 100000.01 } }
}
]),
'商品价格不能大于100000元'
)
})
})
import assert from 'node:assert/strict'
import { register } from 'node:module'
import { beforeEach, describe, it } from 'node:test'
register(
'../../../../tests/work-order-migration/shims/create-order-context-loader.mjs',
import.meta.url
)
let pageConfig
globalThis.getApp = () => ({ globalData: {} })
globalThis.Page = config => {
pageConfig = config
}
globalThis.wx = {
getAccountInfoSync: () => ({
miniProgram: { appId: 'test-app-id', envVersion: 'develop' }
}),
getSystemInfoSync: () => ({ platform: 'devtools' }),
getStorageSync: () => '',
$util: {
decimal: value => Number(value),
getUserInfo: () => ({}),
removeLeadingZerosAndEnsureNonNegative: value => Number(value),
showToast() {}
}
}
await import(`../createOrder.js?price-boundary=${Date.now()}`)
function createPage() {
const goods = {
validMinSellPrice: 'Y',
minSellPrice: 100,
sellPrice: 80,
basePrice: 80
}
const page = {
...pageConfig,
data: {
...pageConfig.data,
orderObj: {
...pageConfig.data.orderObj,
lowPriceFlag: 1,
djOrderType: 1,
selectPayType: 1,
subOrderList: []
},
goodsList: [{ goodsFlag: 1, count: 1, goods }]
},
setData(patch) {
Object.assign(this.data, patch)
}
}
return { page, goods }
}
describe('createOrder goods price boundaries', () => {
let messages
beforeEach(() => {
messages = []
wx.$util.showToast = message => messages.push(message)
})
it('rejects a negative price, keeps the last valid price and blocks submit', () => {
const { page, goods } = createPage()
pageConfig.changePrice.call(page, {
detail: { index: 0, value: '-1' }
})
assert.deepEqual(messages, ['商品价格不能小于0元'])
assert.equal(goods.basePrice, 80)
assert.equal(
pageConfig.checkGoods.call(
page,
false,
[],
true,
page.data.goodsList,
page.data.orderObj
),
'商品价格不能小于0元'
)
})
it('rejects an over-limit price without clamping and clears the error after correction', () => {
const { page, goods } = createPage()
pageConfig.changePrice.call(page, {
detail: { index: 0, value: '100000.01' }
})
assert.deepEqual(messages, ['商品价格不能大于100000元'])
assert.equal(goods.basePrice, 80)
pageConfig.changePrice.call(page, {
detail: { index: 0, value: '70' }
})
assert.equal(goods.basePrice, '70')
assert.equal(goods.priceBoundaryError, '')
assert.equal(
pageConfig.checkGoods.call(
page,
false,
[],
true,
page.data.goodsList,
page.data.orderObj
),
undefined
)
})
it('keeps the legacy price editing path for non-low-price orders', () => {
const { page, goods } = createPage()
page.data.orderObj.lowPriceFlag = 0
pageConfig.changePrice.call(page, {
detail: { index: 0, value: '-1' }
})
assert.deepEqual(messages, [])
assert.equal(goods.priceBoundaryError, undefined)
})
})
import assert from 'node:assert/strict'
import { register } from 'node:module'
import { beforeEach, describe, it } from 'node:test'
register(
'../../../../tests/work-order-migration/shims/create-order-context-loader.mjs',
import.meta.url
)
const mockApi = await import(
'../../../../tests/work-order-migration/shims/mock-api.mjs'
)
const { SubmitContext } = await import(`../submitStrategy.js?flow=${Date.now()}`)
function createPage(options = {}) {
const approvalItems = []
const patches = []
const page = {
data: {
submitStatus: false,
isErrorOrder: false,
orderCreateType: '',
scene: '',
total: 80,
goodsList: [
{
goodsFlag: 1,
count: 1,
goods: {
validMinSellPrice: 'Y',
minSellPrice: 100,
sellPrice: 80,
goodsName: '测试商品'
}
}
],
orderObj: {
lowPriceFlag: options.lowPriceFlag ?? 1,
djOrderType: 1,
selectPayType: 1,
customer: {},
subOrderList: []
}
},
setData(patch) {
patches.push(patch)
Object.assign(this.data, patch)
},
checkPhoneUseConfig() {},
checkGoods() {},
checkRequired() {},
handleRequiredError() {},
openMinPriceApprovalSheet(items, save) {
approvalItems.push(...items)
this.data.minPriceApprovalSheet = { show: true, items }
this.data._pendingSubmitSave = !!save
}
}
return { page, approvalItems, patches }
}
describe('low-price approval submit flow', () => {
beforeEach(() => {
globalThis.__WORK_ORDER_MOCK_API__ = {}
globalThis.wx = {
disableAlertBeforeUnload() {},
hideLoading() {},
showModal() {},
$util: { refreshPageData() {} },
$router: {
back() {},
go() {},
redirectTo() {}
}
}
})
it('opens approval confirmation before calling the order API', async () => {
let apiCalls = 0
globalThis.__WORK_ORDER_MOCK_API__.createWithPay = () => {
apiCalls += 1
return { code: 0, data: {} }
}
const { page, approvalItems } = createPage()
await new SubmitContext(page).execute({ currentTarget: { dataset: {} } })
assert.equal(apiCalls, 0)
assert.equal(page.data.minPriceApprovalSheet.show, true)
assert.equal(approvalItems.length, 1)
assert.equal(approvalItems[0].name, '测试商品')
})
it('submits once after approval and returns the source list to pending', async () => {
let apiCalls = 0
let redirectTarget = ''
let backCalls = 0
let sourcePatch
globalThis.__WORK_ORDER_MOCK_API__.createWithPay = () => {
apiCalls += 1
return { code: 0, data: { orderCode: 'LP-1' } }
}
wx.$router.redirectTo = route => {
redirectTarget = route
}
wx.$router.back = () => {
backCalls += 1
}
wx.$router.getPageInstance = () => ({
__route__: 'pages/tabWorkOrder/pages/index/index',
setData(patch) {
sourcePatch = patch
}
})
const { page } = createPage()
await new SubmitContext(page).executeAfterApproval({ save: false })
assert.equal(apiCalls, 1)
assert.equal(redirectTarget, '')
assert.equal(backCalls, 1)
assert.deepEqual(sourcePatch, {
activeIndex: 1,
tabIndex: 1,
keyword: '',
searchObj: {}
})
})
it('keeps ordinary order success on confirmOrder', async () => {
let redirectTarget = ''
globalThis.__WORK_ORDER_MOCK_API__.createWithPay = () => ({
code: 0,
data: { orderCode: 'NORMAL-1' }
})
wx.$router.redirectTo = route => {
redirectTarget = route
}
const { page } = createPage({ lowPriceFlag: 0 })
await new SubmitContext(page).executeAfterApproval({ save: false })
assert.equal(redirectTarget, 'confirmOrder')
})
it('falls back to the pending-list route when the source list is unavailable', async () => {
let fallbackRoute = ''
let backCalls = 0
globalThis.__WORK_ORDER_MOCK_API__.createWithPay = () => ({
code: 0,
data: { orderCode: 'LP-FALLBACK' }
})
wx.$router.getPageInstance = () => ({
__route__: 'pages/tab/workspace/workspace',
setData() {}
})
wx.$router.back = () => {
backCalls += 1
}
wx.$router.go = route => {
fallbackRoute = route
}
const { page } = createPage()
await new SubmitContext(page).executeAfterApproval({ save: false })
assert.equal(
fallbackRoute,
'/pages/tabWorkOrder/pages/index/index?activeIndex=1'
)
assert.equal(backCalls, 0)
})
})
import assert from 'node:assert/strict'
import { describe, it } from 'node:test'
import {
buildPendingLowPriceListPatch,
isLowPriceListPage,
isLowPriceSubmit
} from '../services/lowPriceSubmitNavigation.helpers.js'
describe('low-price submit navigation', () => {
it('builds the pending-tab list state after a low-price submit', () => {
assert.deepEqual(buildPendingLowPriceListPatch(), {
activeIndex: 1,
tabIndex: 1,
keyword: '',
searchObj: {}
})
})
it('branches only for explicit low-price orders', () => {
assert.equal(isLowPriceSubmit({ lowPriceFlag: 1 }), true)
assert.equal(isLowPriceSubmit({ lowPriceFlag: '1' }), true)
assert.equal(isLowPriceSubmit({ lowPriceFlag: 0 }), false)
})
it('recognizes only the low-price order list as a safe back target', () => {
assert.equal(
isLowPriceListPage({ __route__: 'pages/tabWorkOrder/pages/index/index' }),
true
)
assert.equal(
isLowPriceListPage({ route: 'pages/tabWorkOrder/pages/index/index' }),
true
)
assert.equal(isLowPriceListPage({ __route__: 'pages/tab/workspace/workspace' }), false)
assert.equal(isLowPriceListPage(undefined), false)
})
})
......@@ -68,7 +68,7 @@ test('resolveApprovalActivityPrice uses catalog sellPrice not modified price', (
)
})
test('needsMinPriceApproval uses upgradeShopMinPrice after reset echo', () => {
test('needsMinPriceApproval uses minSellPrice instead of a stale upgrade price', () => {
assert.equal(
needsMinPriceApproval({
validMinSellPrice: 'Y',
......@@ -76,7 +76,7 @@ test('needsMinPriceApproval uses upgradeShopMinPrice after reset echo', () => {
minSellPrice: 100,
sellPrice: 100
}),
true
false
)
})
......
......@@ -25,27 +25,29 @@ test('resolveCreateAllGoodsFlag: 非精品升级按接口', () => {
assert.equal(resolveCreateAllGoodsFlag(1, 0), 1)
})
test('buildOrderTypePickerList limited to normal and internal settlement', () => {
test('buildOrderTypePickerList limits low-price orders to normal order', () => {
const all = [
{ text: '正常订单', value: 1 },
{ text: '打折策略', value: 2 },
{ text: '内部结算', value: 6 }
]
const limited = buildOrderTypePickerList(all, 0)
assert.equal(limited.length, 2)
assert.equal(limited[0].text, '正常订单')
assert.equal(limited[1].text, '内部结算')
const limited = buildOrderTypePickerList(all, 0, 1)
assert.deepEqual(limited, [{ text: '正常订单', value: 1 }])
assert.deepEqual(buildOrderTypePickerList(all, 1, 1), [all[0]])
assert.deepEqual(buildOrderTypePickerList(all, 0, 0), [all[0], all[2]])
assert.equal(buildOrderTypePickerList(all, 1).length, 3)
})
test('isAllowedLimitedOrderType', () => {
assert.equal(isAllowedLimitedOrderType(1), true)
assert.equal(isAllowedLimitedOrderType(6), true)
assert.equal(isAllowedLimitedOrderType(2), false)
test('isAllowedLimitedOrderType rejects internal settlement for low-price orders', () => {
assert.equal(isAllowedLimitedOrderType(1, 1), true)
assert.equal(isAllowedLimitedOrderType(6, 1), false)
assert.equal(isAllowedLimitedOrderType(1, 0), true)
assert.equal(isAllowedLimitedOrderType(6, 0), true)
assert.equal(isAllowedLimitedOrderType(2, 0), false)
})
test('shouldUseMinPriceApprovalFlow disabled after revert', () => {
assert.equal(shouldUseMinPriceApprovalFlow(1), false)
assert.equal(shouldUseMinPriceApprovalFlow(6), false)
assert.equal(shouldUseMinPriceApprovalFlow(2), false)
test('shouldUseMinPriceApprovalFlow enables confirmation only for low-price orders', () => {
assert.equal(shouldUseMinPriceApprovalFlow(1), true)
assert.equal(shouldUseMinPriceApprovalFlow('1'), true)
assert.equal(shouldUseMinPriceApprovalFlow(0), false)
})
import assert from 'node:assert/strict'
import { describe, it } from 'node:test'
import { register } from 'node:module'
import {
LOW_PRICE_FLAG,
buildLowPriceMerchantContext,
......@@ -16,6 +17,10 @@ import {
mergeLowPriceOrderContext
} from '../../tabWorkOrder/pages/createOrder/services/lowPriceOrderContext.helpers.js'
import { resolveDirectWorkOrderAction } from '../../pages/tab/workspace/services/workOrderEntry.helpers.js'
register(
'./shims/low-price-list-loader.mjs',
import.meta.url
)
describe('低价单下单门店上下文', () => {
it('将园区下的 4S 店数组展开并保留园区归属', () => {
......@@ -149,6 +154,37 @@ describe('低价单审批列表适配', () => {
[9, 2, 6, 1]
)
})
it('兜底路由在页面加载时应用待审批页签参数', async () => {
let pageConfig
globalThis.Page = config => {
pageConfig = config
}
globalThis.wx = {
$util: {
getUserInfo: () => ({ merchantAccountList: [] })
}
}
await import(
`../../pages/tabWorkOrder/pages/index/index.js?pending-tab=${Date.now()}`
)
const page = {
...pageConfig,
data: { ...pageConfig.data },
setData(patch, callback) {
Object.assign(this.data, patch)
if (callback) callback()
}
}
pageConfig.onLoad.call(page, { activeIndex: '1' })
assert.equal(page.data.activeIndex, 1)
assert.equal(page.data.tabIndex, 1)
assert.equal(page.data.keyword, '')
assert.equal(page.data.searchObj.merchantId, '')
assert.equal(page.data.searchObj.goodsOrderApplyStatusList, undefined)
})
})
describe('创建页低价单上下文', () => {
......@@ -165,6 +201,7 @@ describe('创建页低价单上下文', () => {
it('只从显式路由参数构建上下文', () => {
assert.deepEqual(buildLowPriceOrderPatch(routeContext), {
lowPriceFlag: 1,
djOrderType: 1,
merchantId: '201',
merchantName: '4S 店一',
yqMerchantId: '100',
......@@ -189,6 +226,7 @@ describe('创建页低价单上下文', () => {
assert.equal(result.merchantId, '201')
assert.equal(result.sellerMerchantId, '100')
assert.equal(result.lowPriceFlag, 1)
assert.equal(result.djOrderType, 1)
})
})
......
import { existsSync } from 'node:fs'
import path from 'node:path'
import { fileURLToPath, pathToFileURL } from 'node:url'
const shimDir = path.dirname(fileURLToPath(import.meta.url))
const projectRoot = path.resolve(shimDir, '../../..')
const mockApiUrl = pathToFileURL(path.join(shimDir, 'mock-api.mjs')).href
const mockGuardsUrl = pathToFileURL(
path.join(shimDir, 'mock-work-order-guards.mjs')
).href
function resolveExistingModule(candidate) {
return [candidate, `${candidate}.js`, path.join(candidate, 'index.js')].find(
item => existsSync(item)
)
}
export async function resolve(specifier, context, nextResolve) {
if (
specifier === '~/store/ModalToQueueControl' ||
specifier === '~/store/ModalToQueueControl.js'
) {
return { shortCircuit: true, url: mockGuardsUrl }
}
if (specifier === '~/api/api' || specifier === '~/api/api.js') {
return { shortCircuit: true, url: mockApiUrl }
}
if (
specifier === '../../api' &&
context.parentURL?.includes('/pages/tabWorkOrder/pages/index/')
) {
return { shortCircuit: true, url: mockApiUrl }
}
if (specifier.startsWith('~/')) {
const mapped = resolveExistingModule(
path.join(projectRoot, specifier.slice(2))
)
if (mapped) return { shortCircuit: true, url: pathToFileURL(mapped).href }
}
if (
(specifier.startsWith('./') || specifier.startsWith('../')) &&
!/\.(?:m?js|json|node)$/.test(specifier)
) {
const parentPath = fileURLToPath(context.parentURL)
const mapped = resolveExistingModule(
path.resolve(path.dirname(parentPath), specifier)
)
if (mapped) return { shortCircuit: true, url: pathToFileURL(mapped).href }
}
return nextResolve(specifier, context)
}
......@@ -30,5 +30,11 @@ export default {
code: 0,
data: []
})
},
createWithPay(data) {
return configuredResponse('createWithPay', data, {
code: 0,
data: {}
})
}
}
export async function checkDailyReport() {
return false
}
export async function checkStudyTask() {
return false
}
export async function checkOrderLockGate() {
return false
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!