Files
SupplierSystem/miniprogram/utils/stockInboundArchive.js
T
Ubuntu 1d47267a8d
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
chore(sync): 提交剩余本地改动(规则文档 / 部署配置 / 小程序入库归档 / 工具与测试)
- .cursor/rules + AGENTS.md:供应商二次开发的隔离硬规则落库(库/端口/上传目录/对象前缀)
- 部署与本地配置:docker-compose*.yml、.env.*.example(仅占位值)、start-split-native / sync-prod-db-to-local 脚本
- 小程序:入库归档识别(stockInboundArchive + 识别与入库面板改动)
- tools:设计门禁脚本(check-migrations / run-all / verify-facts)与架构图脚本更新
- docs:跨系统改价改量审核、第三方订单退货跟随、免入库推进、500+ 分公司规模改造、
  拍照入库识别与档案回写等设计文档;对接清单新增 §4.5.4 我方回执(第六批端到端)
- server:存量修数脚本(legacy CS / 供应商应付 / 结算口径)、采购耳标核对脚本;
  新增测试:入库归档回写、租户优选顺序、规模并发
2026-10-09 22:28:15 +08:00

57 lines
2.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 拍照入库:商品档案字段(规格 / 品牌 / 厂家)的人工编辑追踪与回写载荷。
* 口径见 docs/design/20261012-拍照入库识别规格厂家品牌与档案回写.md
*
* 本模块只做纯计算(不碰 wx API),便于单测。
*
* 核心不变量:**只把人工实际改过的字段放进载荷**。
* AI 识别后未被人动过的字段一律不上报 —— 否则未经确认的识别值会直接覆盖商品档案
* (服务端 `normalizeArchive` 收不到该字段就不会写它)。
*/
/** 表单字段 → 服务端 archive 字段名。`origin` 是表单/库里叫法,`manufacturer` 是前端语义(厂家)。 */
const FIELD_MAP = [
['archiveSpec', 'spec'],
['archiveBrand', 'brand'],
['archiveOrigin', 'manufacturer'],
];
function text(value) {
return String(value == null ? '' : value).trim();
}
/**
* 从编辑追踪表算出要上报的 archive 载荷。
*
* @param {Object} values 当前表单值(archiveSpec / archiveBrand / archiveOrigin)
* @param {Object} edited 人工编辑追踪表(同键,值为 boolean)
* @returns {Object|null} 载荷对象;无人工编辑字段时返回 null(= 不回写档案)
*/
function buildArchivePayload(values, edited) {
const source = values || {};
const marks = edited || {};
const payload = {};
let any = false;
for (const [formKey, wireKey] of FIELD_MAP) {
if (!marks[formKey]) continue;
payload[wireKey] = text(source[formKey]);
any = true;
}
return any ? payload : null;
}
/**
* 是否有「已编辑但当前商品尚未建档」的情况 —— 此时档案回写不适用(档案还不存在),
* 需要给用户一个提示,否则用户会以为改动已存进档案。
*/
function hasUnsavedArchiveEdits(values, edited, skuCode) {
if (text(skuCode)) return false;
return buildArchivePayload(values, edited) !== null;
}
module.exports = {
buildArchivePayload,
hasUnsavedArchiveEdits,
ARCHIVE_FIELD_KEYS: FIELD_MAP.map(([, wire]) => wire),
};