前端修改

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

@@ -290,6 +290,9 @@ export default {
// 原材料和产品列表 // 原材料和产品列表
rawMaterialList: [], rawMaterialList: [],
productList: [], productList: [],
// 原始完整列表备份(用于搜索过滤)
allRawMaterials: [],
allProducts: [],
itemSearchLoading: false, itemSearchLoading: false,
// 只读模式 // 只读模式
readonly: false, readonly: false,
@@ -403,11 +406,15 @@ export default {
// 清空物品选择 // 清空物品选择
this.$set(this.targetCoil, 'itemId', null); this.$set(this.targetCoil, 'itemId', null);
// 根据材料类型设置物品类型 // 根据材料类型设置物品类型并恢复完整列表
if (value === '成品') { if (value === '成品') {
this.$set(this.targetCoil, 'itemType', 'product'); this.$set(this.targetCoil, 'itemType', 'product');
// 恢复完整产品列表
this.productList = [...this.allProducts];
} else if (value === '原料' || value === '废品') { } else if (value === '原料' || value === '废品') {
this.$set(this.targetCoil, 'itemType', 'raw_material'); this.$set(this.targetCoil, 'itemType', 'raw_material');
// 恢复完整原料列表
this.rawMaterialList = [...this.allRawMaterials];
} }
}, },
@@ -607,10 +614,12 @@ export default {
if (rawMaterialRes.code === 200) { if (rawMaterialRes.code === 200) {
this.rawMaterialList = rawMaterialRes.rows || []; this.rawMaterialList = rawMaterialRes.rows || [];
this.allRawMaterials = rawMaterialRes.rows || []; // 保存完整备份
} }
if (productRes.code === 200) { if (productRes.code === 200) {
this.productList = productRes.rows || []; this.productList = productRes.rows || [];
this.allProducts = productRes.rows || []; // 保存完整备份
} }
} catch (error) { } catch (error) {
console.error('加载物品列表失败', error); console.error('加载物品列表失败', error);
@@ -651,45 +660,56 @@ export default {
} }
}, },
// 搜索物品 // 搜索物品(前端过滤,支持名称和规格搜索)
async searchItems(query) { async searchItems(query) {
if (!this.targetCoil.itemType) { if (!this.targetCoil.itemType) {
this.$message.warning('请先选择材料类型'); this.$message.warning('请先选择材料类型');
return; return;
} }
// 如果没有输入,恢复完整列表
if (!query || query.trim() === '') { if (!query || query.trim() === '') {
this.loadItemList(this.targetCoil.itemType); if (this.targetCoil.itemType === 'raw_material') {
this.rawMaterialList = [...this.allRawMaterials];
} else if (this.targetCoil.itemType === 'product') {
this.productList = [...this.allProducts];
}
return; return;
} }
try { // 前端过滤:在已加载的数据中搜索
this.itemSearchLoading = true; const searchQuery = query.toLowerCase().trim();
if (this.targetCoil.itemType === 'raw_material') {
const response = await listRawMaterial({ if (this.targetCoil.itemType === 'raw_material') {
rawMaterialName: query, // 从备份列表中过滤原材料
pageNum: 1, this.rawMaterialList = this.allRawMaterials.filter(item => {
pageSize: 50, // 搜索名称
withBom: true const nameMatch = item.rawMaterialName && item.rawMaterialName.toLowerCase().includes(searchQuery);
}); // 搜索规格
if (response.code === 200) { const specMatch = item.specification && item.specification.toLowerCase().includes(searchQuery);
this.rawMaterialList = response.rows || []; // 搜索 BOM 参数
} const bomMatch = item.bomItems && item.bomItems.some(bom =>
} else if (this.targetCoil.itemType === 'product') { (bom.attrKey && bom.attrKey.toLowerCase().includes(searchQuery)) ||
const response = await listProduct({ (bom.attrValue && bom.attrValue.toLowerCase().includes(searchQuery))
productName: query, );
pageNum: 1,
pageSize: 50, return nameMatch || specMatch || bomMatch;
withBom: true });
}); } else if (this.targetCoil.itemType === 'product') {
if (response.code === 200) { // 从备份列表中过滤产品
this.productList = response.rows || []; this.productList = this.allProducts.filter(item => {
} // 搜索名称
} const nameMatch = item.productName && item.productName.toLowerCase().includes(searchQuery);
} catch (error) { // 搜索规格
console.error('搜索物品失败', error); const specMatch = item.specification && item.specification.toLowerCase().includes(searchQuery);
} finally { // 搜索 BOM 参数
this.itemSearchLoading = false; 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;
});
} }
}, },

View File

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

View File

