前端修改

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: [],
productList: [],
// 原始完整列表备份(用于搜索过滤)
allRawMaterials: [],
allProducts: [],
itemSearchLoading: false,
// 只读模式
readonly: false,
@@ -403,11 +406,15 @@ export default {
// 清空物品选择
this.$set(this.targetCoil, 'itemId', null);
// 根据材料类型设置物品类型
// 根据材料类型设置物品类型并恢复完整列表
if (value === '成品') {
this.$set(this.targetCoil, 'itemType', 'product');
// 恢复完整产品列表
this.productList = [...this.allProducts];
} else if (value === '原料' || value === '废品') {
this.$set(this.targetCoil, 'itemType', 'raw_material');
// 恢复完整原料列表
this.rawMaterialList = [...this.allRawMaterials];
}
},
@@ -607,10 +614,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);
@@ -651,45 +660,56 @@ export default {
}
},
// 搜索物品
// 搜索物品(前端过滤,支持名称和规格搜索)
async searchItems(query) {
if (!this.targetCoil.itemType) {
this.$message.warning('请先选择材料类型');
return;
}
// 如果没有输入,恢复完整列表
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;
}
try {
this.itemSearchLoading = true;
if (this.targetCoil.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 (this.targetCoil.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 (this.targetCoil.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 (this.targetCoil.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;
});
}
},

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);

View File

@@ -287,6 +287,9 @@ export default {
// 原材料和产品列表
rawMaterialList: [],
productList: [],
// 原始完整列表备份(用于搜索过滤)
allRawMaterials: [],
allProducts: [],
itemSearchLoading: false,
// 只读模式
readonly: false
@@ -358,6 +361,23 @@ export default {
}
},
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) {
try {
@@ -429,43 +449,35 @@ export default {
},
// 格式化物品名称添加规格和BOM信息
formatItemName(name, bomItems) {
formatItemName(item) {
if (!item) return '';
// 获取名称(原材料或产品)
const name = item.rawMaterialName || item.productName || '';
if (!name) return '';
let displayName = name;
const specs = [];
// 如果有BOM参数添加到名称后面
if (bomItems && bomItems.length > 0) {
const specs = [];
// 1. 优先显示规格从对象的specification字段
if (item.specification) {
specs.push(item.specification);
}
// 2. 添加BOM参数最多2个
if (item.bomItems && item.bomItems.length > 0) {
const bomParams = item.bomItems
.filter(bomItem => bomItem.attrKey && bomItem.attrValue)
.slice(0, 2); // 最多2个BOM参数
// 查找规格参数
const specItem = bomItems.find(item =>
item.attrKey === '规格' ||
item.attrKey === 'spec' ||
item.attrKey === '型号'
);
if (specItem && specItem.attrValue) {
specs.push(specItem.attrValue);
}
// 添加其他关键参数最多3个
const otherParams = bomItems
.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}`);
}
bomParams.forEach(param => {
specs.push(`${param.attrKey}:${param.attrValue}`);
});
if (specs.length > 0) {
displayName += `${specs.join(' ')}`;
}
}
// 3. 拼接成最终格式
if (specs.length > 0) {
displayName += `${specs.join(' ')}`;
}
return displayName;
@@ -494,10 +506,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);
@@ -540,46 +554,56 @@ export default {
}
},
// 搜索物品(支持名称和规格搜索)
// 搜索物品(前端过滤,支持名称和规格搜索)
async searchItems(query) {
if (!this.updateForm.itemType) {
this.$message.warning('请先选择材料类型');
return;
}
// 如果没有输入,恢复完整列表
if (!query || query.trim() === '') {
// 如果搜索为空,加载默认列表
this.loadItemList(this.updateForm.itemType);
if (this.updateForm.itemType === 'raw_material') {
this.rawMaterialList = [...this.allRawMaterials];
} else if (this.updateForm.itemType === 'product') {
this.productList = [...this.allProducts];
}
return;
}
try {
this.itemSearchLoading = true;
if (this.updateForm.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 (this.updateForm.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 (this.updateForm.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 (this.updateForm.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;
});
}
},