订单入库: 补规格/生产日期/保质期/产地 + 拍照改识别 + 去 AI 判定
开发者:入库要填规格(商品有就带过去)/生产日期/保质期/生产地区,让仓库侧数据全;「拍照鉴别是否合格」去掉但代码别删;照片改为识别商品信息(复用库存入库那套);结果默认为合格、前端隐式。 - 卡片新增 card-r3:规格/生产日期/保质期/产地(选填);规格由商品库 skus.spec 预填(列表带出) - 拍照改走 recognizeStockInboundLines(/mobile/inventory/recognize-lines)预填四字段(只补空) - 去掉 AI 判定:不再调 analyzeInspectionQuality(代码/prompt 保留);去掉 ai-verdict 与结果 picker;移除 !aiDone 入库闸门 - 入库写 inventory.shelf_life + expiry_date(deriveExpiryDate);人工改过的规格/产地才回写 product_catalog.spec/skus.origin(applyArchiveWriteback,同事务) - 新增契约测试 inspectionInboundFields 注:『合格才入库/须拍照/退回』门槛未动;SQL 无迁移(inventory.shelf_life/expiry_date 既有列)。
This commit is contained in:
@@ -7,7 +7,9 @@ const {
|
||||
fetchStockInboundStorageZones,
|
||||
uploadQualityReportStorageFile,
|
||||
createInspectionBatchReports,
|
||||
recognizeStockInboundLines,
|
||||
} = require('../../utils/request');
|
||||
const { buildArchivePayload } = require('../../utils/stockInboundArchive');
|
||||
const { getSession } = require('../../utils/auth');
|
||||
const { ensureMobileRole } = require('../../utils/roleGuard');
|
||||
const { beginPanelShow, endPanelShow } = require('../../utils/panelShowGate');
|
||||
@@ -80,6 +82,15 @@ function defaultRatingFromGrade(grade) {
|
||||
return String(grade || '').trim().toUpperCase() === 'D' ? RESULT_FAIL : RESULT_PASS;
|
||||
}
|
||||
|
||||
/** 识别结果 → 保质期原文(优先识别给的 shelf_life 原文;否则拼「数值+单位」) */
|
||||
function composeShelfLifeText(item) {
|
||||
const text = String((item && item.shelf_life) || '').trim();
|
||||
if (text) return text;
|
||||
const value = String((item && item.shelf_life_value) || '').trim();
|
||||
const unit = String((item && item.shelf_life_unit) || '').trim();
|
||||
return value && unit ? `${value}${unit}` : '';
|
||||
}
|
||||
|
||||
function emptyAiFields() {
|
||||
return {
|
||||
aiDone: false,
|
||||
@@ -414,6 +425,17 @@ Component({
|
||||
prev && prev.production_date !== undefined ? prev.production_date : '',
|
||||
batch_report_id:
|
||||
prev && prev.batch_report_id !== undefined ? prev.batch_report_id : '',
|
||||
// 规格 / 保质期 / 产地(2026-10-16 补齐):规格「商品有就带过去」= 商品库 skus.spec 预填
|
||||
input_spec:
|
||||
prev && prev.input_spec !== undefined
|
||||
? prev.input_spec
|
||||
: String(row.spec || '').trim(),
|
||||
input_shelf_life:
|
||||
prev && prev.input_shelf_life !== undefined ? prev.input_shelf_life : '',
|
||||
input_origin:
|
||||
prev && prev.input_origin !== undefined ? prev.input_origin : '',
|
||||
specEdited: prev?.specEdited === true,
|
||||
originEdited: prev?.originEdited === true,
|
||||
zoneIndex: zoneIndexOf(
|
||||
prev && prev.storage_zone !== undefined
|
||||
? prev.storage_zone
|
||||
@@ -684,6 +706,43 @@ Component({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 拍照后「识别商品信息」(2026-10-16,取代「拍照鉴别是否合格」):
|
||||
* 复用库存入库那套识别,把 规格/生产日期/保质期/产地 **预填**到该行;**只补空、不覆盖已有值**。
|
||||
* 识别失败不阻断入库(可人工填)。
|
||||
*/
|
||||
async runRecognizeForRow(id) {
|
||||
const image = this._aiImageById && this._aiImageById[id];
|
||||
if (!image) return;
|
||||
const row = this.data.rows.find((item) => item.id === id) || {};
|
||||
try {
|
||||
const res = await recognizeStockInboundLines({ images_base64: [image] });
|
||||
const data = (res && (res.data || res)) || {};
|
||||
const items = Array.isArray(data.items) ? data.items : [];
|
||||
const first = items[0] || null;
|
||||
if (!first) return;
|
||||
const patch = {};
|
||||
const spec = String(first.spec || '').trim();
|
||||
const origin = String(first.origin || '').trim();
|
||||
const pd = String(first.production_date || '').trim().slice(0, 10);
|
||||
const shelf = composeShelfLifeText(first);
|
||||
if (spec && !String(row.input_spec || '').trim()) patch.input_spec = spec;
|
||||
if (origin && !String(row.input_origin || '').trim()) patch.input_origin = origin;
|
||||
if (/^\d{4}-\d{2}-\d{2}$/.test(pd) && !String(row.production_date || '').trim()) {
|
||||
patch.production_date = pd;
|
||||
}
|
||||
if (shelf && !String(row.input_shelf_life || '').trim()) patch.input_shelf_life = shelf;
|
||||
if (Object.keys(patch).length) {
|
||||
this.patchRow(id, patch);
|
||||
wx.showToast({ title: '已识别商品信息', icon: 'none' });
|
||||
} else {
|
||||
wx.showToast({ title: '未识别到新信息,可手动填写', icon: 'none' });
|
||||
}
|
||||
} catch (err) {
|
||||
wx.showToast({ title: err.message || '识别失败,可手动填写', icon: 'none' });
|
||||
}
|
||||
},
|
||||
|
||||
async completeWithOverQty(payload) {
|
||||
try {
|
||||
const body = await completeInspection(payload);
|
||||
@@ -705,10 +764,7 @@ Component({
|
||||
const id = e.currentTarget.dataset.id;
|
||||
const row = this.data.rows.find((item) => item.id === id);
|
||||
if (row?.input_rating === RESULT_FAIL) {
|
||||
await alertModal(
|
||||
'当前为不合格',
|
||||
'AI 判定为不合格。请先将结果改为合格,再点确认入库。'
|
||||
);
|
||||
await alertModal('当前为不合格', '请先将结果改为合格,再点确认入库。');
|
||||
return;
|
||||
}
|
||||
await this.submitInspection(e);
|
||||
@@ -794,6 +850,27 @@ Component({
|
||||
this.patchRow(id, { production_month: value });
|
||||
},
|
||||
|
||||
/** 规格(人工改过 ⇒ 标记回写档案) */
|
||||
onSpecInput(e) {
|
||||
this.patchRow(e.currentTarget.dataset.id, { input_spec: e.detail.value, specEdited: true });
|
||||
},
|
||||
|
||||
/** 生产日期(手填,优先于批次报告/预包装年月) */
|
||||
onProductionDateChange(e) {
|
||||
const raw = String(e.detail.value || '').slice(0, 10);
|
||||
this.patchRow(e.currentTarget.dataset.id, { production_date: raw });
|
||||
},
|
||||
|
||||
/** 保质期(原文,如 7天/6个月;落 inventory.shelf_life 并推算效期) */
|
||||
onShelfLifeInput(e) {
|
||||
this.patchRow(e.currentTarget.dataset.id, { input_shelf_life: e.detail.value });
|
||||
},
|
||||
|
||||
/** 生产产地(人工改过 ⇒ 标记回写档案 skus.origin) */
|
||||
onOriginInput(e) {
|
||||
this.patchRow(e.currentTarget.dataset.id, { input_origin: e.detail.value, originEdited: true });
|
||||
},
|
||||
|
||||
choosePhoto(e) {
|
||||
const id = e.currentTarget.dataset.id;
|
||||
wx.chooseImage({
|
||||
@@ -826,8 +903,8 @@ Component({
|
||||
const rows = await this.loadRows();
|
||||
const row = (rows || []).find((item) => item.id === id);
|
||||
if (row?.photoRequired && Number(row.photoCount || 0) > 0) {
|
||||
wx.showLoading({ title: 'AI分析中…', mask: true });
|
||||
await this.runAiForRow(id);
|
||||
wx.showLoading({ title: '识别中…', mask: true });
|
||||
await this.runRecognizeForRow(id);
|
||||
} else if (!(latestScan && latestScan.label_matched === false)) {
|
||||
wx.showToast({ title: '拍照验收已上传', icon: 'success' });
|
||||
}
|
||||
@@ -875,8 +952,8 @@ Component({
|
||||
const rows = await this.loadRows();
|
||||
const row = (rows || []).find((item) => item.id === id);
|
||||
if (row?.photoRequired && Number(row.photoCount || 0) > 0) {
|
||||
wx.showLoading({ title: 'AI分析中…', mask: true });
|
||||
await this.runAiForRow(id);
|
||||
wx.showLoading({ title: '识别中…', mask: true });
|
||||
await this.runRecognizeForRow(id);
|
||||
} else {
|
||||
wx.showToast({ title: '已删除', icon: 'success' });
|
||||
}
|
||||
@@ -1053,10 +1130,6 @@ Component({
|
||||
wx.showToast({ title: '请先拍照验收', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
if (!rejectFulfillment && photoRequired && !row.aiDone) {
|
||||
wx.showToast({ title: '请先完成 AI 质检', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!rejectFulfillment && row?.requires_prepackaged_check) {
|
||||
if (!row.production_month) {
|
||||
@@ -1100,8 +1173,15 @@ Component({
|
||||
loss_qty: 0,
|
||||
storage_zone: String(row?.storage_zone || '').trim() || undefined,
|
||||
production_date_month: row?.requires_prepackaged_check ? row.production_month : undefined,
|
||||
// 批次报告提取的生产日期与报告 id(人工在核对表确认过)——入库时带上
|
||||
// 批次报告提取 / 卡面手填的生产日期(手填优先)——入库时带上
|
||||
production_date: String(row?.production_date || '').trim() || undefined,
|
||||
// 保质期原文(如 7天/6个月)——服务端落 inventory.shelf_life 并推算 expiry_date
|
||||
shelf_life: String(row?.input_shelf_life || '').trim() || undefined,
|
||||
// 规格/产地:人工改过才回写商品档案(product_catalog.spec / skus.origin)
|
||||
archive: buildArchivePayload(
|
||||
{ archiveSpec: row?.input_spec, archiveOrigin: row?.input_origin },
|
||||
{ archiveSpec: row?.specEdited === true, archiveOrigin: row?.originEdited === true }
|
||||
) || undefined,
|
||||
batch_report_id: String(row?.batch_report_id || '').trim() || undefined,
|
||||
location: session?.profile?.branch_name || '',
|
||||
watermark_meta: {
|
||||
@@ -1134,7 +1214,7 @@ Component({
|
||||
|
||||
/**
|
||||
* 一键全部合格入库:仅非须拍照、非预包装行,按应收量合格入库。
|
||||
* 须拍照行需单独走 AI 质检,不进入批量。
|
||||
* 须拍照行需单独拍照后逐行确认入库(2026-10-16 起不再有 AI 质检),不进入批量。
|
||||
*/
|
||||
async submitAllEligible() {
|
||||
if (this.data.batchSubmitting) return;
|
||||
@@ -1150,7 +1230,7 @@ Component({
|
||||
}
|
||||
const confirmed = await confirmModal(
|
||||
'一键全部合格入库',
|
||||
`将按应收量合格入库当前列表 ${targets.length} 项(无损耗)。须拍照行请单独完成 AI 质检后处理。继续吗?`
|
||||
`将按应收量合格入库当前列表 ${targets.length} 项(无损耗)。须拍照行请单独拍照确认后处理。继续吗?`
|
||||
);
|
||||
if (!confirmed) return;
|
||||
|
||||
|
||||
@@ -44,14 +44,6 @@
|
||||
</view>
|
||||
</view>
|
||||
<view class="btn-photo" data-id="{{item.id}}" bindtap="choosePhoto">拍照</view>
|
||||
<view
|
||||
wx:if="{{item.photoRequired && (analyzingId === item.id || item.aiDone)}}"
|
||||
class="ai-verdict {{analyzingId === item.id ? 'pending' : (item.aiSource === 'vision_unavailable' ? 'warn' : (item.input_rating === '不合格' ? 'fail' : 'ok'))}}"
|
||||
>
|
||||
<text wx:if="{{analyzingId === item.id}}">分析中</text>
|
||||
<text wx:elif="{{item.aiSource === 'vision_unavailable'}}">人工</text>
|
||||
<text wx:else>{{item.input_rating === '不合格' ? '不合格' : '合格'}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="r2-field">
|
||||
<input
|
||||
@@ -63,16 +55,6 @@
|
||||
placeholder="实收"
|
||||
/>
|
||||
</view>
|
||||
<picker
|
||||
class="r2-field r2-picker"
|
||||
mode="selector"
|
||||
range="{{resultOptions}}"
|
||||
value="{{item.input_rating === '不合格' ? 1 : 0}}"
|
||||
data-id="{{item.id}}"
|
||||
bindchange="onRatingChange"
|
||||
>
|
||||
<view class="rate-pick">{{item.input_rating || '合格'}}</view>
|
||||
</picker>
|
||||
<picker
|
||||
wx:if="{{item.requires_prepackaged_check}}"
|
||||
class="r2-picker"
|
||||
@@ -95,6 +77,14 @@
|
||||
<view class="rate-pick {{item.storage_zone ? '' : 'is-empty'}}">{{item.storage_zone || '区域'}}</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="card-r3">
|
||||
<input class="r3-input" type="text" value="{{item.input_spec}}" data-id="{{item.id}}" bindinput="onSpecInput" placeholder="规格" />
|
||||
<picker class="r3-picker" mode="date" value="{{item.production_date}}" data-id="{{item.id}}" bindchange="onProductionDateChange">
|
||||
<view class="r3-pick {{item.production_date ? '' : 'is-empty'}}">{{item.production_date || '生产日期'}}</view>
|
||||
</picker>
|
||||
<input class="r3-input" type="text" value="{{item.input_shelf_life}}" data-id="{{item.id}}" bindinput="onShelfLifeInput" placeholder="保质期" />
|
||||
<input class="r3-input" type="text" value="{{item.input_origin}}" data-id="{{item.id}}" bindinput="onOriginInput" placeholder="产地" />
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -266,6 +266,46 @@
|
||||
flex-wrap: nowrap;
|
||||
}
|
||||
|
||||
/* 第三行:规格 / 生产日期 / 保质期 / 产地(2026-10-16 补齐;选填,放不下自动换行) */
|
||||
.card-r3 {
|
||||
margin-top: 10rpx;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10rpx;
|
||||
}
|
||||
|
||||
.r3-input,
|
||||
.r3-picker {
|
||||
flex: 1 1 44%;
|
||||
min-width: 0;
|
||||
box-sizing: border-box;
|
||||
height: 56rpx;
|
||||
border: 1rpx solid #e4e4e7;
|
||||
border-radius: 8rpx;
|
||||
background: #fafafa;
|
||||
}
|
||||
|
||||
.r3-input {
|
||||
padding: 0 14rpx;
|
||||
font-size: 24rpx;
|
||||
color: #18181b;
|
||||
}
|
||||
|
||||
.r3-picker {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.r3-pick {
|
||||
font-size: 24rpx;
|
||||
color: #18181b;
|
||||
}
|
||||
|
||||
.r3-pick.is-empty {
|
||||
color: #a1a1aa;
|
||||
}
|
||||
|
||||
.card-title-wrap {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
Reference in New Issue
Block a user