独立加工:修小程序成品申报与批次继承
- 小程序「开始加工」不再被「待完成到货验收」拦住(独立加工没有验收行) - 成品搜索框补 data 声明并加 || '' 兜底,改为打开即载入候选 + 本地优先过滤 - 成品批次继承原料的生产日期/保质期原文/有效期/产地,入库后仍可在库存管理修改 - 两个继承开关默认勾选,选中态改绿色实心勾(小程序自绘,Web 用 accent) - 新增两篇设计文档并同步索引
This commit is contained in:
@@ -209,6 +209,12 @@ Component({
|
||||
outputLossManual: false,
|
||||
outputAutoLoss: 0,
|
||||
outputAutoUnitCost: 0,
|
||||
/** 成品搜索:必须在 data 里声明,否则 setData 写不进数据层,
|
||||
* 输入框会把 undefined 渲染成字面量并把每次输入刷回 undefined(表现为打字没反应) */
|
||||
outputSkuSearch: '',
|
||||
outputSkuOptions: [],
|
||||
/** 打开弹窗时一次性载入的在售商品(与 Web 同交互:输入本地即时过滤) */
|
||||
allOutputSkus: [],
|
||||
activeTab: 'work',
|
||||
viewMode: 'today',
|
||||
dateField: 'created_at',
|
||||
@@ -421,16 +427,21 @@ Component({
|
||||
const result = await fetchProcessingTasks(this.buildRequestParams());
|
||||
const rows = (result.data || []).map((row) => {
|
||||
const unitPrice = displayUnitPrice(row);
|
||||
const isStandalone = row.source_type === 'standalone';
|
||||
return {
|
||||
...row,
|
||||
statusText: STATUS_TEXT[row.process_status] || '未知',
|
||||
delivery_date_text: formatDeliveryDate(row.delivery_date),
|
||||
inspection_completed: row.inspection_completed === true,
|
||||
is_demand: row.source_type === 'demand',
|
||||
is_standalone: isStandalone,
|
||||
// 独立加工没有验收行(inspection_id 为 NULL,后端 start 允许直接开工),
|
||||
// 不能再用 inspection_completed 拦「开始加工」——Web 端一直是这样判的。
|
||||
can_start_work:
|
||||
row.source_type === 'demand'
|
||||
? Number(row.process_status) < 40
|
||||
: row.inspection_completed === true && Number(row.process_status) <= 20,
|
||||
: (isStandalone || row.inspection_completed === true) &&
|
||||
Number(row.process_status) <= 20,
|
||||
input_grade: row.input_grade || RESULT_PASS,
|
||||
result_label: formatResultLabel(row.quality_rating),
|
||||
inspection_photo_count: Number(row.inspection_photo_count || 0),
|
||||
@@ -759,8 +770,9 @@ Component({
|
||||
qty: '',
|
||||
unit_cost: '',
|
||||
unit_cost_manual: false,
|
||||
inherit_batch_report: false,
|
||||
inherit_inspection_report: false,
|
||||
// 默认继承原料的报告(开发者 2026-10-23:这两个开关默认勾选)
|
||||
inherit_batch_report: true,
|
||||
inherit_inspection_report: true,
|
||||
}));
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -774,8 +786,8 @@ Component({
|
||||
qty: '',
|
||||
unit_cost: '',
|
||||
unit_cost_manual: false,
|
||||
inherit_batch_report: false,
|
||||
inherit_inspection_report: false,
|
||||
inherit_batch_report: true,
|
||||
inherit_inspection_report: true,
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -791,8 +803,22 @@ Component({
|
||||
outputLossManual: false,
|
||||
outputSkuSearch: '',
|
||||
outputSkuOptions: [],
|
||||
allOutputSkus: [],
|
||||
});
|
||||
this.recalcOutput();
|
||||
// 与 Web 一致:打开弹窗就给出候选,不必先打字
|
||||
this.loadOutputSkuOptions();
|
||||
},
|
||||
|
||||
/** 一次性载入在售商品(本地过滤用;limit 走接口上限) */
|
||||
async loadOutputSkuOptions() {
|
||||
try {
|
||||
const res = await fetchStockInboundSkuOptions({ limit: 50 });
|
||||
const rows = res && Array.isArray(res.data) ? res.data : [];
|
||||
this.setData({ allOutputSkus: rows, outputSkuOptions: rows });
|
||||
} catch (err) {
|
||||
this.setData({ allOutputSkus: [], outputSkuOptions: [] });
|
||||
}
|
||||
},
|
||||
|
||||
recalcOutput() {
|
||||
@@ -860,16 +886,33 @@ Component({
|
||||
},
|
||||
|
||||
async searchOutputSkus(e) {
|
||||
const search = e.detail.value || '';
|
||||
const search = String((e && e.detail && e.detail.value) || '');
|
||||
const keyword = search.trim().toLowerCase();
|
||||
this.setData({ outputSkuSearch: search });
|
||||
if (!search.trim()) {
|
||||
this.setData({ outputSkuOptions: [] });
|
||||
const all = this.data.allOutputSkus || [];
|
||||
if (!keyword) {
|
||||
this.setData({ outputSkuOptions: all });
|
||||
return;
|
||||
}
|
||||
// 与 Web 同交互:先在已载入的商品里本地过滤(输入即时响应,不等网络)
|
||||
const local = all.filter(
|
||||
(o) =>
|
||||
String(o.sku_name || '').toLowerCase().includes(keyword) ||
|
||||
String(o.sku_code || '').toLowerCase().includes(keyword)
|
||||
);
|
||||
if (local.length) {
|
||||
this.setData({ outputSkuOptions: local });
|
||||
return;
|
||||
}
|
||||
// 已载入的那批里没有 ⇒ 回服务端搜全量(防商品多时漏掉)
|
||||
const seq = (this._outputSkuSearchSeq || 0) + 1;
|
||||
this._outputSkuSearchSeq = seq;
|
||||
try {
|
||||
const res = await fetchStockInboundSkuOptions({ search: search.trim(), limit: 20 });
|
||||
this.setData({ outputSkuOptions: res.data || [] });
|
||||
const res = await fetchStockInboundSkuOptions({ search: search.trim(), limit: 50 });
|
||||
if (seq !== this._outputSkuSearchSeq) return;
|
||||
this.setData({ outputSkuOptions: res && Array.isArray(res.data) ? res.data : [] });
|
||||
} catch (err) {
|
||||
if (seq !== this._outputSkuSearchSeq) return;
|
||||
this.setData({ outputSkuOptions: [] });
|
||||
}
|
||||
},
|
||||
@@ -879,12 +922,12 @@ Component({
|
||||
const opt = (this.data.outputSkuOptions || []).find((o) => o.sku_code === skuCode);
|
||||
if (!opt) return;
|
||||
if (this.data.outputRows.some((r) => r.sku_code === skuCode)) {
|
||||
this.setData({ outputSkuOptions: [], outputSkuSearch: '' });
|
||||
this.setData({ outputSkuOptions: this.data.allOutputSkus || [], outputSkuSearch: '' });
|
||||
return;
|
||||
}
|
||||
this.setData(
|
||||
{
|
||||
outputSkuOptions: [],
|
||||
outputSkuOptions: this.data.allOutputSkus || [],
|
||||
outputSkuSearch: '',
|
||||
outputRows: [
|
||||
...this.data.outputRows,
|
||||
@@ -894,8 +937,8 @@ Component({
|
||||
qty: '',
|
||||
unit_cost: '',
|
||||
unit_cost_manual: false,
|
||||
inherit_batch_report: false,
|
||||
inherit_inspection_report: false,
|
||||
inherit_batch_report: true,
|
||||
inherit_inspection_report: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -911,6 +954,8 @@ Component({
|
||||
outputRows: [],
|
||||
outputLoss: '',
|
||||
outputLossManual: false,
|
||||
outputSkuSearch: '',
|
||||
outputSkuOptions: [],
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
|
||||
<view wx:if="{{activeTab === 'work'}}" class="task-actions">
|
||||
<view class="task-hint" wx:if="{{item.is_demand}}">从库存领料加工成品</view>
|
||||
<view class="task-hint is-warn" wx:elif="{{!item.inspection_completed}}">待完成到货验收后可开始加工</view>
|
||||
<view class="task-hint is-warn" wx:elif="{{!item.is_standalone && !item.inspection_completed}}">待完成到货验收后可开始加工</view>
|
||||
<button wx:if="{{item.is_demand && item.can_start_work}}" class="btn-primary" size="mini" data-id="{{item.id}}" bindtap="openDemandPick">领料加工</button>
|
||||
<button wx:elif="{{item.can_start_work}}" class="btn-primary" size="mini" data-id="{{item.id}}" bindtap="openWorkForm">
|
||||
{{item.process_status === 10 ? '开始加工' : '提交完工'}}
|
||||
@@ -204,7 +204,7 @@
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label">成品明细(可多行)</text>
|
||||
<input class="field-input" placeholder="搜索成品商品,点下方加入" value="{{outputSkuSearch}}" bindinput="searchOutputSkus" />
|
||||
<input class="field-input" placeholder="搜索成品商品,点下方加入" value="{{outputSkuSearch || ''}}" bindinput="searchOutputSkus" />
|
||||
<view wx:if="{{outputSkuOptions.length}}" class="sku-options">
|
||||
<view wx:for="{{outputSkuOptions}}" wx:key="sku_code" class="sku-option" catchtap="addOutputSku" data-sku="{{item.sku_code}}">
|
||||
<text class="sku-name">{{item.sku_name}}</text>
|
||||
@@ -227,13 +227,15 @@
|
||||
<input class="field-input" type="digit" placeholder="自动" value="{{item.unit_cost}}" data-sku="{{item.sku_code}}" bindinput="onOutputCostInput" />
|
||||
</view>
|
||||
</view>
|
||||
<view class="loss-row">
|
||||
<text data-sku="{{item.sku_code}}" data-field="inherit_batch_report" catchtap="toggleOutputInherit">
|
||||
{{item.inherit_batch_report ? '☑' : '☐'}} 继承原料批次报告
|
||||
</text>
|
||||
<text data-sku="{{item.sku_code}}" data-field="inherit_inspection_report" catchtap="toggleOutputInherit">
|
||||
{{item.inherit_inspection_report ? '☑' : '☐'}} 继承原料检验报告
|
||||
</text>
|
||||
<view class="inherit-row">
|
||||
<view class="inherit-toggle {{item.inherit_batch_report ? 'is-on' : ''}}" data-sku="{{item.sku_code}}" data-field="inherit_batch_report" catchtap="toggleOutputInherit">
|
||||
<view class="inherit-check">{{item.inherit_batch_report ? '✓' : ''}}</view>
|
||||
<text class="inherit-label">继承原料批次报告</text>
|
||||
</view>
|
||||
<view class="inherit-toggle {{item.inherit_inspection_report ? 'is-on' : ''}}" data-sku="{{item.sku_code}}" data-field="inherit_inspection_report" catchtap="toggleOutputInherit">
|
||||
<view class="inherit-check">{{item.inherit_inspection_report ? '✓' : ''}}</view>
|
||||
<text class="inherit-label">继承原料检验报告</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="loss-box">
|
||||
|
||||
@@ -540,6 +540,53 @@
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
/* 成品行:报告继承开关(默认勾选;选中态用绿色实心勾,一眼看得出已勾) */
|
||||
.inherit-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12rpx 32rpx;
|
||||
margin-top: 8rpx;
|
||||
}
|
||||
|
||||
.inherit-toggle {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 10rpx;
|
||||
}
|
||||
|
||||
.inherit-check {
|
||||
width: 34rpx;
|
||||
height: 34rpx;
|
||||
flex: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 8rpx;
|
||||
border: 2rpx solid #cbd5e1;
|
||||
background: #ffffff;
|
||||
color: transparent;
|
||||
font-size: 24rpx;
|
||||
font-weight: 700;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.inherit-toggle.is-on .inherit-check {
|
||||
border-color: #10b981;
|
||||
background: #10b981;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.inherit-label {
|
||||
font-size: 24rpx;
|
||||
color: #64748b;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.inherit-toggle.is-on .inherit-label {
|
||||
color: #047857;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.sheet-actions {
|
||||
display: flex;
|
||||
gap: 16rpx;
|
||||
|
||||
@@ -12,6 +12,7 @@ const assert = require('assert');
|
||||
|
||||
const js = fs.readFileSync(path.join(__dirname, 'index.js'), 'utf8');
|
||||
const wxml = fs.readFileSync(path.join(__dirname, 'index.wxml'), 'utf8');
|
||||
const wxss = fs.readFileSync(path.join(__dirname, 'index.wxss'), 'utf8');
|
||||
const api = fs.readFileSync(path.join(__dirname, '../../utils/request.js'), 'utf8');
|
||||
|
||||
let failed = 0;
|
||||
@@ -48,6 +49,58 @@ it('成品:成本默认均分 + 损耗自动差额 + 两个继承开关', () =
|
||||
assert.ok(wxml.includes('inherit_inspection_report'));
|
||||
});
|
||||
|
||||
/**
|
||||
* 2026-10-23 开发者:「这两个按钮是默认勾选上的,选中状态显眼点,绿色的勾选箭头」。
|
||||
* 三个新建成品的入口(原料带出 / 单据头回退 / 搜索添加)都默认勾选,
|
||||
* 选中态用绿色实心块 + 白色 ✓(不再用 ☑/☐ 字符 —— 小程序里跟正文同色,看不出是否勾选)。
|
||||
*/
|
||||
it('两个继承开关默认勾选,且选中态是绿色勾', () => {
|
||||
assert.ok((js.match(/inherit_batch_report: true/g) || []).length >= 3, '三处新建成品行都要默认勾选');
|
||||
assert.ok((js.match(/inherit_inspection_report: true/g) || []).length >= 3);
|
||||
assert.ok(!js.includes('inherit_batch_report: false'));
|
||||
assert.ok(!js.includes('inherit_inspection_report: false'));
|
||||
// 模板:类名带 is-on 控制选中态,勾号只在选中时渲染
|
||||
assert.ok(wxml.includes("inherit-toggle {{item.inherit_batch_report ? 'is-on' : ''}}"));
|
||||
assert.ok(wxml.includes("item.inherit_batch_report ? '✓'"));
|
||||
assert.ok(!wxml.includes("'☑'"));
|
||||
// 样式:选中态绿色实心 + 白勾 + 标签变绿加粗
|
||||
assert.ok(wxss.includes('.inherit-toggle.is-on .inherit-check'));
|
||||
assert.ok(wxss.includes('background: #10b981'));
|
||||
assert.ok(wxss.includes('.inherit-toggle.is-on .inherit-label'));
|
||||
});
|
||||
|
||||
/**
|
||||
* 2026-10-23 开发者报障:「成品明细」搜索框显示字面量 undefined、搜索商品没反应。
|
||||
* 根因:WXML 绑定的 `outputSkuSearch` / `outputSkuOptions` 没在 `data` 里声明,
|
||||
* setData 写不进数据层 ⇒ input 把 undefined 渲染成字面量,每次重渲染又把输入值刷回 undefined。
|
||||
*/
|
||||
it('成品搜索:input 绑定的键必须在 data 中声明', () => {
|
||||
const dataStart = js.indexOf(' data: {');
|
||||
const dataEnd = js.indexOf('\n observers:');
|
||||
assert.ok(dataStart > 0 && dataEnd > dataStart, ' 解析不到 data 块');
|
||||
const dataBlock = js.slice(dataStart, dataEnd);
|
||||
assert.ok(/\boutputSkuSearch:\s*''/.test(dataBlock), 'data 缺少 outputSkuSearch');
|
||||
assert.ok(/\boutputSkuOptions:\s*\[\]/.test(dataBlock), 'data 缺少 outputSkuOptions');
|
||||
// 绑定上加 `|| ''` 兜底:即使数据层异常也绝不把 undefined 渲染成字面量
|
||||
assert.ok(wxml.includes("value=\"{{outputSkuSearch || ''}}\""));
|
||||
assert.ok(wxml.includes('bindinput="searchOutputSkus"'));
|
||||
});
|
||||
|
||||
it('成品搜索与 Web 同交互:打开即载入候选 + 本地即时过滤 + 本地没有再回服务端', () => {
|
||||
const dataStart = js.indexOf(' data: {');
|
||||
const dataBlock = js.slice(dataStart, js.indexOf('\n observers:'));
|
||||
assert.ok(/\ballOutputSkus:\s*\[\]/.test(dataBlock), 'data 缺少 allOutputSkus');
|
||||
// 打开弹窗就载入(不必先打字)
|
||||
assert.ok(js.includes('this.loadOutputSkuOptions();'));
|
||||
assert.ok(js.includes('const rows = res && Array.isArray(res.data) ? res.data : [];'));
|
||||
// 输入时本地过滤
|
||||
assert.ok(js.includes('const local = all.filter('));
|
||||
assert.ok(js.includes('.includes(keyword)'));
|
||||
// 本地没命中才请求服务端,且丢弃过期响应
|
||||
assert.ok(js.includes('const seq = (this._outputSkuSearchSeq || 0) + 1;'));
|
||||
assert.ok(js.includes('if (seq !== this._outputSkuSearchSeq) return;'));
|
||||
});
|
||||
|
||||
it('订单/需求单加工:毛重净重流程保持原样(不许被改)', () => {
|
||||
assert.ok(js.includes('await completeProcessingWork({'));
|
||||
assert.ok(js.includes('gross_weight: grossWeight,'));
|
||||
|
||||
Reference in New Issue
Block a user