@@ -287,6 +287,9 @@ export default {
// 原材料和产品列表 // 原材料和产品列表
rawMaterialList: [], rawMaterialList: [],
productList: [], productList: [],
// 原始完整列表备份(用于搜索过滤)
allRawMaterials: [],
allProducts: [],
itemSearchLoading: false, itemSearchLoading: false,
// 只读模式 // 只读模式
readonly: false readonly: false
@@ -358,6 +361,23 @@ export default {
} }
}, },
methods: { methods: {
// 处理材料类型变化
handleMaterialTypeChange(value) {
// 清空物品选择
this.$set(this.updateForm, 'itemId', null);
// 根据材料类型设置物品类型
if (value === '成品') {
this.$set(this.updateForm, 'itemType', 'product');
// 恢复完整产品列表
this.productList = [...this.allProducts];
} else if (value === '原料' || value === '废品') {
this.$set(this.updateForm, 'itemType', 'raw_material');
// 恢复完整原料列表
this.rawMaterialList = [...this.allRawMaterials];
}
},
// 加载钢卷信息 // 加载钢卷信息
async loadCoilInfo(coilId) { async loadCoilInfo(coilId) {
try { try {
@@ -429,43 +449,35 @@ export default {
}, },
// 格式化物品名称添加规格和BOM信息 // 格式化物品名称添加规格和BOM信息
formatItemName(name, bomItems) { formatItemName(item) {
if (!item) return '';
// 获取名称(原材料或产品)
const name = item.rawMaterialName || item.productName || '';
if (!name) return ''; if (!name) return '';
let displayName = name; let displayName = name;
const specs = [];
// 如果有BOM参数添加到名称后面 // 1. 优先显示规格从对象的specification字段
if (bomItems && bomItems.length > 0) { if (item.specification) {
const specs = []; specs.push(item.specification);
}
// 查找规格参数 // 2. 添加BOM参数最多2个
const specItem = bomItems.find(item => if (item.bomItems && item.bomItems.length > 0) {
item.attrKey === '规格' || const bomParams = item.bomItems
item.attrKey === 'spec' || .filter(bomItem => bomItem.attrKey && bomItem.attrValue)
item.attrKey === '型号' .slice(0, 2); // 最多2个BOM参数
);
if (specItem && specItem.attrValue) {
specs.push(specItem.attrValue);
}
// 添加其他关键参数最多3个 bomParams.forEach(param => {
const otherParams = bomItems specs.push(`${param.attrKey}:${param.attrValue}`);
.filter(item =>
item.attrKey !== '规格' &&
item.attrKey !== 'spec' &&
item.attrKey !== '型号'
)
.slice(0, 2); // 最多2个其他参数
otherParams.forEach(param => {
if (param.attrValue) {
specs.push(`${param.attrKey}:${param.attrValue}`);
}
}); });
}
if (specs.length > 0) { // 3. 拼接成最终格式
displayName += `${specs.join(' ')}`; if (specs.length > 0) {
} displayName += `${specs.join(' ')}`;
} }
return displayName; return displayName;
@@ -494,10 +506,12 @@ export default {
if (rawMaterialRes.code === 200) { if (rawMaterialRes.code === 200) {
this.rawMaterialList = rawMaterialRes.rows || []; this.rawMaterialList = rawMaterialRes.rows || [];
this.allRawMaterials = rawMaterialRes.rows || []; // 保存完整备份
} }
if (productRes.code === 200) { if (productRes.code === 200) {
this.productList = productRes.rows || []; this.productList = productRes.rows || [];
this.allProducts = productRes.rows || []; // 保存完整备份
} }
} catch (error) { } catch (error) {
console.error('加载物品列表失败', error); console.error('加载物品列表失败', error);
@@ -540,46 +554,56 @@ export default {
} }
}, },
// 搜索物品(支持名称和规格搜索) // 搜索物品(前端过滤,支持名称和规格搜索)
async searchItems(query) { async searchItems(query) {
if (!this.updateForm.itemType) { if (!this.updateForm.itemType) {
this.$message.warning('请先选择材料类型'); this.$message.warning('请先选择材料类型');
return; return;
} }
// 如果没有输入,恢复完整列表
if (!query || query.trim() === '') { if (!query || query.trim() === '') {
// 如果搜索为空,加载默认列表 if (this.updateForm.itemType === 'raw_material') {
this.loadItemList(this.updateForm.itemType); this.rawMaterialList = [...this.allRawMaterials];
} else if (this.updateForm.itemType === 'product') {
this.productList = [...this.allProducts];
}
return; return;
} }
try { // 前端过滤:在已加载的数据中搜索
this.itemSearchLoading = true; const searchQuery = query.toLowerCase().trim();
if (this.updateForm.itemType === 'raw_material') {
const response = await listRawMaterial({ if (this.updateForm.itemType === 'raw_material') {
rawMaterialName: query, // 按名称搜索 // 从备份列表中过滤原材料
pageNum: 1, this.rawMaterialList = this.allRawMaterials.filter(item => {
pageSize: 50, // 搜索名称
withBom: true const nameMatch = item.rawMaterialName && item.rawMaterialName.toLowerCase().includes(searchQuery);
}); // 搜索规格
if (response.code === 200) { const specMatch = item.specification && item.specification.toLowerCase().includes(searchQuery);
this.rawMaterialList = response.rows || []; // 搜索 BOM 参数
} const bomMatch = item.bomItems && item.bomItems.some(bom =>
} else if (this.updateForm.itemType === 'product') { (bom.attrKey && bom.attrKey.toLowerCase().includes(searchQuery)) ||
const response = await listProduct({ (bom.attrValue && bom.attrValue.toLowerCase().includes(searchQuery))
productName: query, // 按名称搜索 );
pageNum: 1,
pageSize: 50, return nameMatch || specMatch || bomMatch;
withBom: true });
}); } else if (this.updateForm.itemType === 'product') {
if (response.code === 200) { // 从备份列表中过滤产品
this.productList = response.rows || []; this.productList = this.allProducts.filter(item => {
} // 搜索名称
} const nameMatch = item.productName && item.productName.toLowerCase().includes(searchQuery);
} catch (error) { // 搜索规格
console.error('搜索物品失败', error); const specMatch = item.specification && item.specification.toLowerCase().includes(searchQuery);
} finally { // 搜索 BOM 参数
this.itemSearchLoading = false; 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;
});
} }
}, },