Files
klp-oa/klp-ui/src/store/modules/category.js
砂糖 bad3f98599 feat(钢卷物料): 实现选中数据导出功能并优化标签显示
添加findItemWithBom工具函数用于统一获取物品名称
修改OuterTagPreview组件使用itemName替代productName
重构导出功能支持选中数据导出,并优化Excel生成逻辑
2025-10-30 15:32:55 +08:00

132 lines
3.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { listCategory } from '@/api/wms/category';
import { listProduct } from '@/api/wms/product';
import { listRawMaterial } from '@/api/wms/rawMaterial';
import { listBomItem } from '@/api/wms/bomItem';
// 目前存在一个问题,当新增或删除,修改分类、产品、物料时,需要刷新整个页面,才能看到最新的数据
// 需要优化当新增或删除修改分类、产品、物料时只刷新相关的数据而不是整个页面修改和删除可以解决新增由于没有返回id所以需要重新获取整个列表
const state = {
categoryList: [],
productMap: {},
rawMaterialMap: {},
productList: [],
rawMaterialList: [],
bomMap: {}
};
const mutations = {
SET_CATEGORY_LIST(state, list) {
state.categoryList = list;
},
SET_PRODUCT_MAP(state, map) {
state.productMap = map;
},
SET_RAW_MATERIAL_MAP(state, map) {
state.rawMaterialMap = map;
},
SET_PRODUCT_LIST(state, list) {
state.productList = list;
},
SET_RAW_MATERIAL_LIST(state, list) {
state.rawMaterialList = list;
},
SET_BOM_MAP(state, map) {
state.bomMap = map;
}
};
const actions = {
getCategoryList({ state, commit }) {
if (state.categoryList.length > 0) {
return Promise.resolve(state.categoryList);
}
return listCategory({ pageNum: 1, pageSize: 10000 }).then(res => {
commit('SET_CATEGORY_LIST', res.rows || []);
return res.rows || [];
});
},
getProductMap({ state, commit }) {
if (Object.keys(state.productMap).length > 0) {
return Promise.resolve(state.productMap);
}
return listProduct({ pageNum: 1, pageSize: 10000 }).then(res => {
const map = {};
res.rows.forEach(item => {
map[item.productId] = item;
});
commit('SET_PRODUCT_MAP', map);
commit('SET_PRODUCT_LIST', res.rows || []);
return map;
});
},
getRawMaterialMap({ state, commit }) {
if (Object.keys(state.rawMaterialMap).length > 0) {
return Promise.resolve(state.rawMaterialMap);
}
return listRawMaterial({ pageNum: 1, pageSize: 10000 }).then(res => {
const map = {};
res.rows.forEach(item => {
map[item.rawMaterialId] = item;
});
commit('SET_RAW_MATERIAL_MAP', map);
commit('SET_RAW_MATERIAL_LIST', res.rows || []);
return map;
});
},
getBomMap({ state, commit }) {
if (Object.keys(state.bomMap).length > 0) {
return Promise.resolve(state.bomMap);
}
return listBomItem({ pageNum: 1, pageSize: 10000 }).then(res => {
console.log('bomItem', res)
const map = {};
res.rows.forEach(item => {
if (!map[item.bomId]) {
map[item.bomId] = [];
}
map[item.bomId].push(item);
});
commit('SET_BOM_MAP', map);
return map;
})
}
};
export function findItemWithBom(itemType, itemId) {
if (!itemType || !itemId) {
return null;
}
console.log('itemType', itemType, 'itemId', itemId)
let map = {}
if (itemType === 'product') {
map = state.productMap;
} else if (itemType === 'raw_material') {
map = state.rawMaterialMap;
} else {
return null;
}
console.log('map', map)
const item = map[itemId];
const bomId = item.bomId
if (!item) {
return null;
}
console.log('bomId', bomId, item)
const bomItems = state.bomMap[bomId];
return {
...item,
boms: bomItems || [],
itemName: itemType === 'product' ? item.productName : item.rawMaterialName,
itemType,
};
}
export default {
namespaced: true,
state,
mutations,
actions,
};