feat: 增加子件查重与模糊搜索功能

This commit is contained in:
dxc
2026-03-06 10:26:19 +08:00
parent 3cc5e77729
commit 14bfe44e46

View File

@ -62,6 +62,7 @@
style="width: 100%"
:disabled="isEditMode"
class="beautified-select"
:filter-method="filterMaterial"
@change="onParentChange"
>
<el-option
@ -112,9 +113,21 @@
</el-col>
</el-row>
<div style="font-weight: bold; margin: 15px 0 10px 0; border-left: 4px solid #409EFF; padding-left: 10px;">子件列表</div>
<div style="font-weight: bold; margin: 15px 0 10px 0; border-left: 4px solid #409EFF; padding-left: 10px;">
子件列表
<span style="font-weight: normal; font-size: 12px; color: #909399; margin-left: 10px;">(已选 {{ filteredChildren.length }} )</span>
</div>
<el-table :data="form.children" border style="width: 100%; margin-bottom: 15px" max-height="300">
<!-- 任务2子件列表本地模糊搜索 -->
<el-input
v-model="childSearchKeyword"
placeholder="请输入子件名称或规格型号搜索"
clearable
style="width: 300px; margin-bottom: 10px;"
:prefix-icon="Search"
/>
<el-table :data="filteredChildren" border style="width: 100%; margin-bottom: 15px" max-height="300">
<el-table-column label="子件物料" min-width="280" v-if="hasFormFieldPermission('child_id')">
<template #default="{ row, $index }">
<el-select
@ -122,6 +135,7 @@
placeholder="请搜索原料"
filterable
style="width: 100%"
:filter-method="filterMaterial"
@change="(val) => onChildChange(val, $index)"
>
<el-option
@ -213,6 +227,34 @@ let originalVersion = '' // 保存原始版本号用于计算升级选项
const bomList = ref<BomItem[]>([])
const materialOptions = ref<MaterialBase[]>([])
const searchKeyword = ref('')
const childSearchKeyword = ref('') // 任务2子件列表搜索关键字
// 任务2子件列表本地模糊搜索 - 计算属性
const filteredChildren = computed(() => {
if (!childSearchKeyword.value) {
return form.children
}
const kw = childSearchKeyword.value.toLowerCase()
return form.children.filter(child => {
// 获取子件物料的名称和规格
const material = materialOptions.value.find(m => m.id === child.child_id)
if (!material) return false
const name = (material.name || '').toLowerCase()
const spec = (material.spec || '').toLowerCase()
return name.includes(kw) || spec.includes(kw)
})
})
// 任务3自定义过滤方法 - 同时匹配名称和规格
const filterMaterial = (val: string) => {
if (!val) return true
const kw = val.toLowerCase()
return (item: MaterialBase) => {
const name = (item.name || '').toLowerCase()
const spec = (item.spec || '').toLowerCase()
return name.includes(kw) || spec.includes(kw)
}
}
// 列与权限Code的映射关系数据库中的code
const permissionMap: Record<string, string> = {
@ -327,9 +369,19 @@ const onParentChange = (val: number) => {
}
}
// 任务2子件物料选中后自动设置用量为1
// 任务2子件物料选中后自动设置用量为1,并检测重复
const onChildChange = (val: number | null, index: number) => {
if (val !== null) {
// 任务1检测重复 - 检查该物料是否已在其他行存在
const existingIndex = form.children.findIndex((child, idx) => idx !== index && child.child_id === val)
if (existingIndex !== -1) {
const material = materialOptions.value.find(m => m.id === val)
ElMessage.warning(`该物料已在第 ${existingIndex + 1} 行存在,请合并用量或删除重复项`)
// 清空当前选择
form.children[index].child_id = null
form.children[index].dosage = 0
return
}
form.children[index].dosage = 1
}
}
@ -419,6 +471,7 @@ const resetForm = () => {
form.children = []
isSaveAsMode.value = false // 任务1重置另存为模式
originalVersion = ''
childSearchKeyword.value = '' // 任务2重置搜索关键字
if (formRef.value) formRef.value.resetFields()
}
@ -432,6 +485,13 @@ const submitForm = async () => {
if (!fullBomNo.value) return ElMessage.warning('BOM编号不能为空')
if (form.children.length === 0) return ElMessage.warning('请至少添加一个子件')
// 任务1提交前校验重复子件
const childIds = form.children.map(c => c.child_id).filter(id => id !== null)
const uniqueIds = new Set(childIds)
if (childIds.length !== uniqueIds.size) {
return ElMessage.warning('子件列表中存在重复物料,请合并用量或删除重复项')
}
const payload = {
bom_no: fullBomNo.value,
version: form.version,