fix: 子表保存改为就地同步,避免整批换 id 打断外键。

协议样本、生产产出和盘点明细按行更新并保留原 id;补齐存储证明质检预填、离职人员显示名,以及样本采集通知模板字段。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-10-28 10:51:53 +08:00
1 parent d66e55af65
commit 5e563a6669
139 files changed
+59986 -49048

No files matched your search

@@ -1572,6 +1572,7 @@
await fetchSaveMaterialStockCheckUnusedLines(
unusedCheckId.value,
items.map((l) => ({
id: l.id || undefined,
usageId: l.usageId || undefined,
batchId: l.batchId || undefined,
materialName: l.materialName.trim(),
@@ -1158,6 +1158,7 @@
<script setup lang="ts">
import { formatDisplayOrDash } from '@/utils/datetime-display'
import { createStableRowId } from '@/utils/production-step-output'
import { computed } from 'vue'
import {
Plus,
@@ -2179,6 +2180,7 @@
if (!selectedStep.value) return
if (!selectedStep.value.reagents) selectedStep.value.reagents = []
selectedStep.value.reagents.push({
id: createStableRowId(),
reagentId: '',
reagentCode: '',
reagentName: '',
@@ -2215,6 +2217,7 @@
await fetchUpdateStepReagents({
stepId: selectedStep.value.id,
items: reagents.map((r: Record<string, any>, idx: number) => ({
id: r.id || '',
reagentCode: r.reagentCode,
reagentName: r.reagentName,
spec: r.spec,
@@ -2235,6 +2238,7 @@
if (!selectedStep.value) return
if (!selectedStep.value.consumables) selectedStep.value.consumables = []
selectedStep.value.consumables.push({
id: createStableRowId(),
consumableId: '',
consumableCode: '',
consumableName: '',
@@ -2271,6 +2275,7 @@
await fetchUpdateStepConsumables({
stepId: selectedStep.value.id,
items: consumables.map((c: Record<string, any>, idx: number) => ({
id: c.id || '',
consumableCode: c.consumableCode,
consumableName: c.consumableName,
specModel: c.specModel,
@@ -2291,6 +2296,7 @@
if (!selectedStep.value) return
if (!selectedStep.value.outputs) selectedStep.value.outputs = []
selectedStep.value.outputs.push({
id: createStableRowId(),
outputTypeId: '',
outputName: '',
outputBarcode: '',
@@ -2310,6 +2316,7 @@
await fetchUpdateStepOutputs({
stepId: selectedStep.value.id,
items: (selectedStep.value.outputs || []).map((o: Record<string, any>, idx: number) => ({
id: o.id || '',
outputTypeId: o.outputTypeId,
outputName: o.outputName,
outputBarcode: o.outputBarcode,
@@ -2333,6 +2340,7 @@
if (!selectedStep.value) return
if (!selectedStep.value.dataCollections) selectedStep.value.dataCollections = []
selectedStep.value.dataCollections.push({
id: createStableRowId(),
collectionName: '',
unit: '',
orderNum: 0,
@@ -2353,6 +2361,7 @@
stepId: selectedStep.value.id,
items: (selectedStep.value.dataCollections || []).map(
(d: Record<string, any>, idx: number) => ({
id: d.id || '',
collectionName: d.collectionName,
unit: d.unit,
orderNum: idx,
@@ -1033,6 +1033,7 @@
<script setup lang="ts">
import { formatDisplayOrDash } from '@/utils/datetime-display'
import { createStableRowId } from '@/utils/production-step-output'
import { Plus, Close, Check, Rank, RefreshLeft, Search, Delete, Edit, Upload } from '@element-plus/icons-vue'
import Sortable from 'sortablejs'
import type { SortableEvent } from 'sortablejs'
@@ -1373,6 +1374,7 @@
function appendReagentFromMaster(r: any) {
if (isReagentDuplicate(r.id, r.reagentCode)) return false
reagentList.value.push({
id: createStableRowId(),
reagentId: r.id,
reagentCode: r.reagentCode || '',
reagentName: r.reagentName || '',
@@ -1391,6 +1393,7 @@
) {
if (isConsumableDuplicate(c.id || c.consumableId, c.consumableCode)) return false
consumableList.value.push({
id: createStableRowId(),
consumableId: c.consumableId || c.id,
consumableCode: c.consumableCode || '',
consumableName: c.consumableName || '',
@@ -1482,7 +1485,7 @@
sopContent: formData.sopContent || undefined,
remark: formData.remark?.trim() || undefined,
reagents: reagentList.value.map((r) => ({
reagentId: r.reagentId || r.id,
id: r.id || '',
reagentCode: r.reagentCode,
reagentName: r.reagentName,
spec: r.spec,
@@ -1492,7 +1495,7 @@
remark: r.remark || ''
})),
consumables: consumableList.value.map((c) => ({
consumableId: c.consumableId || c.id,
id: c.id || '',
consumableCode: c.consumableCode,
consumableName: c.consumableName,
specModel: c.specModel,
@@ -1502,12 +1505,14 @@
remark: c.remark || ''
})),
outputs: outputList.value.map((o) => ({
id: o.id || '',
outputTypeId: o.outputTypeId,
outputName: o.outputName,
outputBarcode: o.outputBarcode,
remark: o.remark || ''
})),
dataCollections: dataCollectionList.value.map((d) => ({
id: d.id || '',
collectionName: d.collectionName,
unit: d.unit || undefined,
orderNum: d.orderNum ?? 0,
@@ -1721,6 +1726,7 @@
// =============== 产出物 ===============
function addOutputRow() {
outputList.value.push({
id: createStableRowId(),
outputTypeId: '',
outputName: '',
outputBarcode: '',
@@ -1731,6 +1737,7 @@
function addDataCollectionRow() {
dataCollectionList.value.push(
withDataCollectionClientKey({
id: createStableRowId(),
collectionName: '',
unit: '',
orderNum: dataCollectionList.value.length + 1,
@@ -131,6 +131,7 @@
import { ref, reactive } from 'vue'
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
import { Plus, Close, Check, Delete } from '@element-plus/icons-vue'
import { createStableRowId } from '@/utils/production-step-output'
import DialogFormBody from '@/components/business/dialog-form-body/index.vue'
import {
fetchCreateProductionMaterial,
@@ -229,6 +230,7 @@
function addFormulaLine() {
formulaLines.value.push({
id: createStableRowId(),
componentMaterialId: '',
componentMaterialType: 'reagent',
standardQty: 1,
@@ -330,6 +332,7 @@
await fetchReplaceProductionMaterialFormula(
id,
formulaLines.value.map((ln) => ({
id: ln.id || '',
componentMaterialId: ln.componentMaterialId,
componentMaterialType: ln.componentMaterialType,
standardQty: ln.standardQty,
@@ -1600,6 +1600,7 @@
await fetchSaveProductionMaterialStockCheckUnusedLines(
unusedCheckId.value,
items.map((l) => ({
id: l.id || undefined,
usageId: l.usageId || undefined,
batchId: l.batchId || undefined,
materialName: l.materialName.trim(),
@@ -25,6 +25,7 @@ export function createEmptySnapshots(): EditorSnapshots {
export function serializeInputs(rows: Record<string, any>[]): string {
return JSON.stringify(
rows.map((r) => ({
id: r.id || '',
inputType: r.inputType,
inputId: r.inputId,
inputCode: r.inputCode,
@@ -62,6 +63,7 @@ export function serializeEquipmentIds(ids: string[]): string {
function normalizeReagents(rows: Record<string, any>[] | undefined) {
return (rows || []).map((r) => ({
id: r.id || '',
reagentCode: r.reagentCode,
reagentName: r.reagentName,
spec: r.spec,
@@ -76,6 +78,7 @@ function normalizeReagents(rows: Record<string, any>[] | undefined) {
function normalizeConsumables(rows: Record<string, any>[] | undefined) {
return (rows || []).map((c) => ({
id: c.id || '',
consumableCode: c.consumableCode,
consumableName: c.consumableName,
specModel: c.specModel,
@@ -90,6 +93,7 @@ function normalizeConsumables(rows: Record<string, any>[] | undefined) {
function normalizeConfiguredReagents(rows: Record<string, any>[] | undefined) {
return (rows || []).map((r) => ({
id: r.id || '',
configuredReagentCode: r.configuredReagentCode,
configuredReagentName: r.configuredReagentName,
spec: r.spec,
@@ -103,6 +107,7 @@ function normalizeConfiguredReagents(rows: Record<string, any>[] | undefined) {
function normalizeStepOutputs(rows: Record<string, any>[] | undefined) {
return (rows || []).map((o) => ({
id: o.id || '',
outputTypeId: o.outputTypeId,
outputName: o.outputName,
outputBarcode: o.outputBarcode,
@@ -112,6 +117,7 @@ function normalizeStepOutputs(rows: Record<string, any>[] | undefined) {
function normalizeDataCollections(rows: Record<string, any>[] | undefined) {
return (rows || []).map((d) => ({
id: d.id || '',
collectionName: d.collectionName,
unit: d.unit,
collectionValue: d.collectionValue || '',
@@ -48,7 +48,11 @@ import type { FinanceAttachmentItem } from '@/components/business/protocol-finan
import { financeAttachmentsToUrlString } from '@/components/business/protocol-finance-confirm-fields/finance-attachments'
import { useUserStore } from '@/store/modules/user'
import { normalizePlannedStartDate, extractProductionTaskSteps } from '@/utils/production-labels'
import { createEmptyStepOutputRow } from '@/utils/production-step-output'
import {
createEmptyStepOutputRow,
createStableRowId,
toStepOutputReplaceItem
} from '@/utils/production-step-output'
import { resolveCellProductSpecDisplay } from '@/utils/cell-product-spec'
import { countOutputsMissingStorageSlot } from '@/utils/storage-slot-options'
import {
@@ -1322,6 +1326,7 @@ export function useTaskStepEditor() {
if (!selectedStep.value) return
if (!selectedStep.value.reagents) selectedStep.value.reagents = []
selectedStep.value.reagents.push({
id: createStableRowId(),
reagentId: '',
reagentCode: '',
reagentName: '',
@@ -1475,6 +1480,7 @@ export function useTaskStepEditor() {
if (!validateExecutionReagents()) return
try {
const items = (selectedStep.value.reagents || []).map((r: Record<string, any>) => ({
id: r.id || '',
material_code: r.reagentCode,
material_name: r.reagentName,
spec: r.spec,
@@ -1496,6 +1502,7 @@ export function useTaskStepEditor() {
if (!selectedStep.value) return
if (!selectedStep.value.consumables) selectedStep.value.consumables = []
selectedStep.value.consumables.push({
id: createStableRowId(),
consumableId: '',
consumableCode: '',
consumableName: '',
@@ -1516,6 +1523,7 @@ export function useTaskStepEditor() {
if (!validateExecutionConsumables()) return
try {
const items = (selectedStep.value.consumables || []).map((c: Record<string, any>) => ({
id: c.id || '',
material_code: c.consumableCode,
material_name: c.consumableName,
spec_model: c.specModel,
@@ -1651,6 +1659,7 @@ export function useTaskStepEditor() {
if (!selectedStep.value) return
if (!selectedStep.value.configuredReagents) selectedStep.value.configuredReagents = []
selectedStep.value.configuredReagents.push({
id: createStableRowId(),
configuredReagentId: '',
configuredReagentCode: '',
configuredReagentName: '',
@@ -1716,6 +1725,7 @@ export function useTaskStepEditor() {
if (!validateExecutionConfiguredReagents()) return
try {
const items = (selectedStep.value.configuredReagents || []).map((r: Record<string, any>) => ({
id: r.id || '',
material_code: r.configuredReagentCode,
material_name: r.configuredReagentName,
spec: r.spec,
@@ -1750,18 +1760,40 @@ export function useTaskStepEditor() {
}
function removeOutputRow(i: number) {
selectedStep.value?.outputs?.splice(i, 1)
void saveOutputs()
}
async function saveOutputs() {
let outputSaveQueue: Promise<void> = Promise.resolve()
function saveOutputs() {
if (!selectedStep.value || configSuppressSave.value) return
const step = selectedStep.value
const currentTaskId = taskId.value
const scope = operateScope.value
const run = outputSaveQueue.then(() => persistStepOutputs(step, currentTaskId, scope))
outputSaveQueue = run.then(
() => undefined,
() => undefined
)
return run
}
async function persistStepOutputs(
step: Record<string, any>,
currentTaskId: string,
scope: typeof operateScope.value
) {
try {
const items = (selectedStep.value.outputs || []).map((o: Record<string, any>) => ({
output_type_id: o.outputTypeId,
output_name: o.outputName,
output_barcode: o.outputBarcode,
remark: o.remark || ''
}))
await fetchReplaceStepOutputs(taskId.value, selectedStep.value.id, items, operateScope.value)
refreshStepSnapshot(selectedStep.value.id)
const outputs = step.outputs || []
const items = outputs.map((row: Record<string, any>) => toStepOutputReplaceItem(row))
const saved = await fetchReplaceStepOutputs(currentTaskId, step.id, items, scope)
if (Array.isArray(saved)) {
saved.forEach((item: Record<string, any>, index: number) => {
const id = String(item?.id || '').trim()
const row = outputs[index]
if (id && row && !String(row.id || '').trim()) row.id = id
})
}
refreshStepSnapshot(step.id)
} catch {
/* ignore */
}
@@ -1771,6 +1803,7 @@ export function useTaskStepEditor() {
if (!selectedStep.value) return
if (!selectedStep.value.dataCollections) selectedStep.value.dataCollections = []
selectedStep.value.dataCollections.push({
id: createStableRowId(),
collectionName: '',
unit: '',
orderNum: 0,
@@ -1784,6 +1817,7 @@ export function useTaskStepEditor() {
if (!selectedStep.value || configSuppressSave.value) return
try {
const items = (selectedStep.value.dataCollections || []).map((d: Record<string, any>) => ({
id: d.id || '',
collection_name: d.collectionName,
unit: d.unit,
collection_value: d.collectionValue || '',
@@ -2000,6 +2034,7 @@ export function useTaskStepEditor() {
operateScope.value
)
const items = (step.reagents || []).map((r: Record<string, any>) => ({
id: r.id || '',
material_code: r.reagentCode,
material_name: r.reagentName,
spec: r.spec,
@@ -2012,6 +2047,7 @@ export function useTaskStepEditor() {
}))
await fetchReplaceStepReagents(taskId.value, step.id, items, operateScope.value)
const consumableItems = (step.consumables || []).map((c: Record<string, any>) => ({
id: c.id || '',
material_code: c.consumableCode,
material_name: c.consumableName,
spec_model: c.specModel,
@@ -2029,6 +2065,7 @@ export function useTaskStepEditor() {
operateScope.value
)
const configuredItems = (step.configuredReagents || []).map((r: Record<string, any>) => ({
id: r.id || '',
material_code: r.configuredReagentCode,
material_name: r.configuredReagentName,
spec: r.spec,
@@ -2044,14 +2081,12 @@ export function useTaskStepEditor() {
configuredItems,
operateScope.value
)
const outputItems = (step.outputs || []).map((o: Record<string, any>) => ({
output_type_id: o.outputTypeId,
output_name: o.outputName,
output_barcode: o.outputBarcode,
remark: o.remark || ''
}))
const outputItems = (step.outputs || []).map((o: Record<string, any>) =>
toStepOutputReplaceItem(o)
)
await fetchReplaceStepOutputs(taskId.value, step.id, outputItems, operateScope.value)
const dataItems = (step.dataCollections || []).map((d: Record<string, any>) => ({
id: d.id || '',
collection_name: d.collectionName,
unit: d.unit,
collection_value: d.collectionValue || '',
@@ -1385,6 +1385,7 @@
await fetchSaveQcMaterialStockCheckUnusedLines(
unusedCheckId.value,
items.map((l) => ({
id: l.id || undefined,
usageId: l.usageId || undefined,
batchId: l.batchId || undefined,
materialName: l.materialName.trim(),
@@ -30,7 +30,48 @@
</el-tag>
</div>
<!-- 检测参数区已隐藏:加载仍拉取、保存原样回传,避免清空历史;详情弹窗仍只读展示 -->
<div class="section-title">检测参数</div>
<div v-if="!item.params.length" class="company-item-block__empty">该项目暂无配置参数</div>
<div v-else class="form-grid-3">
<el-form-item
v-for="(param, idx) in item.params"
:key="param.paramId || param.paramCode || idx"
:label="paramLabel(param)"
>
<el-input
v-if="param.paramType === 'text'"
v-model="param.paramValue"
placeholder="请输入"
:disabled="readonly"
/>
<DecimalInput
v-else-if="param.paramType === 'number'"
:model-value="toResultNumber(param.paramValue)"
:precision="2"
:disabled="readonly"
style="width: 100%"
placeholder="请输入"
@update:model-value="(v) => setResultNumber(param, v)"
/>
<el-select
v-else-if="param.paramType === 'select'"
v-model="param.paramValue"
placeholder="请选择"
clearable
filterable
:disabled="readonly"
style="width: 100%"
>
<el-option
v-for="opt in parseQcParamOptions(param.options)"
:key="opt"
:label="opt"
:value="opt"
/>
</el-select>
<el-input v-else v-model="param.paramValue" placeholder="请输入" :disabled="readonly" />
</el-form-item>
</div>
<div class="section-title">检测结论</div>
<div class="form-grid-2 result-conclusion-row">
<el-form-item label="任务状态" required>
@@ -113,6 +154,7 @@
type QcTaskResultItem
} from '@/api/qc-task-result'
import { taskStatusLabel, taskStatusTagType } from '@/utils/qc-labels'
import { parseQcParamOptions } from '@/utils/qc-item-param-options'
import {
pickSharedRemarkAndAttachments,
sortThirdPartyTasksByCompany,
@@ -225,6 +267,21 @@
return v !== '' && v !== undefined && v !== null
}
function paramLabel(param: QcTaskResultItem) {
const unit = (param.paramUnit || '').trim()
return unit ? `${param.paramName}(${unit})` : param.paramName
}
function toResultNumber(v: string | undefined) {
if (v === '' || v === undefined || v === null) return undefined
const n = Number(v)
return Number.isFinite(n) ? n : undefined
}
function setResultNumber(param: QcTaskResultItem, v: number | undefined) {
param.paramValue = v === undefined || v === null ? '' : String(v)
}
function onAttachmentPreview(file: Record<string, unknown>) {
qcPreviewAttachment(file)
}
@@ -318,6 +375,12 @@
ElMessage.warning(`请选择「${item.itemName}」的检测结论`)
return
}
for (const param of item.params) {
if (param.requiredFlag === '1' && !hasResultValue(param.paramValue)) {
ElMessage.warning(`请填写「${item.itemName}」的参数「${param.paramName}」`)
return
}
}
}
const thirdPartyAttachments = financeAttachmentsToUrlString(attachments.value)
@@ -415,6 +478,12 @@
color: var(--mint-text-muted, #64748b);
}
&__empty {
margin: 0 0 12px;
font-size: 13px;
color: var(--mint-text-muted, #64748b);
}
.section-title {
margin-top: 4px;
}