查询优化,新增酸连轧页面

This commit is contained in:
2025-11-17 11:58:42 +08:00
parent e60b62f3e2
commit 23900f38f8
11 changed files with 1523 additions and 380 deletions

View File

@@ -218,8 +218,8 @@
import { getMaterialCoil, updateMaterialCoil, getMaterialCoilTrace } from '@/api/wms/coil';
import { completeAction } from '@/api/wms/pendingAction';
import { listWarehouse } from '@/api/wms/warehouse';
import { listRawMaterial } from '@/api/wms/rawMaterial';
import { listProduct } from '@/api/wms/product';
import { listRawMaterialWithBom } from '@/api/wms/rawMaterial';
import { listProductWithBom } from '@/api/wms/product';
import ActualWarehouseSelect from "@/components/KLPService/ActualWarehouseSelect";
export default {
@@ -300,12 +300,9 @@ export default {
warehouseList: [],
historySteps: [],
actionId: null,
// 原材料和产品列表
// 原材料和产品列表(实时搜索,不再保存完整备份)
rawMaterialList: [],
productList: [],
// 原始完整列表备份(用于搜索过滤)
allRawMaterials: [],
allProducts: [],
itemSearchLoading: false,
// 只读模式
readonly: false
@@ -352,8 +349,8 @@ export default {
// 先加载库区列表
await this.loadWarehouses();
// 🔥 页面加载时直接加载所有原料和产品列表
await this.loadAllItems();
// 不再一次性加载所有数据,改为实时搜索
// await this.loadAllItems();
// 从路由参数获取coilId和actionId
const coilId = this.$route.query.coilId;
@@ -382,12 +379,12 @@ export default {
// 根据材料类型设置物品类型
if (value === '成品') {
this.$set(this.updateForm, 'itemType', 'product');
// 恢复完整产品列表
this.productList = [...this.allProducts];
// 清空列表,等待用户搜索
this.productList = [];
} else if (value === '原料' || value === '废品') {
this.$set(this.updateForm, 'itemType', 'raw_material');
// 恢复完整原料列表
this.rawMaterialList = [...this.allRawMaterials];
// 清空列表,等待用户搜索
this.rawMaterialList = [];
}
},
@@ -406,10 +403,7 @@ export default {
nextWarehouseName: this.getWarehouseName(data.warehouseId),
};
// 加载对应类型的物品列表
if (data.itemType) {
await this.loadItemList(data.itemType);
}
// 不再预加载物品列表,改为实时搜索
// 加载变更历史
this.loadHistory();
@@ -492,115 +486,59 @@ export default {
}
},
// 页面加载时一次性加载所有原料和产品列表
async loadAllItems() {
try {
// 同时加载原料和产品
const [rawMaterialRes, productRes] = await Promise.all([
listRawMaterial({ pageNum: 1, pageSize: 99999, withBom: true }),
listProduct({ pageNum: 1, pageSize: 99999, withBom: true })
]);
// 已移除 loadAllItems改为实时搜索
if (rawMaterialRes.code === 200) {
this.rawMaterialList = rawMaterialRes.rows || [];
this.allRawMaterials = rawMaterialRes.rows || []; // 保存完整备份
}
// 已移除 loadItemList改为实时搜索
if (productRes.code === 200) {
this.productList = productRes.rows || [];
this.allProducts = productRes.rows || []; // 保存完整备份
}
} catch (error) {
console.error('加载物品列表失败', error);
}
},
// 加载物品列表(根据类型)
async loadItemList(itemType) {
if (!itemType) {
return;
}
try {
this.itemSearchLoading = true;
if (itemType === 'raw_material') {
// 使用带参数的接口
const response = await listRawMaterial({
pageNum: 1,
pageSize: 100,
withBom: true // 请求包含参数信息
});
if (response.code === 200) {
this.rawMaterialList = response.rows || [];
}
} else if (itemType === 'product') {
// 使用带参数的接口
const response = await listProduct({
pageNum: 1,
pageSize: 100,
withBom: true // 请求包含参数信息
});
if (response.code === 200) {
this.productList = response.rows || [];
}
}
} catch (error) {
console.error('加载物品列表失败', error);
} finally {
this.itemSearchLoading = false;
}
},
// 搜索物品(前端过滤,支持名称和规格搜索)
// 实时搜索物品(后端搜索)
async searchItems(query) {
if (!this.updateForm.itemType) {
this.$message.warning('请先选择材料类型');
return;
}
// 如果没有输入,恢复完整列表
// 如果没有输入,清空列表
if (!query || query.trim() === '') {
if (this.updateForm.itemType === 'raw_material') {
this.rawMaterialList = [...this.allRawMaterials];
this.rawMaterialList = [];
} else if (this.updateForm.itemType === 'product') {
this.productList = [...this.allProducts];
this.productList = [];
}
return;
}
// 前端过滤:在已加载的数据中搜索
const searchQuery = query.toLowerCase().trim();
try {
this.itemSearchLoading = true;
const searchQuery = query.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);
// 搜索 参数 参数
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);
// 搜索 参数 参数
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;
});
if (this.updateForm.itemType === 'raw_material') {
// 后端搜索原材料(支持名称或规格模糊搜索)
const response = await listRawMaterialWithBom({
pageNum: 1,
pageSize: 20,
rawMaterialName: searchQuery,
specification: searchQuery // 同时传入,后端会使用 OR 条件
});
if (response.code === 200) {
this.rawMaterialList = response.rows || [];
}
} else if (this.updateForm.itemType === 'product') {
// 后端搜索产品(支持名称或规格模糊搜索)
const response = await listProductWithBom({
pageNum: 1,
pageSize: 20,
productName: searchQuery,
specification: searchQuery // 同时传入,后端会使用 OR 条件
});
if (response.code === 200) {
this.productList = response.rows || [];
}
}
} catch (error) {
console.error('搜索物品失败', error);
this.$message.error('搜索失败,请重试');
} finally {
this.itemSearchLoading = false;
}
},