前端修改

This commit is contained in:
2025-11-11 16:21:45 +08:00
parent 1bccfe57d8
commit cecf8daff5
3 changed files with 185 additions and 121 deletions

View File

@@ -276,6 +276,9 @@ export default {
// 原材料和产品列表
rawMaterialList: [],
productList: [],
// 原始完整列表备份(用于搜索过滤)
allRawMaterials: [],
allProducts: [],
itemSearchLoading: false,
// 只读模式
readonly: false,
@@ -317,11 +320,15 @@ export default {
// 清空物品选择
this.$set(item, 'itemId', null);
// 根据材料类型设置物品类型
// 根据材料类型设置物品类型并恢复完整列表
if (item.materialType === '成品') {
this.$set(item, 'itemType', 'product');
// 恢复完整产品列表
this.productList = [...this.allProducts];
} else if (item.materialType === '原料' || item.materialType === '废品') {
this.$set(item, 'itemType', 'raw_material');
// 恢复完整原料列表
this.rawMaterialList = [...this.allRawMaterials];
}
},
@@ -402,7 +409,7 @@ export default {
this.loadItemListForSplit(this.splitList[index].itemType);
},
// 搜索子卷物品
// 搜索子卷物品(前端过滤,支持名称和规格搜索)
async searchItemsForSplit(query, index) {
const item = this.splitList[index];
@@ -412,38 +419,49 @@ export default {
return;
}
// 如果没有输入,恢复完整列表
if (!query || query.trim() === '') {
this.loadItemListForSplit(itemType);
if (itemType === 'raw_material') {
this.rawMaterialList = [...this.allRawMaterials];
} else if (itemType === 'product') {
this.productList = [...this.allProducts];
}
return;
}
try {
this.itemSearchLoading = true;
if (itemType === 'raw_material') {
const response = await listRawMaterial({
rawMaterialName: query,
pageNum: 1,
pageSize: 50,
withBom: true
});
if (response.code === 200) {
this.rawMaterialList = response.rows || [];
}
} else if (itemType === 'product') {
const response = await listProduct({
productName: query,
pageNum: 1,
pageSize: 50,
withBom: true
});
if (response.code === 200) {
this.productList = response.rows || [];
}
}
} catch (error) {
console.error('搜索物品失败', error);
} finally {
this.itemSearchLoading = false;
// 前端过滤:在已加载的数据中搜索
const searchQuery = query.toLowerCase().trim();
if (itemType === 'raw_material') {
// 从备份列表中过滤原材料
this.rawMaterialList = this.allRawMaterials.filter(item => {
// 搜索名称
const nameMatch = item.rawMaterialName && item.rawMaterialName.toLowerCase().includes(searchQuery);
// 搜索规格
const specMatch = item.specification && item.specification.toLowerCase().includes(searchQuery);
// 搜索 BOM 参数
const bomMatch = item.bomItems && item.bomItems.some(bom =>
(bom.attrKey && bom.attrKey.toLowerCase().includes(searchQuery)) ||
(bom.attrValue && bom.attrValue.toLowerCase().includes(searchQuery))
);
return nameMatch || specMatch || bomMatch;
});
} else if (itemType === 'product') {
// 从备份列表中过滤产品
this.productList = this.allProducts.filter(item => {
// 搜索名称
const nameMatch = item.productName && item.productName.toLowerCase().includes(searchQuery);
// 搜索规格
const specMatch = item.specification && item.specification.toLowerCase().includes(searchQuery);
// 搜索 BOM 参数
const bomMatch = item.bomItems && item.bomItems.some(bom =>
(bom.attrKey && bom.attrKey.toLowerCase().includes(searchQuery)) ||
(bom.attrValue && bom.attrValue.toLowerCase().includes(searchQuery))
);
return nameMatch || specMatch || bomMatch;
});
}
},
@@ -458,10 +476,12 @@ export default {
if (rawMaterialRes.code === 200) {
this.rawMaterialList = rawMaterialRes.rows || [];
this.allRawMaterials = rawMaterialRes.rows || []; // 保存完整备份
}
if (productRes.code === 200) {
this.productList = productRes.rows || [];
this.allProducts = productRes.rows || []; // 保存完整备份
}
} catch (error) {
console.error('加载物品列表失败', error);