From 7a40bd827a87152998a36694da6155b690008d66 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期三, 16 九月 2026 16:23:24 +0800
Subject: [PATCH] feat: 质检绑定支持规格型号
---
src/views/qualityManagement/processInspection/components/formDia.vue | 12 +++
src/views/qualityManagement/finalInspection/components/formDia.vue | 6 +
src/views/qualityManagement/rawMaterialInspection/components/formDia.vue | 12 +++
src/views/qualityManagement/metricBinding/index.vue | 97 +++++++++++++++++++++++++-------
4 files changed, 101 insertions(+), 26 deletions(-)
diff --git a/src/views/qualityManagement/finalInspection/components/formDia.vue b/src/views/qualityManagement/finalInspection/components/formDia.vue
index e5cd36e..312b05c 100644
--- a/src/views/qualityManagement/finalInspection/components/formDia.vue
+++ b/src/views/qualityManagement/finalInspection/components/formDia.vue
@@ -344,6 +344,7 @@
// 骞惰鍔犺浇瑙勬牸鍨嬪彿鍜屾寚鏍囬�夐」
const params = {
productId: currentProductId.value,
+ productModelId: form.value.productModelId || undefined,
inspectType: 2
};
@@ -412,6 +413,8 @@
const handleChangeModel = (value) => {
form.value.model = modelOptions.value.find(item => item.id == value)?.model || '';
form.value.unit = modelOptions.value.find(item => item.id == value)?.unit || '';
+ // 瑙勬牸鍨嬪彿鍙樺寲鍚庢寜 浜у搧+瑙勬牸鍨嬪彿 閲嶆柊杩囨护鍙�夋寚鏍�
+ getList(value);
}
const handleQualifiedQuantityChange = (value) => {
@@ -489,7 +492,7 @@
}
});
}
-const getList = () => {
+const getList = (modelId) => {
if (!currentProductId.value) {
testStandardOptions.value = [];
tableData.value = [];
@@ -497,6 +500,7 @@
}
let params = {
productId: currentProductId.value,
+ productModelId: modelId ?? form.value.productModelId ?? undefined,
inspectType: 2
};
qualityInspectDetailByProductId(params).then(res => {
diff --git a/src/views/qualityManagement/metricBinding/index.vue b/src/views/qualityManagement/metricBinding/index.vue
index ba989ea..f15180b 100644
--- a/src/views/qualityManagement/metricBinding/index.vue
+++ b/src/views/qualityManagement/metricBinding/index.vue
@@ -106,6 +106,11 @@
<el-table-column type="selection" width="48" align="center" />
<el-table-column type="index" label="搴忓彿" width="60" align="center" />
<el-table-column prop="productName" label="浜у搧鍚嶇О" min-width="140" />
+ <el-table-column prop="model" label="瑙勬牸鍨嬪彿" min-width="120">
+ <template #default="{ row }">
+ {{ row.model || '鈥�' }}
+ </template>
+ </el-table-column>
<el-table-column label="鎿嶄綔" width="120" fixed="right" align="center">
<template #default="{ row }">
<el-button link type="danger" size="small" @click="handleUnbind(row)">鍒犻櫎</el-button>
@@ -126,11 +131,14 @@
<div class="binding-dialog">
<el-input
v-model="productSearchKeyword"
- placeholder="鎼滅储浜у搧"
+ placeholder="鎼滅储浜у搧鎴栬鏍煎瀷鍙�"
clearable
prefix-icon="Search"
class="binding-search"
/>
+ <div class="binding-tip">
+ 鍕鹃�変骇鍝侊紙澶х被鎴栧叿浣撲骇鍝侊級琛ㄧず璇ョ被涓嬫墍鏈夎鏍奸�氱敤锛涘嬀閫夎鏍煎瀷鍙疯〃绀哄彧瀵硅鍨嬪彿鐢熸晥锛屼袱绉嶅彲浠ュ悓鏃堕�夋嫨銆�
+ </div>
<el-tree
ref="productTreeRef"
:key="productTreeKey"
@@ -138,7 +146,7 @@
:data="productTreeData"
show-checkbox
check-strictly
- node-key="id"
+ node-key="treeKey"
:props="{ label: 'label', children: 'children', disabled: 'disabled' }"
:filter-node-method="filterProductNode"
class="product-binding-tree"
@@ -173,7 +181,7 @@
import { ref, reactive, toRefs, computed, watch, nextTick, onMounted, getCurrentInstance } from 'vue'
import { ElMessageBox } from 'element-plus'
import PIMTable from '@/components/PIMTable/PIMTable.vue'
-import { productTreeList } from '@/api/basicData/product.js'
+import { productTreeList, modelList } from '@/api/basicData/product.js'
import {
qualityTestStandardListPage
} from '@/api/qualityManagement/metricMaintenance.js'
@@ -287,21 +295,14 @@
const productSearchKeyword = ref('')
const selectedProductIds = ref([])
-const markParentNodesDisabled = (nodes) => {
- return (nodes || []).map((node) => {
- const children = node.children?.length ? markParentNodesDisabled(node.children) : []
- return {
- ...node,
- children,
- disabled: children.length > 0
- }
- })
-}
+// 鏍戣妭鐐瑰敮涓� key锛氫骇鍝佽妭鐐圭敤 id锛岃鏍煎瀷鍙疯妭鐐圭敤 model-{id}锛岄伩鍏嶄笌浜у搧 id 鍐茬獊
+const nodeKey = (node) => (node.isModel ? `model-${node.id}` : node.id)
const buildProductLabelMap = (nodes, map = {}) => {
;(nodes || []).forEach((node) => {
- if (node.id != null) {
- map[node.id] = node.label
+ const key = nodeKey(node)
+ if (key != null) {
+ map[key] = node.label
}
if (node.children?.length) {
buildProductLabelMap(node.children, map)
@@ -328,12 +329,42 @@
productTreeRef.value?.filter(val)
})
+// 涓轰骇鍝佽妭鐐规寕杞借鏍煎瀷鍙峰瓙鑺傜偣锛涙棤瑙勬牸鍨嬪彿鐨勪骇鍝佷繚鎸佸彲閫�
+const attachProductModels = async (nodes) => {
+ if (!Array.isArray(nodes)) return []
+ const list = await Promise.all(
+ nodes.map(async (node) => {
+ const children = await attachProductModels(node.children)
+ let modelChildren = []
+ try {
+ const res = await modelList({ id: node.id })
+ modelChildren = (res || []).map((model) => ({
+ id: model.id,
+ label: model.model || model.productCode || `鍨嬪彿${model.id}`,
+ isModel: true,
+ productId: node.id,
+ treeKey: `model-${model.id}`
+ }))
+ } catch (error) {
+ console.error('鑾峰彇浜у搧瑙勬牸鍨嬪彿澶辫触:', error)
+ }
+ return {
+ ...node,
+ treeKey: nodeKey(node),
+ children: [...children, ...modelChildren]
+ }
+ })
+ )
+ return list
+}
+
const getProductTreeData = async () => {
if (productTreeData.value?.length) return
productTreeLoading.value = true
try {
const res = await productTreeList()
- productTreeData.value = markParentNodesDisabled(Array.isArray(res) ? res : [])
+ const tree = Array.isArray(res) ? res : []
+ productTreeData.value = await attachProductModels(tree)
} catch (error) {
console.error('鑾峰彇浜у搧鏍戝け璐�:', error)
} finally {
@@ -416,6 +447,23 @@
bindingSelectedRows.value = selection
}
+// 鍕鹃�夎妭鐐� -> 缁戝畾椤癸細浜у搧鑺傜偣缁戝畾鏁翠釜浜у搧锛岃鏍煎瀷鍙疯妭鐐圭粦瀹氬埌鍏蜂綋鍨嬪彿
+const checkedNodesToBindings = () => {
+ const nodes = productTreeRef.value?.getCheckedNodes(true) || []
+ const seen = new Set()
+ return nodes
+ .map((node) => (node.isModel
+ ? { productId: node.productId, productModelId: node.id }
+ : { productId: node.id, productModelId: null }))
+ .filter((item) => item.productId != null)
+ .filter((item) => {
+ const key = `${item.productId}_${item.productModelId ?? ''}`
+ if (seen.has(key)) return false
+ seen.add(key)
+ return true
+ })
+}
+
const openBindingDialog = () => {
if (!currentStandard.value?.id) return
selectedProductIds.value = []
@@ -438,13 +486,14 @@
const submitBinding = async () => {
const testStandardId = currentStandard.value?.id
if (!testStandardId) return
- const ids = (selectedProductIds.value || []).filter(Boolean)
- if (!ids.length) {
- proxy.$message.warning('璇烽�夋嫨浜у搧')
+ const items = checkedNodesToBindings()
+ if (!items.length) {
+ proxy.$message.warning('璇烽�夋嫨浜у搧鎴栬鏍煎瀷鍙�')
return
}
- const payload = ids.map((pid) => ({
- productId: pid,
+ const payload = items.map((item) => ({
+ productId: item.productId,
+ productModelId: item.productModelId ?? null,
testStandardId
}))
await qualityTestStandardBindingAdd(payload)
@@ -618,6 +667,12 @@
width: 100%;
}
+.binding-tip {
+ font-size: 12px;
+ color: #909399;
+ line-height: 18px;
+}
+
.product-binding-tree {
max-height: 360px;
overflow-y: auto;
diff --git a/src/views/qualityManagement/processInspection/components/formDia.vue b/src/views/qualityManagement/processInspection/components/formDia.vue
index a02976e..7cc4f10 100644
--- a/src/views/qualityManagement/processInspection/components/formDia.vue
+++ b/src/views/qualityManagement/processInspection/components/formDia.vue
@@ -411,7 +411,11 @@
modelOptions.value = res || [];
// 鍚屾鍥炲~ model / unit锛堟湁浜涙帴鍙h繑鍥炵殑 row 閲屽彲鑳芥病甯﹀叏锛�
if (form.value.productModelId) {
- handleChangeModel(form.value.productModelId);
+ const selectedModel = modelOptions.value.find(item => item.id == form.value.productModelId);
+ if (selectedModel) {
+ form.value.model = selectedModel.model || "";
+ form.value.unit = selectedModel.unit || "";
+ }
}
} catch (e) {
console.error("鍔犺浇瑙勬牸鍨嬪彿澶辫触", e);
@@ -423,6 +427,7 @@
// 鍏堝姞杞芥寚鏍囬�夐」
let params = {
productId: currentProductId.value,
+ productModelId: form.value.productModelId || undefined,
inspectType: 1,
process: form.value.process || "",
};
@@ -497,6 +502,8 @@
modelOptions.value.find(item => item.id == value)?.model || "";
form.value.unit =
modelOptions.value.find(item => item.id == value)?.unit || "";
+ // 瑙勬牸鍨嬪彿鍙樺寲鍚庢寜 浜у搧+瑙勬牸鍨嬪彿 閲嶆柊杩囨护鍙�夋寚鏍�
+ getList(value);
};
const handleQualifiedQuantityChange = (value) => {
@@ -591,7 +598,7 @@
}
});
};
- const getList = () => {
+ const getList = (modelId) => {
if (!currentProductId.value) {
testStandardOptions.value = [];
tableData.value = [];
@@ -600,6 +607,7 @@
const processName = form.value.process || "";
let params = {
productId: currentProductId.value,
+ productModelId: modelId ?? form.value.productModelId ?? undefined,
inspectType: 1,
process: processName,
};
diff --git a/src/views/qualityManagement/rawMaterialInspection/components/formDia.vue b/src/views/qualityManagement/rawMaterialInspection/components/formDia.vue
index d3f9fc0..a66c609 100644
--- a/src/views/qualityManagement/rawMaterialInspection/components/formDia.vue
+++ b/src/views/qualityManagement/rawMaterialInspection/components/formDia.vue
@@ -349,7 +349,11 @@
modelOptions.value = res || [];
// 鍚屾鍥炲~ model / unit锛堟湁浜涙帴鍙h繑鍥炵殑 row 閲屽彲鑳芥病甯﹀叏锛�
if (form.value.productModelId) {
- handleChangeModel(form.value.productModelId);
+ const selectedModel = modelOptions.value.find(item => item.id == form.value.productModelId);
+ if (selectedModel) {
+ form.value.model = selectedModel.model || '';
+ form.value.unit = selectedModel.unit || '';
+ }
}
} catch (e) {
console.error("鍔犺浇瑙勬牸鍨嬪彿澶辫触", e);
@@ -361,6 +365,7 @@
// 鍏堝姞杞芥寚鏍囬�夐」
let params = {
productId: currentProductId.value,
+ productModelId: form.value.productModelId || undefined,
inspectType: 0
}
qualityInspectDetailByProductId(params).then(res => {
@@ -425,6 +430,8 @@
const handleChangeModel = (value) => {
form.value.model = modelOptions.value.find(item => item.id == value)?.model || '';
form.value.unit = modelOptions.value.find(item => item.id == value)?.unit || '';
+ // 瑙勬牸鍨嬪彿鍙樺寲鍚庢寜 浜у搧+瑙勬牸鍨嬪彿 閲嶆柊杩囨护鍙�夋寚鏍�
+ getList(value);
}
const findNodeById = (nodes, productId) => {
@@ -483,7 +490,7 @@
})
}
-const getList = () => {
+const getList = (modelId) => {
if (!currentProductId.value) {
testStandardOptions.value = [];
tableData.value = [];
@@ -491,6 +498,7 @@
}
let params = {
productId: currentProductId.value,
+ productModelId: modelId ?? form.value.productModelId ?? undefined,
inspectType: 0
}
qualityInspectDetailByProductId(params).then(res => {
--
Gitblit v1.9.3