From 8a2da1ac1e39252515169ae7015c2e91948791fd Mon Sep 17 00:00:00 2001 From: DXC Date: Thu, 4 Jun 2026 16:01:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=8A=E6=88=90=E5=93=81/=E6=88=90=E5=93=81?= =?UTF-8?q?=E5=85=A5=E5=BA=93=EF=BC=9ABOM=20=E7=BC=96=E5=8F=B7=E4=B8=8B?= =?UTF-8?q?=E6=8B=89=E6=8C=89=E7=88=B6=E4=BB=B6=E8=A7=84=E6=A0=BC=E8=81=94?= =?UTF-8?q?=E5=8A=A8=E8=BF=87=E6=BB=A4=EF=BC=88=E5=89=8D=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=E5=8F=8C=E7=AB=AF=E6=94=B9=E9=80=A0=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 后端 /inbound/{semi,product}/search-bom 增加 parent_spec 可选参数,Service 层在 MaterialBase.spec_model 上加等值过滤 --- inventory-backend/app/api/v1/inbound/product.py | 3 ++- inventory-backend/app/api/v1/inbound/semi.py | 3 ++- .../app/services/inbound/product_service.py | 5 ++++- .../app/services/inbound/semi_service.py | 5 ++++- inventory-web/src/api/inbound/product.ts | 4 ++-- inventory-web/src/api/inbound/semi.ts | 4 ++-- inventory-web/src/views/stock/inbound/product.vue | 15 ++++++++++----- inventory-web/src/views/stock/inbound/semi.vue | 15 ++++++++++----- 8 files changed, 36 insertions(+), 18 deletions(-) diff --git a/inventory-backend/app/api/v1/inbound/product.py b/inventory-backend/app/api/v1/inbound/product.py index 86f59d4..4a99dea 100644 --- a/inventory-backend/app/api/v1/inbound/product.py +++ b/inventory-backend/app/api/v1/inbound/product.py @@ -60,7 +60,8 @@ def search_base(): def search_bom(): try: keyword = request.args.get('keyword', '') - data = ProductInboundService.search_bom_options(keyword) + parent_spec = request.args.get('parent_spec', None) + data = ProductInboundService.search_bom_options(keyword, parent_spec=parent_spec) return jsonify({"code": 200, "msg": "success", "data": data}) except Exception as e: traceback.print_exc() diff --git a/inventory-backend/app/api/v1/inbound/semi.py b/inventory-backend/app/api/v1/inbound/semi.py index 6d1b42b..f310d38 100644 --- a/inventory-backend/app/api/v1/inbound/semi.py +++ b/inventory-backend/app/api/v1/inbound/semi.py @@ -60,7 +60,8 @@ def search_base(): def search_bom(): try: keyword = request.args.get('keyword', '') - data = SemiInboundService.search_bom_options(keyword) + parent_spec = request.args.get('parent_spec', None) + data = SemiInboundService.search_bom_options(keyword, parent_spec=parent_spec) return jsonify({"code": 200, "msg": "success", "data": data}) except Exception as e: traceback.print_exc() diff --git a/inventory-backend/app/services/inbound/product_service.py b/inventory-backend/app/services/inbound/product_service.py index fe5dddf..ac47faf 100644 --- a/inventory-backend/app/services/inbound/product_service.py +++ b/inventory-backend/app/services/inbound/product_service.py @@ -66,7 +66,7 @@ class ProductInboundService: return {"items": [], "total": 0, "page": 1, "has_next": False} @staticmethod - def search_bom_options(keyword): + def search_bom_options(keyword, parent_spec=None): from app.models.bom import BomTable try: query = db.session.query( @@ -79,6 +79,9 @@ class ProductInboundService: if hasattr(BomTable, 'is_enabled'): query = query.filter(BomTable.is_enabled == True) + if parent_spec: + query = query.filter(MaterialBase.spec_model == parent_spec) + if keyword: kw = f'%{keyword}%' query = query.filter( diff --git a/inventory-backend/app/services/inbound/semi_service.py b/inventory-backend/app/services/inbound/semi_service.py index 03b6ec5..1a6dc6b 100644 --- a/inventory-backend/app/services/inbound/semi_service.py +++ b/inventory-backend/app/services/inbound/semi_service.py @@ -71,7 +71,7 @@ class SemiInboundService: return {"items": [], "total": 0, "page": 1, "has_next": False} @staticmethod - def search_bom_options(keyword): + def search_bom_options(keyword, parent_spec=None): from app.models.bom import BomTable try: query = db.session.query( @@ -84,6 +84,9 @@ class SemiInboundService: if hasattr(BomTable, 'is_enabled'): query = query.filter(BomTable.is_enabled == True) + if parent_spec: + query = query.filter(MaterialBase.spec_model == parent_spec) + if keyword: kw = f'%{keyword}%' query = query.filter( diff --git a/inventory-web/src/api/inbound/product.ts b/inventory-web/src/api/inbound/product.ts index c65f671..73b602a 100644 --- a/inventory-web/src/api/inbound/product.ts +++ b/inventory-web/src/api/inbound/product.ts @@ -43,11 +43,11 @@ export function searchMaterialBase(keyword: string, page: number = 1) { } // 搜索BOM -export function searchBom(keyword: string) { +export function searchBom(keyword: string, parent_spec?: string) { return request({ url: '/inbound/product/search-bom', method: 'get', - params: { keyword } + params: { keyword, parent_spec } }) } diff --git a/inventory-web/src/api/inbound/semi.ts b/inventory-web/src/api/inbound/semi.ts index b3964d3..061130f 100644 --- a/inventory-web/src/api/inbound/semi.ts +++ b/inventory-web/src/api/inbound/semi.ts @@ -45,11 +45,11 @@ export function searchMaterialBase(keyword: string, page: number = 1) { } // 5.5 搜索BOM (新增) -export function searchBom(keyword: string) { +export function searchBom(keyword: string, parent_spec?: string) { return request({ url: '/inbound/semi/search-bom', method: 'get', - params: { keyword } + params: { keyword, parent_spec } }) } diff --git a/inventory-web/src/views/stock/inbound/product.vue b/inventory-web/src/views/stock/inbound/product.vue index eee85d4..fa6e193 100644 --- a/inventory-web/src/views/stock/inbound/product.vue +++ b/inventory-web/src/views/stock/inbound/product.vue @@ -461,7 +461,8 @@ filterable remote clearable - placeholder="搜规格/编号" + :disabled="!form.spec_model" + :placeholder="!form.spec_model ? '请先在上方选择入库物料' : '搜规格/编号'" :remote-method="handleSearchBom" :loading="bomSearchLoading" @change="handleBomSelect" @@ -544,10 +545,10 @@ - + Preview Image - + - +
Label Preview @@ -957,7 +958,7 @@ const form = reactive({ const handleSearchBom = async (query: string) => { bomSearchLoading.value = true try { - const res: any = await searchBom(query) + const res: any = await searchBom(query, form.spec_model) bomOptions.value = res.data || [] } finally { bomSearchLoading.value = false } } @@ -1108,6 +1109,10 @@ const onMaterialSelected = async (val: number) => { form.material_type = item.type form.category = item.category form.unit = item.unit + // 切换物料时清空已选 BOM,防止脏数据 + form.bom_code = '' + form.bom_version = '' + bomOptions.value = [] // 获取该物料历史入库库位(新增独立接口) try { diff --git a/inventory-web/src/views/stock/inbound/semi.vue b/inventory-web/src/views/stock/inbound/semi.vue index 1d6948d..51a6942 100644 --- a/inventory-web/src/views/stock/inbound/semi.vue +++ b/inventory-web/src/views/stock/inbound/semi.vue @@ -526,7 +526,8 @@ filterable remote clearable - placeholder="搜规格/编号" + :disabled="!form.spec_model" + :placeholder="!form.spec_model ? '请先在上方选择入库物料' : '搜规格/编号'" :remote-method="handleSearchBom" :loading="bomSearchLoading" @change="handleBomSelect" @@ -603,15 +604,15 @@ - Preview Image - + Preview Image + - +
Label Preview @@ -1004,7 +1005,7 @@ watch( const handleSearchBom = async (query: string) => { bomSearchLoading.value = true try { - const res: any = await searchBom(query) + const res: any = await searchBom(query, form.spec_model) bomOptions.value = res.data || [] } finally { bomSearchLoading.value = false } } @@ -1102,6 +1103,10 @@ const onMaterialSelected = async (val: number) => { form.category = item.category form.unit = item.unit form.material_type = item.type + // 切换物料时清空已选 BOM,防止脏数据 + form.bom_code = '' + form.bom_version = '' + bomOptions.value = [] checkHistoryAndSetMode(item.id) // 获取该物料历史入库库位(新增独立接口)